lassik / emacs-format-all-the-code

Auto-format source code in many languages with one command
https://melpa.org/#/format-all
MIT License
623 stars 108 forks source link

sqlformat should use option -r #251

Closed cosven closed 10 months ago

cosven commented 10 months ago

Before, sqlformat almost does nothing when format sql files. After adding the -r option, the sql can be correctly formatted.

For example, using SQL

select l_orderkey   from lineitem
 where exists (        select *
          from orders
         where o_orderkey = l_orderkey
       )
    or l_linenumber in (1,2,3);

Without this change, the sql is not formatted. After this change, it can be formatted to

select l_orderkey
from lineitem
where exists
    (select *
     from orders
     where o_orderkey = l_orderkey )
  or l_linenumber in (1,
                      2,
                      3);
lassik commented 10 months ago

It looks like sqlformat has been designed so that it has no default behavior. I agree that it is confusing, but this problem should probably be solved upstream in sqlformat itself. Format-all tries to be neutral and unopinionated about options. You can use different flags by setting format-all-formatters.

Several people have been confused by sqlformat, so it should probably be covered in thee readme.

lassik commented 10 months ago

Example:

(eval-after-load 'format-all
  '(add-hook 'sql-mode-hook
             (lambda ()
               (setq format-all-formatters
                     '(("SQL" (sqlformat "-r")))))))
lassik commented 10 months ago

I added the example to the README.

cosven commented 10 months ago

Then I think we can close this PR.

lassik commented 10 months ago

Commit 7d95da8