Eslint: warning File ignored by default. Use a negated ignore pattern

11,372

Solution 1

Your npm script runs the linter on the .eslintrc.js file and this file is as the comment says File ignored by default.

You need to change the lint script from:

"lint": "eslint .eslintrc.js --fix",

to:

"lint": "eslint <foldername> --fix"

Where <foldername> is the correct folder.

Solution 2

You can create a .eslintignore file next to .eslintrc.js. Then in .eslintignore put:

!.eslintrc.js
Share:
11,372
Prithviraj Mitra
Author by

Prithviraj Mitra

Updated on June 24, 2022

Comments

  • Prithviraj Mitra
    Prithviraj Mitra almost 2 years

    I am new in using Eslint.

    So far I have installed Eslint in my local project and configured it. The eslintrc.js file contains

    module.exports = {
      env: {
        node: true,
        commonjs: true,
        es6: true,
        mocha: true,
      },
      extends: [
        'airbnb-base',
      ],
      globals: {
        Atomics: 'readonly',
        SharedArrayBuffer: 'readonly',
      },
      parserOptions: {
        ecmaVersion: 2018,
      },
      rules: {
      },
    };
    

    And in package.json I have

      "scripts": {
        "lint": "eslint .eslintrc.js --fix",
    }
    

    In terminal I run

    npm run lint

    And the output is

    > [email protected] lint C:\nodeprojects\restapi
    > eslint .eslintrc.js --fix
    
    
    C:\nodeprojects\restapi\.eslintrc.js
      0:0  warning  File ignored by default.  Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'") to override
    

    But if I run

    eslint <foldername> --fix then it works.

    I am using webstorm IDE and in windows os.

    Any help is highly appreciated.

  • Prithviraj Mitra
    Prithviraj Mitra over 4 years
    Thanks a lot. I have changed to "lint": "eslint . --fix" and I believe that it will run on all the files in the current folder? If so then will it include node_modules folder too? Also, my second question is that then how .eslintrc.js file will be called or related in this whole process.
  • Mac_W
    Mac_W over 4 years
    You can create another file in your root called .eslintignore where you can place folders to be ignored like /node_modules/ in this case.
  • William Swanson
    William Swanson over 4 years
    Also, eslint ignores node_modules and bower_components by default, so you don't need to do anything extra for those.