fix: normalize input to LF before parsing - #1140
Open
keithharvey wants to merge 1 commit into
Open
Conversation
A token keeps whatever line ending the source used. In my case, I am trying to add stylua to [Beyond-All-Reason](https://github.com/beyond-all-reason/Beyond-All-Reason/), which sets eol=crlf in .gitattributes, so the input was always CRLF. That repo also has a TON of single-line comments. A single-line comment is tokenised as `SingleLineComment(" text\r")` with the `\n` as separate whitespace. Comments are relocated by `take_leading_comments` / `take_trailing_comments` without passing through `format_token`, so that `\r` reaches the output, and the configured line ending is then appended after it, producing `\r\r\n`. The output line ending is decided solely by the `line_endings` config, so the input's must not survive parsing. This makes formatting non-idempotent: with `line_endings = "Windows"`, each run adds another `\r` to affected lines. Related to JohnnyMorganz#665, which fixed the same class of bug for multiline comments and strings.
keithharvey
added a commit
to keithharvey/bar
that referenced
this pull request
Aug 4, 2026
.gitattributes marks *.lua as eol=crlf, so git writes CRLF on checkout. stylua wrote LF, so running the formatter left every file it touched reported as modified with an empty diff. column_width drops from the 2000 sentinel to 120, the wrap width the formatting migration actually applies. StyLua keeps a comment's source \r when it relocates the comment (JohnnyMorganz/StyLua#1140), so under CRLF output every comment sitting on a token stylua moves or deletes came out as \r\r\n. Reshapes those sites so the formatter passes them through: trailing semicolons before comments dropped, trailing and/or operators moved below their comment, and comments pulled out of expressions stylua rewrites every pass.
keithharvey
added a commit
to keithharvey/bar
that referenced
this pull request
Aug 4, 2026
.gitattributes marks *.lua as eol=crlf, so git writes CRLF on checkout. stylua wrote LF, so running the formatter left every file it touched reported as modified with an empty diff. column_width drops from the 2000 sentinel to 120, the wrap width the formatting migration actually applies. StyLua keeps a comment's source \r when it relocates the comment (JohnnyMorganz/StyLua#1140), so under CRLF output every comment sitting on a token stylua moves or deletes came out as \r\r\n. Reshapes those sites so the formatter passes them through: trailing semicolons before comments dropped, trailing and/or operators moved below their comment, and comments pulled out of expressions stylua rewrites every pass. Hand-aligned drawing and data blocks keep their layout: gl vertex fans, paired-diamond vertices, index-aligned triangle strips, the sphere VBO generator, and the buildmenu sort table sit inside stylua: ignore ranges; tool-generated atlas tables join .styluaignore wholesale. Ignore ranges still lose trailing semicolons on local/assignment statements (upstream stylua bug), so the sphere generator trades its C-style semicolons for spaces to keep the comment columns.
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.
A token keeps whatever line ending the source used. In my case, I am trying to add stylua to Beyond-All-Reason, which sets eol=crlf in .gitattributes, so the input was always CRLF. That repo also has a TON of single-line comments.
A single-line comment is tokenised as
SingleLineComment(" text\r")with the\nas separate whitespace. Comments are relocated bytake_leading_comments/take_trailing_commentswithout passing throughformat_token, so that\rreaches the output, and the configured line ending is then appended after it, producing\r\r\n. The output line ending is decided solely by theline_endingsconfig, so the input's must not survive parsing.This makes formatting non-idempotent: with
line_endings = "Windows", each run adds another\rto affected lines. Related to #665, which fixed the same class of bug for multiline comments and strings.