[英]How to find conflicting eslint rules
What is the best way to find conflicts within the rules?在规则中查找冲突的最佳方法是什么?
The problem I am trying to solve is a follows.我要解决的问题如下。 Something is forcing this ternary expression onto new lines.
有些东西迫使这个三元表达式换行。 I suspect it's something to do with long lines but I've tried setting max-len with no change:
我怀疑这与长线有关,但我尝试过设置max-len而不做任何更改:
setAdjustmentValue((props.adjustmenttype === AdjustmentTypes.Restock) ? props.selectedsiteunitstock.maximumCapacity - props.selectedsiteunitstock.currentStockLevel : null);
linted to:棉绒到:
setAdjustmentValue(
props.adjustmenttype === AdjustmentTypes.Restock
? props.selectedsiteunitstock.maximumCapacity -
props.selectedsiteunitstock.currentStockLevel
: null
);
The lint fails if I set "multiline-ternary": ["error", "never"]
如果我设置
"multiline-ternary": ["error", "never"]
则 lint 失败
Here is my full config:这是我的完整配置:
{
"env": {
"browser": true,
"es2020": true
},
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["react", "@typescript-eslint", "react-hooks"],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/jsx-filename-extension": [
1,
{
"extensions": [".tsx"]
}
],
"import/prefer-default-export": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"react/jsx-one-expression-per-line": "off",
"no-use-before-define": "off",
"no-unexpected-multiline": 2,
"dot-location": ["error", "object"],
"linebreak-style": ["error", "windows"],
"brace-style": "off",
"max-len": [
"error",
{
"code": 9999999
}
],
"@typescript-eslint/brace-style": [
"error",
"allman",
{
"allowSingleLine": false
}
],
"arrow-body-style": ["error", "as-needed"],
"curly": ["error", "multi-or-nest"],
"jsx-quotes": ["error", "prefer-double"],
"quotes": ["off"],
"@typescript-eslint/quotes": ["error", "single"],
"comma-dangle": "off",
"@typescript-eslint/comma-dangle": ["error", "never"],
"array-element-newline": [
"error",
{
"minItems": 3
}
],
"array-bracket-newline": [
"error",
{
"multiline": true
}
],
"indent": ["off"],
"@typescript-eslint/indent": ["error", "tab"],
"multiline-ternary": ["error", "never"]
},
"settings": {
"import/resolver": {
"typescript": {}
},
"settings": {
"react": {
"version": "detect"
}
}
}
}
I've created a very plain project to test things out.我创建了一个非常简单的项目来测试。 My very basic.eslintrc config file containing only one rule quotes :
我非常基本的.eslintrc 配置文件只包含一个规则引号:
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "script"
},
"rules": {
"quotes": ["error", "double"]
}
}
And my index.js file which is going to be tested:还有我要测试的 index.js 文件:
let no = 'this is wrong';
let yes = "this is correct bc i enforced double quotes";
Now, running the following command:现在,运行以下命令:
npx eslint index.js
Yields the following output:产生以下 output:
2:10 error Strings must use doublequote quotes
2:10 错误字符串必须使用双引号
where quotes after "String must use doublequote" is the rule that raised the error.其中“字符串必须使用双引号”后的引号是引发错误的规则。
And in VSCode it looks like this:在 VSCode 中它看起来像这样:
For readers in 2022 using对于 2022 年的读者使用
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^16.1.4",
you will need to add this to your eslintrc(.json):您需要将其添加到您的 eslintrc(.json) 中:
"@typescript-eslint/semi": ["error", "never"],
in my use case I don't want to see any fu#king semi.在我的用例中,我不想看到任何 fu#king semi。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.