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

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

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

问题

这是我在我的 .eslintrc.json 文件中的代码:

  1. {
  2. "env": {
  3. "browser": true,
  4. "es2021": true
  5. },
  6. "extends": ["eslint:recommended", "plugin:react/recommended"],
  7. "parserOptions": {
  8. "ecmaVersion": "latest",
  9. "sourceType": "module"
  10. },
  11. "plugins": ["react"],
  12. "rules": {
  13. "indent": ["error", "tab"],
  14. "linebreak-style": ["error", "windows"],
  15. "quotes": ["error", "single"],
  16. "semi": ["error", "always"]
  17. }
  18. }

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

  1. PS C:\frontend> git commit -a -m "try"
  2. [STARTED] Preparing lint-staged...
  3. [SUCCESS] Preparing lint-staged...
  4. [STARTED] Running tasks for staged files...
  5. [STARTED] package.json 3 files
  6. [STARTED] **/*.{js,jsx,json} — 1 file
  7. [STARTED] eslint . --fix
  8. [FAILED] eslint . --fix [FAILED]
  9. [FAILED] eslint . --fix [FAILED]
  10. [FAILED] eslint . --fix [FAILED]
  11. [STARTED] Applying modifications from tasks...
  12. [SKIPPED] Skipped because of errors from tasks.
  13. [STARTED] Reverting to original state because of errors...
  14. [SUCCESS] Reverting to original state because of errors...
  15. [STARTED] Cleaning up temporary files...
  16. [SUCCESS] Cleaning up temporary files...
  17. ✖ eslint . --fix:
  18. Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration .
  19. C:\frontend\.eslintrc.json
  20. 3:10 error Parsing error: Unexpected token :
  21. ✖ 1 problem (1 error, 0 warnings)
  22. husky - pre-commit hook exited with code 1 (error)

无法弄清楚这一行有什么问题:

  1. "env": {

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

英文:

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

  1. {
  2. "env": {
  3. "browser": true,
  4. "es2021": true
  5. },
  6. "extends": ["eslint:recommended", "plugin:react/recommended"],
  7. "parserOptions": {
  8. "ecmaVersion": "latest",
  9. "sourceType": "module"
  10. },
  11. "plugins": ["react"],
  12. "rules": {
  13. "indent": ["error", "tab"],
  14. "linebreak-style": ["error", "windows"],
  15. "quotes": ["error", "single"],
  16. "semi": ["error", "always"]
  17. }
  18. }

this is the error, every time I try to run a commit:

  1. PS C:\frontend> git commit -a -m "try"
  2. [STARTED] Preparing lint-staged...
  3. [SUCCESS] Preparing lint-staged...
  4. [STARTED] Running tasks for staged files...
  5. [STARTED] package.json 3 files
  6. [STARTED] **/*.{js,jsx,json} — 1 file
  7. [STARTED] eslint . --fix
  8. [FAILED] eslint . --fix [FAILED]
  9. [FAILED] eslint . --fix [FAILED]
  10. [FAILED] eslint . --fix [FAILED]
  11. [STARTED] Applying modifications from tasks...
  12. [SKIPPED] Skipped because of errors from tasks.
  13. [STARTED] Reverting to original state because of errors...
  14. [SUCCESS] Reverting to original state because of errors...
  15. [STARTED] Cleaning up temporary files...
  16. [SUCCESS] Cleaning up temporary files...
  17. ✖ eslint . --fix:
  18. Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration .
  19. C:\frontend\.eslintrc.json
  20. 3:10 error Parsing error: Unexpected token :
  21. ✖ 1 problem (1 error, 0 warnings)
  22. husky - pre-commit hook exited with code 1 (error)

can not figure out what is wrong with this line:

  1. "env": {

would very much appreciate any suggestions!
thank you!

答案1

得分: 1

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

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

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:
  1. {
  2. "scripts": {
  3. "lint-staged": {
  4. "**/*.{js,jsx}": [ "eslint . --fix" ]
  5. }
  6. }
  7. }

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:

确定