You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
preserve-block-newline-gaps=Preserve inserts trailing whitespace for an empty function #1146
Thanks for adding this option! I much prefer having some newlines in my if statements!
Using preserve-block-newline-gaps=Preserve when a function contains a blank line removes the line but adds a space after the function declaration.
Before:
functionFuncWithBlankLine()
endfunctionFuncEmpty()
endfunctionFuncOneLiner() end
Run stylua --preserve-block-newline-gaps=Preserve --no-editorconfig --config-path NUL test.lua
After:
functionFuncWithBlankLine()
endfunctionFuncEmpty() endfunctionFuncOneLiner() end
FuncWithBlankLine has a space on the end of the line: function FuncWithBlankLine()_
Expected: FuncOneLiner is unchanged as I'd expect, but I would expect FuncWithBlankLine and FuncEmpty to look the same.
functionFuncWithBlankLine()
endfunctionFuncEmpty()
endfunctionFuncOneLiner() end
Additionally, the output is not stable. Running the same stylua command again removes the space and makes all functions look like FuncOneLiner. This is the same behaviour as using --preserve-block-newline-gaps=Never on the original file, so I think the intent was for the newline to be preserved instead of replacing it with a space.
changed the title [-]preserve-block-newline-gaps=Preserve leaves trailing whitespace for an empty function[/-][+]preserve-block-newline-gaps=Preserve inserts trailing whitespace for an empty function[/+]on Aug 13, 2026
I tried v2.6.0 but it gave me the exact same results as above, so I guess it's not yet released.
From the PR's test it looks like this would be the output:
function FuncWithBlankLine()
end
function FuncEmpty() end
function FuncOneLiner() end
I expected it would remove blank lines but preserve newlines. The PR preserves blank links but collapses newlines. The PR better matches the description of the feature:
Specify whether to preserve leading and trailing newline gaps for blocks. Possible options: Never, Preserve.
However, I'm not sure this behaviour is actually more useful in practice. I don't like one-line functions, so I wouldn't find it helpful to collapse like this. I also wouldn't write functions that only contain a blank line so I wouldn't go the route of adding a blank line before each end just to prevent them from collapsing to one line. But these empty functions are rare, and the output is now stable so it's definitely an improvement. I think you can close as resolved if the current behaviour is satisfactory.
Activity
[-]preserve-block-newline-gaps=Preserve leaves trailing whitespace for an empty function[/-][+]preserve-block-newline-gaps=Preserve inserts trailing whitespace for an empty function[/+]JohnnyMorganz commentedon Oct 3, 2026
The behaviour implemented in #1159 is slightly different to your expectation here, but I think it's also reasonable - does that match what you expect?
idbrii commentedon Oct 19, 2026
I tried v2.6.0 but it gave me the exact same results as above, so I guess it's not yet released.
From the PR's test it looks like this would be the output:
I expected it would remove blank lines but preserve newlines. The PR preserves blank links but collapses newlines. The PR better matches the description of the feature:
However, I'm not sure this behaviour is actually more useful in practice. I don't like one-line functions, so I wouldn't find it helpful to collapse like this. I also wouldn't write functions that only contain a blank line so I wouldn't go the route of adding a blank line before each
endjust to prevent them from collapsing to one line. But these empty functions are rare, and the output is now stable so it's definitely an improvement. I think you can close as resolved if the current behaviour is satisfactory.