保存时VS代码更漂亮的格式不起作用

时间:2019-12-21 03:38:15

标签: visual-studio-code vscode-settings prettier

大约一个月以来,我的Prettier扩展程序已停止正常运行。最值得注意的是-保存格式不起作用。其他说明:

  • 键入;时的格式有效
  • 我在Prettier按钮旁边的状态栏中看到此错误类型符号-我在Google上找不到与此相关的任何有关Prettier的引用:

    enter image description here]

  • 我在“设置”中检查了保存的格式:

    Format on save

  • “格式化文档,格式选择and使用“命令调色板”选项格式化文档都无济于事

  • 休息的时间恰好是从漂亮的2-3搬来的
  • 我已经执行了迁移步骤,并认为一切正常。我在eslint和更漂亮之间的配置摘要:

    1. 根据the prettier documentation,我的VS代码设置为:
"eslint.autoFixOnSave": true, // (even though VSCode has this as deprecated), have tried with and without this line
"editor.codeActionsOnSave": {
  "source.organizeImports": true,
  "source.fixAll.eslint": true
},
  1. 我的开发依赖项包括:
    "eslint-config-prettier": "^6.5.0",
    "eslint-plugin-prettier": "^3.1.2",
    "prettier-eslint": "^9.0.0",
  1. 我有一个prettier.config.js文件
  2. 我的.eslintrc.js文件包括:
extends: ['airbnb', 'prettier'],
plugins: ['react', 'jsx-a11y', 'import', 'react-hooks', 'plugin:prettier/recommended'],

任何人对如何解决此问题或进一步的调试测试有什么想法吗?真让我发疯!

6 个答案:

答案 0 :(得分:32)

请按照以下步骤操作:

  1. CTRL + SHIFT + P
  2. 格式化文档(在弹出栏中)
  3. 选择Format Document
  4. 选择Configure Default Formatter...
  5. 选择Prettier - Code formatter

完成!

答案 1 :(得分:4)

在VSCode设置中,搜索“编辑器:默认格式化程序”并将其设置为esbenp.prettier-vscode

答案 2 :(得分:2)

对我来说,使用 prettier+(svipas.prettier-plus) -- 因为默认的 prettier 插件不好 -- 只是改变:

"editor.formatOnSaveMode": "modifications",

"editor.formatOnSaveMode": "file",

解决了我的问题。

答案 3 :(得分:1)

配置已更改,您需要将此添加到vs代码设置中:

根据文档:“您可以在保存时为ESLint,TSLint或Stylelint启用自动修复,并且仍然具有格式和快速修复功能”

"editor.codeActionsOnSave": {
  // For ESLint
  "source.fixAll.eslint": true,
  // For TSLint
  "source.fixAll.tslint": true,
  // For Stylelint
  "source.fixAll.stylelint": true
}

答案 4 :(得分:0)

尝试通过按CTRL + SHIFT + P >>>设置文档格式来使代码更漂亮。如果文件格式化没有任何问题,则意味着问题出在formatOnSave设置中。可能您可以尝试从那里进行进一步的调试。

答案 5 :(得分:0)

因为 formatonSave 已经是 checkeddefaultFormatter 更漂亮......当我切换到 settings.json 时,就像!!

"[javascript]": { "editor.formatOnSave": false }, "eslint.autoFixOnSave": true, "prettier.disableLanguages": [ "js" ],

改成后

"[javascript]": { "editor.formatOnSave": true }, "eslint.autoFixOnSave": true, "prettier.disableLanguages": [],

它确实有效...

相关问题