Closed dang1507 closed 7 months ago
I guess from the other issue you opened that this one also isn't about prettier-plugin-sql-cst
. But I'll respond anyway as I'm maintaining both this library and sql-formatter
.
In general the philosophy behind prettier-plugin-sql-cst
is to support one SQL formatting style and do it well. Just like the original Prettier library does for JavaScript.
With sql-formatter
, this is less of a case in theory. In the past it had several more options to configure the formatting style. But the maintenance overhead just wasn't worth it as the implementations of these other styles were mostly terrible hacks. That's why I've been gradually deprecating and removing such options. For example there used to be an option for comma-first style, but it has been removed by now.
Regarding this comma-first style, did you know that BigQuery allows for trailing commas in SELECT
columns list. That's IMHO a much better solution for the same problem. Currently prettier-plugin-sql-cst
removes such trailing commas, but I'm planning to introduce an option for configuring it (as it's a syntax that can't be used in all SQL dialects).
Regarding these "floating statements":
UPDATE my_table
SET
field1 = 'hello'
WHERE
1=1;
prettier-plugin-sql-cst
already does what you're asking for:
UPDATE my_table
SET field1 = 'hello'
WHERE 1 = 1;
It decides dynamically whether it should split WHERE
-clause to multiple lines or keep it on a single line. It's actually even more dynamic than that. It will format SELECT foo, bar
on a single line if it fits within line-length limit and is on a single line in original source code. But if the original code has it broken to multiple lines, it will format it to multiple lines. This sort of thing is still work-in-progress. It works for some clauses, but the plan is to support it in most places.
It does not however support the implicit-indents style (using SQLFluff terminology):
WHERE 1=1
AND 2=2;
Currently there's no plan to support such a style in neither formatting library. Even if on one day I would consider supporting it, I would prefer doing it consistently. That is, I would also apply it to the columns in SELECT
-clause and everywhere else.
I have a few option requests that would mean a lot to me if they could be be realized.
FROM / WHERE Example
Desired Output
Floating statement examples