如何找到冲突的 eslint 规则

How to find conflicting eslint rules

在规则中查找冲突的最佳方法是什么?

我要解决的问题如下。有些东西迫使这个三元表达式换行。我怀疑这与长线有关,但我尝试设置 max-len 没有任何变化:

setAdjustmentValue((props.adjustmenttype === AdjustmentTypes.Restock) ? props.selectedsiteunitstock.maximumCapacity - props.selectedsiteunitstock.currentStockLevel : null);

检查到:

setAdjustmentValue(
            props.adjustmenttype === AdjustmentTypes.Restock
                ? props.selectedsiteunitstock.maximumCapacity -
                        props.selectedsiteunitstock.currentStockLevel
                : null
        );

如果我设置 "multiline-ternary": ["error", "never"]

,lint 会失败

这是我的完整配置:

{
    "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"
            }
        }
    }
}

我创建了一个非常简单的项目来进行测试。我非常基本的 .eslintrc 配置文件只包含一个规则 quotes:

{
    "parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "script"
    },
    "rules": {
        "quotes": ["error", "double"]
    }
}

还有我要测试的index.js文件:

let no = 'this is wrong';

let yes = "this is correct bc i enforced double quotes";

现在,运行以下命令:

npx eslint index.js

产生以下输出:

2:10 error Strings must use doublequote quotes

其中“字符串必须使用双引号”后的 引号 是引发错误的规则。

而在 VSCode 中它看起来像这样:

2022 年读者使用

"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^16.1.4",

您需要将此添加到您的 eslintrc(.json):

"@typescript-eslint/semi": ["error", "never"],

在我的用例中,我不想看到任何 fu#king semi。