nimpretty: don't introduce extra spaces after a colon or a comma (#11672)
This commit is contained in:
parent
085a21ebf4
commit
d0616ed115
3 changed files with 143 additions and 133 deletions
|
|
@ -69,6 +69,7 @@ proc openEmitter*(em: var Emitter, cache: IdentCache;
|
||||||
|
|
||||||
proc computeMax(em: Emitter; pos: int): int =
|
proc computeMax(em: Emitter; pos: int): int =
|
||||||
var p = pos
|
var p = pos
|
||||||
|
var extraSpace = 0
|
||||||
result = 0
|
result = 0
|
||||||
while p < em.tokens.len and em.kinds[p] != ltEndSection:
|
while p < em.tokens.len and em.kinds[p] != ltEndSection:
|
||||||
var lhs = 0
|
var lhs = 0
|
||||||
|
|
@ -76,10 +77,12 @@ proc computeMax(em: Emitter; pos: int): int =
|
||||||
var foundTab = false
|
var foundTab = false
|
||||||
while p < em.tokens.len and em.kinds[p] != ltEndSection:
|
while p < em.tokens.len and em.kinds[p] != ltEndSection:
|
||||||
if em.kinds[p] in {ltCrucialNewline, ltSplittingNewline}:
|
if em.kinds[p] in {ltCrucialNewline, ltSplittingNewline}:
|
||||||
if foundTab and lineLen <= MaxLineLen: result = max(result, lhs+1)
|
if foundTab and lineLen <= MaxLineLen:
|
||||||
|
result = max(result, lhs + extraSpace)
|
||||||
inc p
|
inc p
|
||||||
break
|
break
|
||||||
if em.kinds[p] == ltTab:
|
if em.kinds[p] == ltTab:
|
||||||
|
extraSpace = if em.kinds[p-1] == ltSpaces: 0 else: 1
|
||||||
foundTab = true
|
foundTab = true
|
||||||
else:
|
else:
|
||||||
if not foundTab:
|
if not foundTab:
|
||||||
|
|
@ -160,8 +163,9 @@ proc closeEmitter*(em: var Emitter) =
|
||||||
maxLhs = 0
|
maxLhs = 0
|
||||||
|
|
||||||
if maxLhs == 0:
|
if maxLhs == 0:
|
||||||
content.add em.tokens[i]
|
if em.kinds[i-1] != ltSpaces:
|
||||||
inc lineLen, em.tokens[i].len
|
content.add em.tokens[i]
|
||||||
|
inc lineLen, em.tokens[i].len
|
||||||
else:
|
else:
|
||||||
# pick the shorter indentation token:
|
# pick the shorter indentation token:
|
||||||
var spaces = maxLhs - lineLen
|
var spaces = maxLhs - lineLen
|
||||||
|
|
|
||||||
|
|
@ -728,3 +728,6 @@ type
|
||||||
first, ## this is a long comment here, but please align it
|
first, ## this is a long comment here, but please align it
|
||||||
secondWithAVeryLongNameMightBreak, ## this is a short one
|
secondWithAVeryLongNameMightBreak, ## this is a short one
|
||||||
thirdOne ## it's ok
|
thirdOne ## it's ok
|
||||||
|
|
||||||
|
if true: # just one space before comment
|
||||||
|
echo 7
|
||||||
|
|
|
||||||
|
|
@ -486,132 +486,132 @@ type
|
||||||
HttpPatch ## Applies partial modifications to a resource.
|
HttpPatch ## Applies partial modifications to a resource.
|
||||||
|
|
||||||
type
|
type
|
||||||
HtmlTag* = enum ## list of all supported HTML tags; order will always be
|
HtmlTag* = enum ## list of all supported HTML tags; order will always be
|
||||||
## alphabetically
|
## alphabetically
|
||||||
tagUnknown, ## unknown HTML element
|
tagUnknown, ## unknown HTML element
|
||||||
tagA, ## the HTML ``a`` element
|
tagA, ## the HTML ``a`` element
|
||||||
tagAbbr, ## the deprecated HTML ``abbr`` element
|
tagAbbr, ## the deprecated HTML ``abbr`` element
|
||||||
tagAcronym, ## the HTML ``acronym`` element
|
tagAcronym, ## the HTML ``acronym`` element
|
||||||
tagAddress, ## the HTML ``address`` element
|
tagAddress, ## the HTML ``address`` element
|
||||||
tagApplet, ## the deprecated HTML ``applet`` element
|
tagApplet, ## the deprecated HTML ``applet`` element
|
||||||
tagArea, ## the HTML ``area`` element
|
tagArea, ## the HTML ``area`` element
|
||||||
tagArticle, ## the HTML ``article`` element
|
tagArticle, ## the HTML ``article`` element
|
||||||
tagAside, ## the HTML ``aside`` element
|
tagAside, ## the HTML ``aside`` element
|
||||||
tagAudio, ## the HTML ``audio`` element
|
tagAudio, ## the HTML ``audio`` element
|
||||||
tagB, ## the HTML ``b`` element
|
tagB, ## the HTML ``b`` element
|
||||||
tagBase, ## the HTML ``base`` element
|
tagBase, ## the HTML ``base`` element
|
||||||
tagBdi, ## the HTML ``bdi`` element
|
tagBdi, ## the HTML ``bdi`` element
|
||||||
tagBdo, ## the deprecated HTML ``dbo`` element
|
tagBdo, ## the deprecated HTML ``dbo`` element
|
||||||
tagBasefont, ## the deprecated HTML ``basefont`` element
|
tagBasefont, ## the deprecated HTML ``basefont`` element
|
||||||
tagBig, ## the HTML ``big`` element
|
tagBig, ## the HTML ``big`` element
|
||||||
tagBlockquote, ## the HTML ``blockquote`` element
|
tagBlockquote, ## the HTML ``blockquote`` element
|
||||||
tagBody, ## the HTML ``body`` element
|
tagBody, ## the HTML ``body`` element
|
||||||
tagBr, ## the HTML ``br`` element
|
tagBr, ## the HTML ``br`` element
|
||||||
tagButton, ## the HTML ``button`` element
|
tagButton, ## the HTML ``button`` element
|
||||||
tagCanvas, ## the HTML ``canvas`` element
|
tagCanvas, ## the HTML ``canvas`` element
|
||||||
tagCaption, ## the HTML ``caption`` element
|
tagCaption, ## the HTML ``caption`` element
|
||||||
tagCenter, ## the deprecated HTML ``center`` element
|
tagCenter, ## the deprecated HTML ``center`` element
|
||||||
tagCite, ## the HTML ``cite`` element
|
tagCite, ## the HTML ``cite`` element
|
||||||
tagCode, ## the HTML ``code`` element
|
tagCode, ## the HTML ``code`` element
|
||||||
tagCol, ## the HTML ``col`` element
|
tagCol, ## the HTML ``col`` element
|
||||||
tagColgroup, ## the HTML ``colgroup`` element
|
tagColgroup, ## the HTML ``colgroup`` element
|
||||||
tagCommand, ## the HTML ``command`` element
|
tagCommand, ## the HTML ``command`` element
|
||||||
tagDatalist, ## the HTML ``datalist`` element
|
tagDatalist, ## the HTML ``datalist`` element
|
||||||
tagDd, ## the HTML ``dd`` element
|
tagDd, ## the HTML ``dd`` element
|
||||||
tagDel, ## the HTML ``del`` element
|
tagDel, ## the HTML ``del`` element
|
||||||
tagDetails, ## the HTML ``details`` element
|
tagDetails, ## the HTML ``details`` element
|
||||||
tagDfn, ## the HTML ``dfn`` element
|
tagDfn, ## the HTML ``dfn`` element
|
||||||
tagDialog, ## the HTML ``dialog`` element
|
tagDialog, ## the HTML ``dialog`` element
|
||||||
tagDiv, ## the HTML ``div`` element
|
tagDiv, ## the HTML ``div`` element
|
||||||
tagDir, ## the deprecated HTLM ``dir`` element
|
tagDir, ## the deprecated HTLM ``dir`` element
|
||||||
tagDl, ## the HTML ``dl`` element
|
tagDl, ## the HTML ``dl`` element
|
||||||
tagDt, ## the HTML ``dt`` element
|
tagDt, ## the HTML ``dt`` element
|
||||||
tagEm, ## the HTML ``em`` element
|
tagEm, ## the HTML ``em`` element
|
||||||
tagEmbed, ## the HTML ``embed`` element
|
tagEmbed, ## the HTML ``embed`` element
|
||||||
tagFieldset, ## the HTML ``fieldset`` element
|
tagFieldset, ## the HTML ``fieldset`` element
|
||||||
tagFigcaption, ## the HTML ``figcaption`` element
|
tagFigcaption, ## the HTML ``figcaption`` element
|
||||||
tagFigure, ## the HTML ``figure`` element
|
tagFigure, ## the HTML ``figure`` element
|
||||||
tagFont, ## the deprecated HTML ``font`` element
|
tagFont, ## the deprecated HTML ``font`` element
|
||||||
tagFooter, ## the HTML ``footer`` element
|
tagFooter, ## the HTML ``footer`` element
|
||||||
tagForm, ## the HTML ``form`` element
|
tagForm, ## the HTML ``form`` element
|
||||||
tagFrame, ## the HTML ``frame`` element
|
tagFrame, ## the HTML ``frame`` element
|
||||||
tagFrameset, ## the deprecated HTML ``frameset`` element
|
tagFrameset, ## the deprecated HTML ``frameset`` element
|
||||||
tagH1, ## the HTML ``h1`` element
|
tagH1, ## the HTML ``h1`` element
|
||||||
tagH2, ## the HTML ``h2`` element
|
tagH2, ## the HTML ``h2`` element
|
||||||
tagH3, ## the HTML ``h3`` element
|
tagH3, ## the HTML ``h3`` element
|
||||||
tagH4, ## the HTML ``h4`` element
|
tagH4, ## the HTML ``h4`` element
|
||||||
tagH5, ## the HTML ``h5`` element
|
tagH5, ## the HTML ``h5`` element
|
||||||
tagH6, ## the HTML ``h6`` element
|
tagH6, ## the HTML ``h6`` element
|
||||||
tagHead, ## the HTML ``head`` element
|
tagHead, ## the HTML ``head`` element
|
||||||
tagHeader, ## the HTML ``header`` element
|
tagHeader, ## the HTML ``header`` element
|
||||||
tagHgroup, ## the HTML ``hgroup`` element
|
tagHgroup, ## the HTML ``hgroup`` element
|
||||||
tagHtml, ## the HTML ``html`` element
|
tagHtml, ## the HTML ``html`` element
|
||||||
tagHr, ## the HTML ``hr`` element
|
tagHr, ## the HTML ``hr`` element
|
||||||
tagI, ## the HTML ``i`` element
|
tagI, ## the HTML ``i`` element
|
||||||
tagIframe, ## the deprecated HTML ``iframe`` element
|
tagIframe, ## the deprecated HTML ``iframe`` element
|
||||||
tagImg, ## the HTML ``img`` element
|
tagImg, ## the HTML ``img`` element
|
||||||
tagInput, ## the HTML ``input`` element
|
tagInput, ## the HTML ``input`` element
|
||||||
tagIns, ## the HTML ``ins`` element
|
tagIns, ## the HTML ``ins`` element
|
||||||
tagIsindex, ## the deprecated HTML ``isindex`` element
|
tagIsindex, ## the deprecated HTML ``isindex`` element
|
||||||
tagKbd, ## the HTML ``kbd`` element
|
tagKbd, ## the HTML ``kbd`` element
|
||||||
tagKeygen, ## the HTML ``keygen`` element
|
tagKeygen, ## the HTML ``keygen`` element
|
||||||
tagLabel, ## the HTML ``label`` element
|
tagLabel, ## the HTML ``label`` element
|
||||||
tagLegend, ## the HTML ``legend`` element
|
tagLegend, ## the HTML ``legend`` element
|
||||||
tagLi, ## the HTML ``li`` element
|
tagLi, ## the HTML ``li`` element
|
||||||
tagLink, ## the HTML ``link`` element
|
tagLink, ## the HTML ``link`` element
|
||||||
tagMap, ## the HTML ``map`` element
|
tagMap, ## the HTML ``map`` element
|
||||||
tagMark, ## the HTML ``mark`` element
|
tagMark, ## the HTML ``mark`` element
|
||||||
tagMenu, ## the deprecated HTML ``menu`` element
|
tagMenu, ## the deprecated HTML ``menu`` element
|
||||||
tagMeta, ## the HTML ``meta`` element
|
tagMeta, ## the HTML ``meta`` element
|
||||||
tagMeter, ## the HTML ``meter`` element
|
tagMeter, ## the HTML ``meter`` element
|
||||||
tagNav, ## the HTML ``nav`` element
|
tagNav, ## the HTML ``nav`` element
|
||||||
tagNobr, ## the deprecated HTML ``nobr`` element
|
tagNobr, ## the deprecated HTML ``nobr`` element
|
||||||
tagNoframes, ## the deprecated HTML ``noframes`` element
|
tagNoframes, ## the deprecated HTML ``noframes`` element
|
||||||
tagNoscript, ## the HTML ``noscript`` element
|
tagNoscript, ## the HTML ``noscript`` element
|
||||||
tagObject, ## the HTML ``object`` element
|
tagObject, ## the HTML ``object`` element
|
||||||
tagOl, ## the HTML ``ol`` element
|
tagOl, ## the HTML ``ol`` element
|
||||||
tagOptgroup, ## the HTML ``optgroup`` element
|
tagOptgroup, ## the HTML ``optgroup`` element
|
||||||
tagOption, ## the HTML ``option`` element
|
tagOption, ## the HTML ``option`` element
|
||||||
tagOutput, ## the HTML ``output`` element
|
tagOutput, ## the HTML ``output`` element
|
||||||
tagP, ## the HTML ``p`` element
|
tagP, ## the HTML ``p`` element
|
||||||
tagParam, ## the HTML ``param`` element
|
tagParam, ## the HTML ``param`` element
|
||||||
tagPre, ## the HTML ``pre`` element
|
tagPre, ## the HTML ``pre`` element
|
||||||
tagProgress, ## the HTML ``progress`` element
|
tagProgress, ## the HTML ``progress`` element
|
||||||
tagQ, ## the HTML ``q`` element
|
tagQ, ## the HTML ``q`` element
|
||||||
tagRp, ## the HTML ``rp`` element
|
tagRp, ## the HTML ``rp`` element
|
||||||
tagRt, ## the HTML ``rt`` element
|
tagRt, ## the HTML ``rt`` element
|
||||||
tagRuby, ## the HTML ``ruby`` element
|
tagRuby, ## the HTML ``ruby`` element
|
||||||
tagS, ## the deprecated HTML ``s`` element
|
tagS, ## the deprecated HTML ``s`` element
|
||||||
tagSamp, ## the HTML ``samp`` element
|
tagSamp, ## the HTML ``samp`` element
|
||||||
tagScript, ## the HTML ``script`` element
|
tagScript, ## the HTML ``script`` element
|
||||||
tagSection, ## the HTML ``section`` element
|
tagSection, ## the HTML ``section`` element
|
||||||
tagSelect, ## the HTML ``select`` element
|
tagSelect, ## the HTML ``select`` element
|
||||||
tagSmall, ## the HTML ``small`` element
|
tagSmall, ## the HTML ``small`` element
|
||||||
tagSource, ## the HTML ``source`` element
|
tagSource, ## the HTML ``source`` element
|
||||||
tagSpan, ## the HTML ``span`` element
|
tagSpan, ## the HTML ``span`` element
|
||||||
tagStrike, ## the deprecated HTML ``strike`` element
|
tagStrike, ## the deprecated HTML ``strike`` element
|
||||||
tagStrong, ## the HTML ``strong`` element
|
tagStrong, ## the HTML ``strong`` element
|
||||||
tagStyle, ## the HTML ``style`` element
|
tagStyle, ## the HTML ``style`` element
|
||||||
tagSub, ## the HTML ``sub`` element
|
tagSub, ## the HTML ``sub`` element
|
||||||
tagSummary, ## the HTML ``summary`` element
|
tagSummary, ## the HTML ``summary`` element
|
||||||
tagSup, ## the HTML ``sup`` element
|
tagSup, ## the HTML ``sup`` element
|
||||||
tagTable, ## the HTML ``table`` element
|
tagTable, ## the HTML ``table`` element
|
||||||
tagTbody, ## the HTML ``tbody`` element
|
tagTbody, ## the HTML ``tbody`` element
|
||||||
tagTd, ## the HTML ``td`` element
|
tagTd, ## the HTML ``td`` element
|
||||||
tagTextarea, ## the HTML ``textarea`` element
|
tagTextarea, ## the HTML ``textarea`` element
|
||||||
tagTfoot, ## the HTML ``tfoot`` element
|
tagTfoot, ## the HTML ``tfoot`` element
|
||||||
tagTh, ## the HTML ``th`` element
|
tagTh, ## the HTML ``th`` element
|
||||||
tagThead, ## the HTML ``thead`` element
|
tagThead, ## the HTML ``thead`` element
|
||||||
tagTime, ## the HTML ``time`` element
|
tagTime, ## the HTML ``time`` element
|
||||||
tagTitle, ## the HTML ``title`` element
|
tagTitle, ## the HTML ``title`` element
|
||||||
tagTr, ## the HTML ``tr`` element
|
tagTr, ## the HTML ``tr`` element
|
||||||
tagTrack, ## the HTML ``track`` element
|
tagTrack, ## the HTML ``track`` element
|
||||||
tagTt, ## the HTML ``tt`` element
|
tagTt, ## the HTML ``tt`` element
|
||||||
tagU, ## the deprecated HTML ``u`` element
|
tagU, ## the deprecated HTML ``u`` element
|
||||||
tagUl, ## the HTML ``ul`` element
|
tagUl, ## the HTML ``ul`` element
|
||||||
tagVar, ## the HTML ``var`` element
|
tagVar, ## the HTML ``var`` element
|
||||||
tagVideo, ## the HTML ``video`` element
|
tagVideo, ## the HTML ``video`` element
|
||||||
tagWbr ## the HTML ``wbr`` element
|
tagWbr ## the HTML ``wbr`` element
|
||||||
|
|
||||||
|
|
||||||
# bug #11469
|
# bug #11469
|
||||||
|
|
@ -732,7 +732,10 @@ let
|
||||||
423948999 - 42399
|
423948999 - 42399
|
||||||
|
|
||||||
type
|
type
|
||||||
MyLongEnum = enum ## doc comment here
|
MyLongEnum = enum ## doc comment here
|
||||||
first, ## this is a long comment here, but please align it
|
first, ## this is a long comment here, but please align it
|
||||||
secondWithAVeryLongNameMightBreak, ## this is a short one
|
secondWithAVeryLongNameMightBreak, ## this is a short one
|
||||||
thirdOne ## it's ok
|
thirdOne ## it's ok
|
||||||
|
|
||||||
|
if true: # just one space before comment
|
||||||
|
echo 7
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue