繁体   English   中英

如何找到冲突的 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 配置文件只包含一个规则引号

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

产生以下 output:

2:10 错误字符串必须使用双引号

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

在 VSCode 中它看起来像这样:

eslint 错误的图片

对于 2022 年的读者使用

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM