Skip to content

Add Input mode for collapse_simple_statement#1112

Open
ddashdev wants to merge 5 commits into
JohnnyMorganz:mainfrom
ddashdev:preserve-collapse-simple-statement
Open

Add Input mode for collapse_simple_statement#1112
ddashdev wants to merge 5 commits into
JohnnyMorganz:mainfrom
ddashdev:preserve-collapse-simple-statement

Conversation

@ddashdev
Copy link
Copy Markdown

Adds a new Input mode for collapse_simple_statement.

It allows Stylua to preserve whether simple functions and conditionals were originally collapsed or expanded, instead of enforcing one global collapse behavior across the whole codebase.

With this mode:

if x then return end

stays collapsed, while:

if x then
    return
end

stays expanded.

The motivation is making it possible for users to keep a mixed style where some simple statements are collapsed and others are intentionally expanded, not all simple statements carry the same importance in a codebase. In some cases a collapsed statement improves readability by keeping a guard clause or empty function compact, while in others, expanding the statement makes the control flow or intent more visible.

The existing collapse_simple_statement modes require users to choose one global behavior: collapse matching statements everywhere, or expand them everywhere. This can be limiting when different simple statements benefit from different formatting choices.

And, while stylua: ignore comments can work around individual cases, they add noise and become difficult to maintain when used repeatedly for formatting preferences. Adding an Input mode follows the existing input-preserving semantics used by other Stylua rules like call_parenthesis, and gives users the ability to preserve these choices per situation without changing the default behavior.

Note: I used AI assistance while working through parts of the implementation, but reviewed the resulting changes and verified the behavior with tests.

@ddashdev
Copy link
Copy Markdown
Author

Also closes #863

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant