英文:
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 文件进行审查。现在你有两个选择:
- 如果 JSON 文件的审查对你很重要,你可以安装并配置一个支持此功能的插件,例如 eslint-plugin-json。
- 如果你不关心 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:
- If JSON file linting is important to you, you can install and configure a plugin which supports this, such as eslint-plugin-json
- If you don't care about linting your JSON files, remove the
json
extension from your lint script in yourpackage.json
:
{
"scripts": {
"lint-staged": {
"**/*.{js,jsx}": [ "eslint . --fix" ]
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论