-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Comma Position #697
Comments
As a workaround. If you really want to simply get this feature back as it was, you can take the old implementation (formatCommaPositions.ts) and run the formatted code through it. Something like: import { format } from "sql-formatter";
import { formatCommaPositions } from "./formatCommaPositions";
const sql = format("SELECT foo, bar, baz FROM tbl", { language: "sqlite" });
console.log(formatCommaPositions(sql, "before", " ")); IssuesYou should be aware that this whole implementation is one big hack and will easily break. e.g. it will break for BigQuery which allows a trailing comma in SELECT (though this style won't really make much sense in case of BigQuery anyway). And it will break when it encounters comments in unexpected places. And likely many more scenarios... The implementation also conflicts with how the same feature is implemented in SQLFluff. Namely, SQLFluff expects leading commas to be indented like so (keeping the actual indentation of each line): SELECT
foo
, bar
, baz
FROM
tbl But this implementation unindents each line with a comma by two spaces: SELECT
foo
, bar
, baz
FROM
tbl Which is IMHO pretty awkward and also prevents it from working when TABs are used for indentation. FutureI currently don't have any plans to re-implement this feature. I'm open to pull requests if anybody is interested in creating this feature properly. |
Thank you for the workaround and clear explanation. Looking forward to the future plans. |
When using the previous version of sql formatter, I found comma position configuration very useful in debugging. I wondered if this feature could be brought back sometime.
The text was updated successfully, but these errors were encountered: