Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESLint producing different output when run with npm run-script

Tags:

npm

eslint

When I lint my code with eslint scripts/**/*.js I see two linting errors:

» eslint scripts/**/*.js
/Users/user/dev/scripts/application.js
  3:8  error  "React" is defined but never used  no-unused-vars

/Users/user/dev/scripts/components/Header.js
  24:2  error  Unnecessary semicolon  no-extra-semi

✖ 2 problem (2 error, 0 warnings)

That's fine. When I put that command into "scripts" in my package.json then I only get one error.

// package.json
// ...
"scripts": {
  "lint": "eslint scripts/**/*.js"
}
// ...


» npm run lint
/Users/david.tuite/dev/ui/scripts/components/Header.js
  24:2  error  Unnecessary semicolon  no-extra-semi

✖ 2 problems (2 errors, 0 warnings)

What's happening to the other linting error?

edit I'm starting to suspect this is a globbing problem. The missing linting error is in a file which isn't in a subdirectory of scripts.

like image 589
David Tuite Avatar asked Jan 04 '16 13:01

David Tuite


2 Answers

Globs work differently in the package.json file.

The trick is to wrap the path matchers in single quotes to have them expanded at the shell level before they're passed to eslint.

// package.json
// ...
"scripts": {
  "lint": "eslint 'scripts/**/*.js'"
}
// ...
like image 76
David Tuite Avatar answered Sep 18 '22 17:09

David Tuite


Sounds like David's answer solved the problem he was encountering. However, I had an identical symptom to the problem described.

In my case the problem was that npm was using the node_modules in the project directory which had a different version of the plugin than the global npm folder had.

Running eslint from command line was using the global version. Reconciling those versions resolved the issue in my case.

like image 31
Dustin Graham Avatar answered Sep 21 '22 17:09

Dustin Graham