error Parsing error: Unexpected token : in my .eslintrc.json file. Why?

huangapple go评论61阅读模式
英文:

error Parsing error: Unexpected token : in my .eslintrc.json file. Why?

问题

这是我在我的 .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"]
    }
  }

这是错误,每次我尝试运行提交时的错误:


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": {

非常感谢任何建议!谢谢!

英文:

this is my code in my .eslintrc.json file:

{
    "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"]
    }
  }

this is the error, every time I try to run a 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)

can not figure out what is wrong with this line:

 "env": {

would very much appreciate any suggestions!
thank you!

答案1

得分: 1

问题在于你试图对一个 JSON 文件进行代码审查,但 ESLint 不支持默认情况下对 JSON 文件进行审查。现在你有两个选择:

  1. 如果 JSON 文件的审查对你很重要,你可以安装并配置一个支持此功能的插件,例如 eslint-plugin-json
  2. 如果你不关心 JSON 文件的审查,可以从你的 package.json 中的审查脚本中删除 json 扩展名:
{
  "scripts": {
    "lint-staged": {
      "**/*.{js,jsx}": [ "eslint . --fix" ]
    }
  }
}
英文:

The problem is that you are trying to lint a JSON file, but ESLint doesn't support linting of JSON files out of the box. You are left with two options now:

  1. If JSON file linting is important to you, you can install and configure a plugin which supports this, such as eslint-plugin-json
  2. If you don't care about linting your JSON files, remove the json extension from your lint script in your package.json:
{
  "scripts": {
    "lint-staged": {
      "**/*.{js,jsx}": [ "eslint . --fix" ]
    }
  }
}

huangapple
  • 本文由 发表于 2023年6月6日 15:53:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76412488.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定