eslint Oops! Something went wrong!
遇到老多次了
problem
eslint检查报错:
Oops! Something went wrong!
完整报错信息
> running pre-commit hook: npm run precommit
> ant-design-pro@5.0.0 precommit
> lint-staged
✔ Preparing...
⚠ Running tasks...
↓ No staged files match **/*.less [SKIPPED]
❯ Running tasks for **/*.{js,jsx,ts,tsx}
✖ npm run lint-staged:js [FAILED]
✔ Running tasks for **/*.{js,jsx,tsx,ts,less,md,json}
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up...
✖ npm run lint-staged:js:
Oops! Something went wrong! :(
ESLint: 7.32.0
ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:
eslint --init
ESLint looked for configuration files in /path/to/src/pages/NewFun and its ancestors. If it found none, it then looked in your home directory.
If you think you already have a configuration file or if you need more help, please stop by the ESLint chat room: https://eslint.org/chat/help
> ant-design-pro@5.0.0 lint-staged:js
> eslint --ext .js,.jsx,.ts,.tsx "/path/to/src/pages/NewFun/index.tsx"
pre-commit hook failed (add --no-verify to bypass)
reason
git commit 出现eslint报错
原因是工程没有 .eslintrc.js 配置文件
solution1
可能是项目拷贝过程,丢失了因此文件 .eslintrc.js
solution2
根据提示执行 eslint --init
然后再 git commit 出现语法检查提示
22:16 error Component definition is missing display name react/display-name
24:5 error 'React' must be in scope when using JSX react/react-in-jsx-scope
25:7 error 'React' must be in scope when using JSX react/react-in-jsx-scope
32:7 error 'React' must be in scope when using JSX react/react-in-jsx-scope
方法
- 根据语法提示 修复问题
- .eslintrc.js rule中关闭规则
- .eslintignore 添加忽略检查的文件
// .eslintrc.js
module.exports = {
//...
"rules": {
"react/react-in-jsx-scope":0,
"@typescript-eslint/ban-ts-comment": 0,
"react/prop-types": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"react/display-name": 0,
}
};
// .eslintignore
src/e2e/baseLayout.e2e.js