Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESLint with Mocha

I am trying to use ESLint for mocha, but for some reason the rules don'y apply and the linting passes.

My config file:

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"
            }
        }
    ]
};

My test file only includes one line:

it('should throw a lint error')

The linter should find an error because of the 'no pending tests' rule, yet when I run the test file with eslint the linting passes as a success.

I have no idea why. I looked it up online and it seems like my configuration file is good as it is.

like image 552
Sagi Rika Avatar asked May 05 '19 11:05

Sagi Rika


2 Answers

your solution is the same as this post answer.

However, the one that suits you better is the one you only edit the .eslintrc file as shown in eslint-configuration-doc, which would go like this:

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

}

The line you are aiming is the one with

mocha: true

like image 92
Nicholas Fernandes Paolillo Avatar answered Oct 30 '22 12:10

Nicholas Fernandes Paolillo


This solution worked for me.

{
    "env": {
        "browser": true,
        "es6": true,
        "mocha": true // add mocha as true to your ".eslintrc. *" file
    }
}
like image 38
Marcos Santos Dev Avatar answered Oct 30 '22 11:10

Marcos Santos Dev