【问题标题】:@typescript-eslint/no-unused-vars raises a warn where it shouldn't@typescript-eslint/no-unused-vars 在不应该的地方发出警告
【发布时间】:2021-02-13 05:51:37
【问题描述】:

我正在尝试使用 webpack、typescript 和 eslint 启动一个项目。我在这里收到警告@typescript-eslint/no-unused-vars

如果没有达到env,我就无法达到argv 的价值。在这种情况下避免错误的唯一方法是模拟变量env的使用吗?

我的 eslint.json

{
    "env": {
        "browser": true,
        "node": true,
        "es2020": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended",
        "plugin:@typescript-eslint/recommended"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true,
            "modules": true,
            "arrowFunctions": true,
            "classes": true
        },
        "ecmaVersion": 11,
        "sourceType": "module"
    },
    "plugins": [
        "react",
        "@typescript-eslint",
        "import"
    ],
    "rules": {
        "no-console": ["error", {
            "allow": ["timeEnd", "warn"]
        }],
        "func-names": "off",
        "linebreak-style": ["error", "windows"],
        "no-plusplus": "off",
        "max-len": ["error", {"code":  120}],
        "indent": ["error", 4, {
            "ignoredNodes": ["JSXElement *"]
        }],
        "arrow-parens": ["error", "as-needed"],
        "import/order": ["error", {
            "pathGroups": [{
                "pattern": "@*/**",
                "group": "parent",
                "position": "before"
            }],
            "groups": ["builtin", "external", "internal", "parent", "sibling", "index"],
            "alphabetize": {"order": "asc"}
        }]
    }
}

【问题讨论】:

    标签: typescript webpack eslint


    【解决方案1】:

    您可以为此 eslint 规则定义一个正则表达式,以使用属性 argsIgnorePattern 指示已知未使用的函数参数。一种常见的正则表达式是"argsIgnorePattern": "^_",用于忽略所有以下划线开头的变量。有了这个配置,你可以写:

    module.exports = (_: {} = {}, argv: {} = {}) => {
    

    有关信息,这是我的配置:

      '@typescript-eslint/no-unused-vars':
        - error
        - argsIgnorePattern: '^_'
    

    【讨论】:

    • 谢谢,但没用
    • 您还需要什么?不能修改 eslint 配置吗?
    • 我确实修改了我的配置,但警告没有消失
    • 我的错,这不是 varsIgnorePattern 而是 argsIgnorePattern 用于函数参数。我更新了答案。
    猜你喜欢
    • 2020-01-25
    • 2021-02-22
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 2019-09-12
    相关资源
    最近更新 更多