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,6 +163,7 @@ proc closeEmitter*(em: var Emitter) =
|
||||||
maxLhs = 0
|
maxLhs = 0
|
||||||
|
|
||||||
if maxLhs == 0:
|
if maxLhs == 0:
|
||||||
|
if em.kinds[i-1] != ltSpaces:
|
||||||
content.add em.tokens[i]
|
content.add em.tokens[i]
|
||||||
inc lineLen, em.tokens[i].len
|
inc lineLen, em.tokens[i].len
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -736,3 +736,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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue