【问题标题】:Eslint fix throw error even on json file?即使在 json 文件上,Eslint 也能修复抛出错误?
【发布时间】:2021-01-14 14:49:26
【问题描述】:

所以我正在使用 eslint 来修复我的文件格式,这是我的依赖项。

"devDependencies": {
 "@typescript-eslint/eslint-plugin": "^3.10.1",
 "@typescript-eslint/parser": "^3.10.1",
 "babel-eslint": "^10.1.0",
 "eslint": "^6.8.0",
 "eslint-config-prettier": "^6.12.0",
 "eslint-plugin-flowtype": "^5.2.0",
 "eslint-plugin-import": "^2.22.0",
 "eslint-plugin-jsx-a11y": "^6.3.1",
 "eslint-plugin-prettier": "^3.1.4",
 "eslint-plugin-react": "^7.20.6",
 "eslint-plugin-react-hooks": "^4.1.2",
 "husky": "^4.3.0",
 "lint-staged": "^10.4.0",
 "prettier": "^2.1.1"
},

这是我的 lint 暂存

 "lint-staged": {
   "!(node_modules|build)/**/*.{js,tsx,json,css,scss,html}": [
    "prettier --write",
    "eslint --fix"
   ]
  }

但是它会在我的 json 文件中抛出错误

  1:1  error  Expected an assignment or function call and instead saw an expression  no-unused- 
expressions

虽然我的 JSON 文件是这样的

{
  "homeTitle": "Hello <br/> <strong>World</strong>"
}

我可以知道我的 JSON 文件有什么问题吗?

【问题讨论】:

    标签: javascript node.js json eslint


    【解决方案1】:

    如果你想 lint json 文件,你需要使用 eslint-plugin-json。

    【讨论】:

      猜你喜欢
      • 2017-03-10
      • 2021-12-22
      • 2021-03-13
      • 2018-08-06
      • 2021-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-18
      相关资源
      最近更新 更多