Skip to content

preserve-block-newline-gaps=Preserve inserts trailing whitespace for an empty function #1146

Description

@idbrii

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:

function FuncWithBlankLine()

end

function FuncEmpty()
end

function FuncOneLiner() end

Run stylua --preserve-block-newline-gaps=Preserve --no-editorconfig --config-path NUL test.lua

After:

function FuncWithBlankLine() 
end

function FuncEmpty() end

function FuncOneLiner() 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.

function FuncWithBlankLine()
end

function FuncEmpty()
end

function FuncOneLiner() 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions