sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.23k stars 392 forks source link

Feature Request: Keep some blank lines when formatting #750

Open arm32x opened 2 weeks ago

arm32x commented 2 weeks ago

Describe the Feature A configuration option (or default behavior) to keep some existing blank lines from the input file. For example, IntelliJ has the following options for Java: 20240619_22h02m40s_grim

Why do you want this feature? I have some SQL files used for database migrations with a header comment at the top that isn't directly related to the first query:

-- Some header comment
-- with metadata for migrations tool

CREATE TABLE something(id INTEGER PRIMARY KEY);

When I format this with sql-formatter, it currently deletes the blank line between the header comment and the first query.

nene commented 2 weeks ago

Thanks for the suggestion. It would definitely make sense to preserve blank lines.

However, with the current architecture of the formatter this is pretty hard to accomplish. Besides, I'm not actively developing this tool any more. Instead concentrating on prettier-plugin-sql-cst. So this is unlikely to happen unless you would like to implement it by yourself.