Alexander Mills
Alexander Mills

Reputation: 100020

jshint - ignore node_modules directory

I am simply running:

$> jshint .

which looks through my project's directory for .js files, but it is also looking into the node_modules directory which has a shit-ton of .js files that I don't really want to know about.

I might mention that eslint works out of the box to ignore the node_modules directory.

is there a way to run .jshint with a flag to ignore the node_modules directory?

for example

$> jshint . --ignore ./node_modules

?

Upvotes: 1

Views: 6515

Answers (4)

Alexander Mills
Alexander Mills

Reputation: 100020

To ignore the node_modules folder using JSHint, this seems to work best

in your package.json file at the root of your project:

{
  "scripts": {
    "jshint": "jshint --exclude 'node_modules/**/*' ."
  }
}

now you can run this at the command line

npm run jshint

and you won't forget the syntax because you have documented it for yourself

You can also use .jshintignore:

node_modules/**/*

Upvotes: 0

Whyhankee
Whyhankee

Reputation: 903

According to https://jshint.com/docs/cli/#ignoring-files you can also use the .jshintignore file.

Just add:

node_modules/**/*

Upvotes: 8

ericalli
ericalli

Reputation: 1233

The correct syntax for ignoring the node_modlues directory from the .jshintignore file is:

node_modules/**/*

Upvotes: 3

Sachacr
Sachacr

Reputation: 732

You can create a .jshintrc file in the root directory of your project with the following config :

{
   node: true
}

For a full list of options you can look here

Upvotes: 1

Related Questions