【问题标题】:How to remove Prettier errors from blocking page render如何从阻塞页面渲染中删除 Prettier 错误
【发布时间】:2021-03-10 20:36:56
【问题描述】:

由于错误消息无法查看页面:

可忽略的更漂亮的错误正在阻止页面本身,我如何禁用此功能? 当前设置:

.prettierrc

{
  "printWidth": 120,
  "trailingComma": "all",
  "tabWidth": 2,
  "semi": false,
  "singleQuote": true,
  "endOfLine": "auto"
}

.eslintrc.json

{
"parserOptions": {
  "ecmaVersion": 2018,
  "sourceType": "module",
  "ecmaFeatures": {
    "jsx": true
  }
},
"extends": [
  "airbnb-base",
  "plugin:prettier/recommended",
  "prettier/react"
],
"env": {
  "es6": true, 
  "browser": true
},
"plugins": [
  "prettier"
],
"rules": {
  "prettier/prettier": ["error", {
    "endOfLine": "auto"
  }]
}
}

【问题讨论】:

  • 也许你可以试试this,它会禁用prettier

标签: reactjs eslint prettier


【解决方案1】:

我建议您将环境配置为 formatOnSave,然后您的更漂亮的错误将立即得到修复。您不必费心消除一些愚蠢的打字错误,同时保持您的代码质量。如果您使用 vscode,您可以安装 eslint 扩展并在您的 .vscode 工作区设置或全局配置:

{
  "eslint.validate": [ "javascript", "html"],

  "eslint.options": {
    "extensions": [".js", "html"]
  },
  "editor.formatOnSave": true,
  "files.trimFinalNewlines": true,
  "files.trimTrailingWhitespace": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
  }
}

【讨论】:

    猜你喜欢
    • 2015-05-06
    • 2021-04-16
    • 2019-05-27
    • 2022-06-08
    • 1970-01-01
    • 2016-01-26
    • 1970-01-01
    • 1970-01-01
    • 2013-08-03
    相关资源
    最近更新 更多