Skip to content
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

How to use this plugin with prettier in Visual Studio Code (vscode) #12

Open
mattez opened this issue Apr 11, 2020 · 3 comments
Open

How to use this plugin with prettier in Visual Studio Code (vscode) #12

mattez opened this issue Apr 11, 2020 · 3 comments

Comments

@mattez
Copy link

mattez commented Apr 11, 2020

Hi,
thank you very much in advance for any tips how to use this plugin with prettier in Visual Studio Code (vscode).

@mattez
Copy link
Author

mattez commented Apr 11, 2020

I just installed this via npm i -D git+ssh://git@github.com/justrhysism/prettier-plugin-nunjucks to my project.
I tried to setup this plugin as custom parser in .prettierrc:

{
    "tabs": "true",
    "tabWidth": 4,
    "parser": "prettier-plugin-nunjucks",
}

It end with error ofcourse:

["ERROR" - 6:13:53 PM] Error formatting document.
["ERROR" - 6:13:53 PM] Couldn't resolve parser "prettier-plugin-nunjucks"

:) you see, I do not know how to do it right. Thank you for your help.

@mubaraqwahab
Copy link

Hello,

This is coming quite late, but I hope it still helps:

The name of the parser appears to be "nunjucks":

parsers: ["nunjucks"],

Prettier's documentation also mentions that you should Never put the parser option at the top level of your configuration. Only use it inside overrides. That means your config file should look something like this instead:

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

You don't have to specify the plugin in the config file, Prettier will try to find it automatically. But if you have to specify, you can do:

{
  "overrides": [
    {
      "files": "*.njk",
      "options": {
        "parser": "nunjucks",
        "plugins": ["./node_modules/prettier-plugin-nunjucks"]
      }
    }
  ]
}

You can read more in the Plugins documentation.

@guilleliss
Copy link

Running $ npm i -D git+ssh://git@github.com/justrhysism/prettier-plugin-nunjucks I get:

npm ERR! Found: prettier@2.7.1
npm ERR! node_modules/prettier
npm ERR!   dev prettier@"^2.7.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer prettier@"^1.19.0" from prettier-plugin-nunjucks@0.0.1
npm ERR! node_modules/prettier-plugin-nunjucks
npm ERR!   dev prettier-plugin-nunjucks@"git+ssh://git@github.com/justrhysism/prettier-plugin-nunjucks" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Any alternative that works with latest prettier version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants