简体   繁体   English

如何找到冲突的 eslint 规则

[英]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 中它看起来像这样:

eslint 错误的图片

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.

相关问题 你如何解决 eslint 和 typescript-eslint 之间 VSCode 中冲突的 linting 规则 - How do you resolve conflicting linting rules in VSCode between eslint and typescript-eslint 如何将 typescript-eslint 规则添加到 eslint - How to add typescript-eslint rules to eslint 如何配置@typescript-eslint 规则 - How to configure @typescript-eslint rules 如何使用 ESLint + Prettier + Airbnb 规则 + TypeScript + Vetur 配置 Vue CLI 4? - How to configure Vue CLI 4 with ESLint + Prettier + Airbnb rules + TypeScript + Vetur? ESLint:如何在函数上找到不必要的“异步”标记? - ESLint: How to find unnecessary “async” markers on functions? TypeScript 编译器不遵循 ESLint 规则 - TypeScript compiler not following ESLint rules 如何在 VS Code 编辑器中使用 ESLint + Airbnb 规则 + TypeScript + Stylelint 为 SCSS 配置 Vue CLI 4,并在保存时自动修复? - How to configure Vue CLI 4 with ESLint + Airbnb rules + TypeScript + Stylelint for SCSS, in VS Code editor with autofix on save? @typescript-eslint/naming-convention:如何混合错误和警告规则? - @typescript-eslint/naming-convention: How to mix error and warn rules? @typescript-eslint/no-unsafe-* 规则的新 eslint 错误 - New eslint errors with the @typescript-eslint/no-unsafe-* rules ESLint 找不到插件“eslint-plugin-@typescript-eslint” - ESLint couldn't find the plugin "eslint-plugin-@typescript-eslint"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM