Repository navigation
fixes #26693; nimpretty no longer writes an empty line when it splits a joined line - #26880
Merged
Merged
Conversation
…t splits a joined line When optionalIsGood joins two lines it turns the newline between them into an optional newline, but kept its token "\n". An optional newline's token is the indentation written when the line is split there, so splitting at that position wrote an empty line and put the rest at column 0. Now the token becomes the indentation of the joined line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #26693
When
optionalIsGoodjoins two lines that have the same indentation, it turns the newline between them into anltOptionalNewline, but the token stays"\n". The token of an optional newline is the indentation thatrenderTokenswrites when it splits the line there. So when the joined line was split at that position again, nimpretty wrote"\L" & "\n": an empty line, then the rest of the expression at column 0. Inside brackets the output still parses; in an indented block it failsfinalCheckwithinvalid indentation.Fix: when the newline becomes an optional newline, set its token to the indentation of the joined line.
Test:
nimpretty/tests/twrappedexpr.nimwith the two examples from the issue.Verification, on macOS arm64:
nim r nimpretty/tester.nimfails ontwrappedexpr(invalid indentation); after the fix all files are identical, including the pretty(pretty(x)) runs.compiler/*.nim,lib/pure/*.nimandlib/std/*.nim(307 files). The 284 files that both versions format are byte-identical. 5 files that failed before with(line, 1) Error: invalid indentationnow format (compiler/docgen2.nim,jsgen.nim,lexer.nim,main.nim,varpartitions.nim). 18 files fail with both versions; in 3 of them the column-1 error is gone and a later, different error remains.optionalIsGoodblock as fixes #26691; fixes #26692; nimpretty keeps the space after a binary operator when it joins lines #26878 but not the same lines; the two merge without conflicts in either order and the tester passes on the merged tree.