使用npm run-script运行时,ESLint生成不同的输出

Dav*_*ite 7 npm eslint

当我使用lint我的代码时,eslint scripts/**/*.js我看到两个linting错误:

» 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)
Run Code Online (Sandbox Code Playgroud)

没关系.当我把那个命令放进"scripts"我的package.json时候我只得到一个错误.

// 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)
Run Code Online (Sandbox Code Playgroud)

另一个linting错误发生了什么?

编辑 我开始怀疑这是一个全球性的问题.丢失的linting错误位于不在子目录中的文件中scripts.

Dav*_*ite 14

Globs在package.json文件中的工作方式不同.

诀窍是将路径匹配器包装在单引号中,以便在它们传递给eslint之前在shell级别进行扩展.

// package.json
// ...
"scripts": {
  "lint": "eslint 'scripts/**/*.js'"
}
// ...
Run Code Online (Sandbox Code Playgroud)