StyLua icon indicating copy to clipboard operation
StyLua copied to clipboard

Add Input mode for collapse_simple_statement

Open ddashdev opened this issue 6 months ago • 1 comments

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 avatar May 15 '26 02:05 ddashdev

Also closes #863

ddashdev avatar May 15 '26 03:05 ddashdev