jscheid/prettier.el

Not formatting SQL region with plugin prettier-plugin-sql

Closed this issue · 1 comments

Describe the bug
M-x prettier-prettify-region does not seem to work with SQL buffer (of a file.sql) with prettier-plugin-sql installed.

Link to M-x prettier-info output
https://gist.github.com/jjnilton/757502a98e4dd4d42da436fe0aa2fc54

To Reproduce
Install prettier-plugin-sql and use prettier-prettify-region on a SQL region like this:

create table table_name (id int, thing_name varchar(255), city varchar(255), country varchar(255));

Expected behavior
It should format like when using M-x shell-command-on-region with prettier --parser=sql:

create table table_name (
  id int,
  thing_name varchar(255),
  city varchar(255),
  country varchar(255)
);

@jjnilton I think you might need to create .prettierrc as below.

{
  "plugins": ["prettier-plugin-sql"],
  "overrides": [
    {
      "files": "*.sql",
      "options": { "parser": "sql" }
    }
  ]
}

Or you could also specify it in .dir-locals.el without using overrides key in .prettierrc .

{
  "plugins": ["prettier-plugin-sql"],
}
((sql-mode . ((prettier-infer-parser-flag . nil)
              (prettier-parsers . (sql)))))

As far as I know, there isn't a way to pass plugins contents from prettier.el, so you need to create a .prettierrc if you want to use plugins.