似乎有一些规则让我的配置让系统知道使用 ESLint 并不总是有效。我在 VSCode 中启用了“自动格式”保存。
例如,这有一个 ESLint 错误no-confusing-arrow
:
getOptionSelected={option =>
typeof option === 'string' ? option : option.description
}
如果我运行eslint --fix
它更新以将括号包裹为表达式:
getOptionSelected={option =>
(typeof option === 'string' ? option : option.description)
}
但是,如果我保存,它会撤消更改并返回错误。
我的 ESLint 如下:
{
"root": true,
"parser": "@babel/eslint-parser",
"extends": [
"plugin:prettier/recommended",
"plugin:jest/recommended",
"plugin:testing-library/react",
"airbnb",
"eslint:recommended",
"next"
],
"plugins": ["prettier", "simple-import-sort"],
"env": {
"browser": true,
"es6": true,
"node": true,
"jest": true
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"settings": {
"react": {
"version": "detect"
},
"import/resolver": {
"alias": {
"map": [["@", "./"]],
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
},
"rules": {
"arrow-parens": "off",
"camelcase": "error",
"comma-dangle": "off",
"consistent-return": "off",
"function-paren-newline": "off",
"implicit-arrow-linebreak": "off",
"indent": "off",
"jsx-a11y/alt-text": "off",
"jsx-a11y/click-events-have-key-events": "off",
"jsx-a11y/no-noninteractive-element-interactions": "off",
"jsx-a11y/no-static-element-interactions": "off",
"no-restricted-globals": "off",
"no-return-assign": "off",
"no-console": ["error", { "allow": ["warn", "error", "dir", "debug"] }],
"no-unused-vars": "error",
"object-curly-newline": "off",
"operator-linebreak": "off",
"prefer-arrow-callback": "error",
// Jest
"jest/expect-expect":"error",
// React
"react/destructuring-assignment": "error",
"react/forbid-prop-types": "off",
"react/jsx-curly-newline": "off",
"react/jsx-filename-extension": "off",
"react/jsx-one-expression-per-line": "off",
"react/jsx-props-no-spreading": "off",
"react/jsx-wrap-multilines": "off",
"react/no-array-index-key": "warn",
"react/require-default-props": "warn",
// "react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error",
// Sorting autofix overrides
"import/order": "off",
"sort-imports": "off",
"import/extensions": "off",
"import/prefer-default-export": "off",
"import/no-named-as-default": "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error",
},
}
漂亮的:
module.exports = {
bracketSpacing: true,
printWidth: 80,
singleQuote: true,
trailingComma: 'es5',
arrowParens: 'avoid',
};
如您所见,我prettier
将更漂亮的错误显示为 ESLint 错误。
什么可以在保存时关闭括号?
编辑:我尝试查看其他 ESLint 规则,例如no-extra-parens,但没有成功
编辑 2:我在我的 VSCode 中禁用了 Prettier,并且保存正确持久,所以它似乎与 Prettier 发生了经过验证的冲突。我可以更改什么设置来保持 Prettier 不会出现这种冲突?