Skip to content

Preserve final newline in sqlformat output - #900

Open
RamiNoodle733 wants to merge 2 commits into
andialbrecht:masterfrom
RamiNoodle733:fix/sqlformat-preserve-final-newline-637
Open

RamiNoodle733 wants to merge 2 commits into
andialbrecht:masterfrom
RamiNoodle733:fix/sqlformat-preserve-final-newline-637

Conversation

@RamiNoodle733

Copy link
Copy Markdown

Fixes #637.

sqlparse.format() serializes each statement with SerializerUnicode, which strips trailing whitespace from split lines. For the CLI that means a SQL file ending in a newline can be emitted without its final newline.

This keeps the library formatter behavior unchanged and fixes the CLI boundary instead: if the input ended in a newline and formatted output no longer does, sqlformat restores one before writing it. Inputs without a final newline remain unchanged.

Regression coverage checks both newline/no-newline stdout behavior and the --in-place path.

Validation: I inspected the focused branch diff against current master. I could not run the project test suite in this automation environment because a runnable checkout is unavailable, so no local pytest result is claimed.

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.

sqlformat mangles newlines at end of file

1 participant