来自 .eslintrc.json 的规则未被遵守,但 eslint 评论中的相同规则是
A rule from .eslintrc.json isn't being respected, but the same rule in an eslint comment is
当我将规则“react-redux/useSelector-prefer-selectors”放入我的 .eslintrc.json 中时,规则“react-redux/useSelector-prefer-selectors”并未得到遵守,但其他规则受到遵守。然而,当我把
/* eslint react-redux/useSelector-prefer-selectors: "off" */
在有问题的文件的顶部,错误消失了。
我的 .eslintrc.json 文件(在我的根目录中):
{
"env": {
"browser": true,
"commonjs": true,
"es2020": true,
"node": false
},
"extends": [
"airbnb",
"react-app",
"airbnb/hooks",
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:react-redux/recommended"
],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": [
"react",
"react-redux"
],
"rules": {
"indent": [
"warn",
"tab"
],
"no-tabs": "off",
"no-unused-vars": "warn",
"consistent-return": "warn",
"no-mixed-spaces-and-tabs": 0,
"react/prop-types": 0,
"unused-imports/no-unused-imports": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react-redux/useSelector-prefer-selectors": "off",
"react/jsx-indent": "off",
"react/jsx-filename-extension": "off",
"react/jsx-no-useless-fragment": "warn"
}
}
感谢 @guiwme5 的评论,我想通了。虽然我不使用 vscode,但我确实使用 WebStorm - 看起来它们都有同样的问题 - 它们在更改时不会重新加载 .eslintrc.* 文件。
因此,如果您在试图找出 IDE 不遵守 eslint 规则的原因时偶然发现这个问题,请尝试重新启动 IDE。
当我将规则“react-redux/useSelector-prefer-selectors”放入我的 .eslintrc.json 中时,规则“react-redux/useSelector-prefer-selectors”并未得到遵守,但其他规则受到遵守。然而,当我把
/* eslint react-redux/useSelector-prefer-selectors: "off" */
在有问题的文件的顶部,错误消失了。
我的 .eslintrc.json 文件(在我的根目录中):
{
"env": {
"browser": true,
"commonjs": true,
"es2020": true,
"node": false
},
"extends": [
"airbnb",
"react-app",
"airbnb/hooks",
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:react-redux/recommended"
],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": [
"react",
"react-redux"
],
"rules": {
"indent": [
"warn",
"tab"
],
"no-tabs": "off",
"no-unused-vars": "warn",
"consistent-return": "warn",
"no-mixed-spaces-and-tabs": 0,
"react/prop-types": 0,
"unused-imports/no-unused-imports": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react-redux/useSelector-prefer-selectors": "off",
"react/jsx-indent": "off",
"react/jsx-filename-extension": "off",
"react/jsx-no-useless-fragment": "warn"
}
}
感谢 @guiwme5 的评论,我想通了。虽然我不使用 vscode,但我确实使用 WebStorm - 看起来它们都有同样的问题 - 它们在更改时不会重新加载 .eslintrc.* 文件。
因此,如果您在试图找出 IDE 不遵守 eslint 规则的原因时偶然发现这个问题,请尝试重新启动 IDE。