Why Prettier does not format code in VSCODE?

后端 未结 18 598
失恋的感觉
失恋的感觉 2020-12-07 18:39

In my Nuxt application where ESlint and Prettier are installed and enabled, I switched to Visual Studio Code editor.

When I open a .vue file and pre

相关标签:
18条回答
  • 2020-12-07 18:57

    For me - it was to do with ESlint which also works with Prettier. Eslint wasn't working (a local installation vs global installation conflict) which broke Prettier.

    0 讨论(0)
  • 2020-12-07 19:01

    Don't forget to enable "editor.defaultFormatter" in the settings of the VSCode. In my case it was null and hence even the "editor.formatOnSave" was also not seeming to solve the issue.

    0 讨论(0)
  • 2020-12-07 19:03

    How I've sorted it after having super huge frustrations with Prettier stopping working in VSCode.

    1. Select VS Code -> View -> Command Palette, and type: Format Document With
    2. Then Configure Default Formatter... and then choose Prettier - Code formatter.

    This sorted the problem for me magically.

    Depending on your case this might help you...

    0 讨论(0)
  • 2020-12-07 19:03

    This is not a problem with Prettier itself, but prettier-vscode, the VSCode extension. According to its documentation, Vue formatting is disabled by default:

    prettier.disableLanguages (default: ["vue"])

    A list of languages IDs to disable this extension on. Restart required. Note: Disabling a language enabled in a parent folder will prevent formatting instead of letting any other formatter to run

    In this case, to enable you should set "prettier.disableLanguages": []. And since this is an extension configuration, you should do it in VSCode settings file, not .prettierrc.

    0 讨论(0)
  • 2020-12-07 19:03

    I am not using Vue, but had the same problem.

    I already had the settings

    • Editor: default formatter to prettier
    • Editor: Format on Save to true
    • I already had .eslintrc.js and .prettierrc files But nothing worked.

    The solution to my problem was that I had all set properly, except I needed to:

    • Command + Shift + p
    • type format document with
    • select Configure Default Formatter...
    • select Prettier as default.

    I don't know why the Editor: Format on Save set to true was not enough. I needed to select default formatter using the above steps so it worked.

    0 讨论(0)
  • 2020-12-07 19:06

    If none of the other answers work, check that a conflicting prettier config .prettierrc does not exist in your working directory or check for .prettierignore to be sure the files/folders are not being ignored.

    0 讨论(0)
提交回复
热议问题