jfunk
jfunk

Reputation: 8162

Eslint glob (**) is not considering all directories recursively

I am using OSX, in my package.json file I have the script entry:

"lint": "eslint ./src/**/*.js"

However, when I run npm lint only the 1st level of directories are being considered for linting, eg. ./src/dir/* not ./src/dir/nested_dir/*.

I was under the impression that ** glob indicated recursive search?

Does anyone know how I can make this behave as expected?

Upvotes: 37

Views: 18395

Answers (4)

jfunk
jfunk

Reputation: 8162

The problem is likely missing quotes around the glob path.

Change this (not working): "lint": "eslint ./src/**/*.js"

To this (working): "lint": "eslint './src/**/*.js'"

The ESLint docs say this:

Please note that when passing a glob as a parameter, it is expanded by your shell. The results of the expansion can vary depending on your shell, and its configuration. If you want to use node glob syntax, you have to quote your parameter (using double quotes if you need it to run in Windows)

And some Googling turned up this thread on GitHub:

Upvotes: 81

Mynameisbt
Mynameisbt

Reputation: 1

This also occurs when linting using vue-cli-service so you will need quotes with it as well:

"lint": "vue-cli-service lint './src/main/app/**/*.ts' './src/main/app/**/*.vue'"

Upvotes: 0

This command is working recursively in monorepos (first glob is for all subfolders in packages, second one, is for any subfolder in src). Without second glob, the command does not work.

"lint": "eslint 'packages/**/src/**' --ext .ts,.tsx"

Upvotes: 0

Udi
Udi

Reputation: 30532

Try this instead:

"lint": "eslint src --ext .js"

Or for more than one extension:

"lint": "eslint src --ext .js,.jsx,.ts,.tsx"

See more info on eslint's docs

Upvotes: 21

Related Questions