Open ed9w2in6 opened 1 year ago
Do you mean that the user args should come before the "-"
?
No, it is incorrect because sqlformat
does not do formatting when no options are supplied.
This is more explicit:
(format-all--buffer-easy executable "--keywords=upper" "--identifiers=lower" "--indent_width=4" "--reindent" "--encoding" ienc "-")
I just saw this: https://github.com/sqlfluff/sqlfluff, which can do more auto styling and it comes with default styling configs but it is really a linter.
No, it is incorrect because
sqlformat
does not do formatting when no options are supplied.
Does it just return the old SQL unmodified? I so, that's a feature of sqlparse, not a bug.
I'd be happy to accept a PR for sqlfluff if someone sends one.
Here is the usage: https://docs.sqlfluff.com/en/stable/cli.html
(format-all--buffer-easy executable "fix" "--nocolor" "-")
should be a good start.
No, it is incorrect because
sqlformat
does not do formatting when no options are supplied.Does it just return the old SQL unmodified? I so, that's a feature of sqlparse, not a bug.
Yes but then isn't that against the users expectation of running the format-all
command? Since sqlformat
only accepts configs from CLI, the only way to make it do some form of formatting is by editing the elisp code. Or is there a way to config format-all
that I do not know?
I am happy with my hack at the moment but I will look into sqlfluff
when I have time. sqlfluff
might fit better into this project since:
Yes but then isn't that against the users expectation of running the
format-all
command?
It probably is surprising.
The format-all policy is that counter-intuitive behavior should be fixed upstream in the formatter itself. If editor plug-ins like format-all set their own defaults for each formatter, then different plugins will inevitably set different defaults and users are going to be confused about where the settings are coming from.
If the policy is that all defaults are set in the upstream formatter, that's simpler for both users and maintainers of the formatter and the plug-ins.
Since
sqlformat
only accepts configs from CLI, the only way to make it do some form of formatting is by editing the elisp code. Or is there a way to configformat-all
that I do not know?
There is. Users can place the command line flags in the format-all-formatters
variable, which can be set via a hook function and/or a project-specific .dir-locals.el
file.
For example:
(add-hook 'sql-mode-hook
(lambda ()
(setq-local format-all-formatters
'(("SQL" (sqlformat
"--keywords=upper"
"--identifiers=lower"
"--indent_width=4"
"--reindent"))))))
I am happy with my hack at the moment but I will look into
sqlfluff
when I have time.
Thanks! Any help increasing formatter coverage is appreciated.
sqlfluff
might fit better into this project since:
We try to be un-opinionated and add all formatters, even ones like sqlformat
that are counter-intuitive :)
Currently the formatter for
sqlformat
goes like this:Which is incorrect: Output of
sqlformat --help
Currently I am using this hack:
Which will convert upcase keywords and reindent. I am not sure about the standard of this project say if customisation is required, etc.
I can write a pull request if not one wants to write one.