Repository navigation
Conversation
The check deciding whether an assignment fits the column width measured the
variable list by its total length. When the list itself spans multiple lines,
the total length is far larger than what actually sits on the line with the
equals token, so the assigned function's parameters were expanded
unnecessarily. The same applied to Luau type specifiers and Lua 5.4
attributes, which are also appended to the variable list before the equals
token.
Measure the last line of the variable list instead, which is what the equals
token and the expression are appended to:
let singleline_shape = shape.take_last_line(&strip_leading_trivia(&var_list))
+ 3 // 3 = " = "
+ strip_trailing_trivia(&expr_list).to_string().len();
This is the same approach the TableConstructor branch of
function_args_multiline_heuristic uses for the equivalent width check.
Adds regression tests for each affected path, plus a guard test asserting
that the parameters are still expanded when they genuinely do not fit.
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.
Problem
The check deciding whether an assignment fits the column width measured the variable list by its total length. When the list itself spans multiple lines, the total length is far larger than what actually sits on the line with the equals token, so the assigned function's parameters were expanded unnecessarily.
Given (default
column_width = 120)StyLua produced
Only
}).setup(8 characters) shares a line with the equals token, but the whole variable list (143 characters) was added to the width, pushing the check past 120. Whether this triggers therefore depends on how many rows the table happens to have, not on the width of the line that is actually produced.The same measurement feeds
format_local_assignment_no_triviaandformat_const_assignment_no_trivia, where Luau type specifiers and Lua 5.4 attributes are also appended to the variable list:The type specifier is 125 characters across 8 lines, but only
}sits on the line with the equals token, so the parameters were expanded at the defaultcolumn_width = 120.Fix
Measure the last line of the variable list, which is what the equals token and the expression are appended to:
For
localandconst, the type specifier and attribute text is appended to the variable list first, so a multiline specifier only contributes its last line. The prefix keyword (local/const) is added before taking the last line, so it is dropped when the list is multiline and kept when it is not.This is the same approach the
TableConstructorbranch offunction_args_multiline_heuristicuses for the equivalent width check.Tests
Six tests added in
tests/tests.rs:test_assignment_var_list_spanning_multiple_linesformat_assignment_no_triviatest_assignment_var_list_spanning_multiple_lines_still_expands_when_over_budgettest_local_assignment_name_list_spanning_multiple_linesformat_local_assignment_no_trivia— name list split by a commenttest_const_assignment_name_list_spanning_multiple_linesformat_const_assignment_no_trivia— same, for Luauconsttest_local_assignment_multiline_type_specifiertest_const_assignment_multiline_type_specifierconstEach of the five regression tests fails when the fix is reverted, so none of them passes by accident. The guard test passes both with and without the fix, which is the point: it checks that the parameters are still expanded when they genuinely do not fit. The Luau tests are gated behind
#[cfg(feature = "luau")].Verification
cargo testpasses for every feature set inci.yml(default,--no-default-features,luau,lua52,lua53,lua54,luajit,cfxlua,--all-features), along withcargo clippy --all-features --all-targets -- -D warningsandcargo fmt --check. No existing snapshots change.The Docker image builds and formats the example above correctly. The wasm check was not run locally (no
wasm32-unknown-unknowntarget available), and the large-scale comparison workflow isworkflow_dispatch-only and requires the PR number, so both are left to CI.