ESLint 与摩卡

ESLint with Mocha

我正在尝试将 ESLint 用于 mocha,但由于某些原因规则不适用并且 linting 通过。

我的配置文件:

module.exports = {
    "env": {
        "browser": true,
        "es6": true,
        "node": true,
    },
    "extends": "eslint:recommended",
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly",
        "expect": "true"
    },
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    overrides: [
        {
            files: [
                "**/*.test.js"
            ],
            env: {
                mocha: true
            },
            plugins: ["mocha"],
            rules: {
                "mocha/no-exclusive-tests": "error",
                "mocha/no-pending-tests": "error"
            }
        }
    ]
};

我的测试文件只有一行:

it('should throw a lint error')

由于 'no pending tests' 规则,linter 应该发现错误,但是当我 运行 使用 eslint 的测试文件时,linting 成功通过。

我不知道为什么。网上查了下,好像我的配置文件还不错

您的解决方案与此相同post

然而,更适合您的是您只编辑 .eslintrc 文件的那个,如 eslint-configuration-doc 所示:

module.exports = {
  env: {
    browser: false,
    es6: true,
    node: true,
    mocha: true
   }
 // More code to go on that is not relative to your question ...

}

你瞄准的线是

mocha: true

这个解决方案对我有用。

{
    "env": {
        "browser": true,
        "es6": true,
        "mocha": true // add mocha as true to your ".eslintrc. *" file
    }
}