vscode 使用prettier 格式化错误

clipboard.png

这种情况要如何解决?彻底删除了 重新安装也不行
阅读 7.4k
2 个回答

这个不能格式化React jsx吧,换个插件格式化吧
试试rc-beautify

你应该没配置eslint,prettier格式化之后没有通过eslint格式检查,在prettier里面设置使用eslint语法格式化,以下配置参考下:

{
  "workbench.editor.enablePreview": false, //打开文件不覆盖
  "search.followSymlinks": false, //关闭rg.exe进程
  "editor.minimap.enabled": true, //打开快速预览
  "files.autoSave": "afterDelay", //打开自动保存
  "editor.quickSuggestions": {
    //开启自动显示建议
    "other": true,
    "comments": true,
    "strings": true
  },
  "editor.tabSize": 2, //制表符符号eslint
  // "editor.formatOnSave": true, // 每次保存的时候将代码按eslint格式进行修复
  "prettier.singleQuote": true, //使用单引号替代双引号
  "prettier.eslintIntegration": true, // //让prettier使用eslint的代码格式进行校验
  "javascript.format.insertSpaceBeforeFunctionParenthesis": true, //让函数(名)和后面的括号之间加个空格
  "vetur.format.defaultFormatter.html": "js-beautify-html", //格式化.vue中html
  "vetur.format.defaultFormatter.js": "vscode-typescript", //让vue中的js按编辑器自带的ts格式进行格式化
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      "wrap_attributes": "force-aligned" //属性强制折行对齐
    }
  },
  "eslint.validate": [
    //开启对.vue文件中错误的检查
    "javascript",
    "javascriptreact",
    // "html5",
    // "vue"
    {
      "language": "html",
      "autoFix": true
    },
    {
      "language": "vue",
      "autoFix": true
    }
  ],
  // 在 vscode 中排除 node_modules 等文件夹
  "files.exclude": {
    "**/.git": true,
    "**/.svn": true,
    "**/.hg": true,
    "**/CVS": true,
    "**/.DS_Store": true,
    "**/node_modules": true,
    "**/package-lock.json": true
  },

  // 指定python编译器路径
  "python.pythonPath": "D:/python35/python.exe",
  "markdown.extension.preview.autoShowPreviewToSide": true,
  "eslint.autoFixOnSave": true,
  "sync.gist": "d592ea9cfb18d1552bccc8421e85fd15",
  "sync.quietSync": false,
  "sync.removeExtensions": true,
  "sync.syncExtensions": true,
  "sync.autoDownload": false,
  "sync.autoUpload": false,
  "sync.forceDownload": false,
  "workbench.iconTheme": "vscode-icons",
  "prettier.printWidth": 100,
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进