以下是我的.eslintrc.json文件中的代码:

{
    "env": {
      "browser": true,
      "es2021": true
    },
    "extends": ["eslint:recommended", "plugin:react/recommended"],
    "parserOptions": {
      "ecmaVersion": "latest",
      "sourceType": "module"
    },
    "plugins": ["react"],
    "rules": {
      "indent": ["error", "tab"],
      "linebreak-style": ["error", "windows"],
      "quotes": ["error", "single"],
      "semi": ["error", "always"]
    }
  }

这就是错误,每次我try 运行COMMIT时:


PS C:\frontend> git commit -a -m "try"
[STARTED] Preparing lint-staged...
[SUCCESS] Preparing lint-staged...
[STARTED] Running tasks for staged files...
[STARTED] package.json — 3 files
[STARTED] **/*.{js,jsx,json} — 1 file
[STARTED] eslint . --fix
[FAILED] eslint . --fix [FAILED]
[FAILED] eslint . --fix [FAILED]
[FAILED] eslint . --fix [FAILED]
[STARTED] Applying modifications from tasks...
[SKIPPED] Skipped because of errors from tasks.
[STARTED] Reverting to original state because of errors...
[SUCCESS] Reverting to original state because of errors...
[STARTED] Cleaning up temporary files...
[SUCCESS] Cleaning up temporary files...

✖ eslint . --fix:
Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration .

C:\frontend\.eslintrc.json
  3:10  error  Parsing error: Unexpected token :

✖ 1 problem (1 error, 0 warnings)

husky - pre-commit hook exited with code 1 (error)

我想不出这条线路出了什么问题:

 "env": {

如有任何建议,我们将不胜感激! 谢谢!

推荐答案

问题是您正在try 打印JSON文件,但ESLint不支持开箱即用的JSON文件打印.现在你只有两个 Select :

  1. 如果JSON文件链接对您很重要,您可以安装和配置一个支持它的插件,例如eslint-plugin-json
  2. 如果您不关心JSON文件的linting,那么从package.json中的lint脚本中删除json扩展名:
{
  "scripts": {
    "lint-staged": {
      "**/*.{js,jsx}": [ "eslint . --fix" ]
    }
  }
}

Json相关问答推荐

服务器不返回JSON

如何使用JQ将JSON字符串替换为解析后的类似功能?

将JSON输入子数组转换为字符串顺序列表输出

修改Deneb图表中工具提示的字体大小

Jolt变换将字段移动到数组的每个元素中

Vega-Lite(Deneb):难以将最小和最大值应用于折线图和文本标签以及线条末尾的点

如何使用Powershell查找所有包含特定键值对的JSON对象并迭代所有对象?

Vega-Lite规范:尽管在规范中提供了数据,但显示空图表

基于JQ中另一个对象的值 Select 对象

如果值不存在,则将值插入 JSON 数组

将文本转换为 python 列表

一起使用 Argparse 和 Json

Jackson Json:如何将数组转换为 JsonNode 和 ObjectNode?

在 JavaScript 中从 Json 数据中删除反斜杠

jquery用json数据填充下拉列表

将文件发送到 Rails JSON API

使用 Codable 序列化为 JSON 时的 Swift 字符串转义

FastAPI:如何将正文读取为任何有效的 json?

不处理从这里抛出的错误

无法构建 C# 项目