Why Prettier does not format code in VSCODE?

后端 未结 18 596
失恋的感觉
失恋的感觉 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:39

    Prettier could also format your files on save.

    However, installing and enabling does not result in working.

    You have to check "format on Save" in VSCode: Setting >> User >> Text Editor >> Formatting

    0 讨论(0)
  • 2020-12-07 18:43

    If doing what @Simin Maleki mentioned does not solve it for you, there is a chance that your default formatter is not set:

    File > Preferences > Settings > Search for "default formatter" 
    

    Make sure your Editor: Default Formatter field is not null but rather esbenp.prettier-vscode and that all the languages below are ticked. This fixed my issue.

    0 讨论(0)
  • 2020-12-07 18:43

    File Path:

    C:\Users\pgmre\AppData\Roaming\Code\User\settings.json
    

    Change From:

    "[javascript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features"
    },
    

    To:

    "[javascript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    

    Note:

    • If the above is not present, add it instead of changing.
    • You should already have installed the "Prettier - code formatter" to see the effect of the above change.
    0 讨论(0)
  • 2020-12-07 18:43

    can you try to add this section to your user setting file?

     "[javascript]": {
            "editor.defaultFormatter": "esbenp.prettier-vscode",
            //   "editor.formatOnSave": true,
        },
    
    0 讨论(0)
  • 2020-12-07 18:45

    Sometimes, prettier stops working when there are syntactic errors in the code. You can view the errors by clicking on the x button on the bottom right corner beside Prettier

    0 讨论(0)
  • 2020-12-07 18:47

    Enabling "format on Save" in VSCode: Setting >> User >> Text Editor >> Formatting worked for me!

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