Prettier-vscode: Support for additional file types

Created on 30 May 2020  路  8Comments  路  Source: prettier/prettier-vscode

Is your feature request related to a problem? Please describe.
I would like to use prettier on .njk files with the html parser. It works when I run npx prettier **/*.njk --parser html, but (as far as I can tell), there is no way to set this up in the .prettierrc file.

Describe the solution you'd like
A clear and concise description of what you want to happen.
I think the simplest solution would be to support arbitrary file types in the overrides section of the .prettierrc file. For example:

{
  "overrides": [
    {
      "files": "*.njk",
      "options": { "parser": "html" }
    }
  ]
}
locked

Most helpful comment

This feature is now supported in 5.3.0. You can register custom glob paths for the extension to provide formatting for. See: https://github.com/prettier/prettier-vscode#prettierdocumentselectors

All 8 comments

This is supported today, but it can be somewhat complex depending on what is happening. I wrote a wiki article that should help explain this: https://github.com/prettier/prettier-vscode/wiki/Custom-File-Extension-Configuration

This doesn't solve my problem. I'd like vscode to syntax highlight as a .njk file, but format as though it were an .html file, which (unless I'm misunderstanding your writing) still isn't possible.

@cj81499 You have to send a pull request to prettier as explained here: https://github.com/prettier/prettier-vscode/wiki/Custom-File-Extension-Configuration#custom-language-identifier

It seems a way to do this, either in prettier config or vscode prettier, without making a PR to prettier would be very useful... What a shame.

Happy to accept a PR for a more convenient implementation.

This feature is now supported in 5.3.0. You can register custom glob paths for the extension to provide formatting for. See: https://github.com/prettier/prettier-vscode#prettierdocumentselectors

@ntotten this looks great! Many thanks to you and whomever implemented the feature!

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings