Suppress a specific ESLint warning: File ignored by default

2.6k views Asked by At

Hopefully this is a reasonable question but it's possible I'm misunderstanding something. I get this warning raised on 9 seemingly random .js files in my project's node_modules dependency directory when I run ESLint from grunt. For example:

node_modules/cosmiconfig/node_modules/js-yaml/lib/js-yaml/type/js/function.js
  0:0  warning  File ignored by default. Use "--ignore-pattern '!node_modules/*'" to override

The docs say,

/node_modules/* and /bower_components/* in the project root are ignored by default

That's all well and good, but I don't want these warnings raised every time I lint my actual code.

I have tried explicitly adding the /node_modules/* pattern to the .eslintignore in my project root, which hasn't helped. Using the command line flag suggested just makes ESLint raise errors on my dependencies, which isn't what I want either.

Is there a way to tell ESLint that I explicitly don't want to lint my dependencies so that this warning won't be raised? Having a default that raises warnings and cannot be turned off seems pretty silly.

Thanks for any help. Here are some of the relevant configs (full code is in the repo but of course node_modules is not checked in): https://github.com/jshields/joshuashields.com/blob/master/.eslintrc.js https://github.com/jshields/joshuashields.com/blob/master/.eslintignore https://github.com/jshields/joshuashields.com/blob/master/package.json

2

There are 2 answers

0
JHS On BEST ANSWER

My problem was the files that I was targeting in my Gruntfile.js. My task was reaching down into the node_modules instead of my own code. I changed '**/js/*.js' to simply 'js/*.js':

diff --git a/Gruntfile.js b/Gruntfile.js
index 6b549f7..872abb2 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -10,7 +10,7 @@ module.exports = function(grunt) {
                     //configFile:
                 },
                 files: {
-                    src: ['Gruntfile.js', 'stylelint.config.js', '**/js/*.js']
+                    src: ['Gruntfile.js', 'stylelint.config.js', 'js/*.js']
                 }
             }
         },
1
Wayrex On

Can you try adding **/node_modules/* and **/bower_components/* to see if it solves the problem? (It might be that you have nested node_modules and bower_components).

Resulting .eslintignore:

/node_modules/*
**/node_modules/*
/bower_components/*
**/bower_components/*