Repository navigation
Conversation
A comment before `do` in a numeric for loop, or right after the opening parenthesis of a hanging condition, was followed by the rest of the code on the same line, commenting it out. Put `do` on its own line, as while and generic for already do, and hang the parenthesised expression when its opening parenthesis carries a single-line comment. Fixes JohnnyMorganz#1176
This branch has not been deployed
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 #1176.
Both cases in the issue produced output that no longer parses, because a single-line comment ended up in front of code on the same line.
1. Numeric
forwith a comment beforedo.format_numeric_foralways appended" do"after the end or step expression, so a trailing-- commenton that expression swallowed it. If the last expression of the header (the step, or else the end) has a trailing single-line comment, ordohas a leading one, it now ends that expression with a newline and putsdoon its own line, withdo's leading comments handled aswhiledoes (format_end_token,IndentComments).whileand genericforalready keepdoon its own line in this case. A block comment (--[[ ]]) beforedois unchanged, since it can't swallow anything.2. Comment right after
(in a hanging condition. Informat_hanging_expression_, a short parenthesised expression took the single-line shortcut when the expression itself had no comments. A comment attached to the opening parenthesis wasn't checked, so( -- commentwas followed byb or c)on the same line. A trailing single-line comment on(now sends it down the existing hanging path, which already puts the expression on the next line.Output for the issue's inputs:
The second fix also covers
local x = ( -- commentfollowed by1 + 2 ), which onmaingavelocal x = ( -- comment1 + 2).Tests
There are two new snapshot inputs.
tests/inputs/numeric-for-comment-before-do.luacovers:do;do, which stays on one line.tests/inputs/parentheses-comment-after-open.luacovers the issue's condition and thelocalcase.Without the two
srcchanges, both snapshots fail. With them,cargo testpasses for every feature set inci.ymlon macOS arm64:--no-default-featuresluaulua52lua53lua54luajitcfxluaFormatting the new snapshots' output again gives the same output, and it parses.
cargo fmt --checkandcargo clippy --all-targets --all-featuresare clean.A related case I left alone:
print(( -- c/1/))drops the comment onmainand still does with this change. The redundant inner parentheses are removed along with the comment attached to them. That's a different code path, so I can open a separate issue if you like.