使用npm run-script运行时,ESLint会产生不同的输出 [英] ESLint producing different output when run with npm run-script

查看:85
本文介绍了使用npm run-script运行时,ESLint会产生不同的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用 eslint脚本/**/*.js 填充代码时,我看到两个掉毛错误:

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)

很好.当我将该命令放入 package.json 中的"scripts" 中时,我只会遇到一个错误.

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?

修改我开始怀疑这是一个问题.缺少的掉毛错误位于文件中,该文件不在 scripts 的子目录中.

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.

推荐答案

全局文件在 package.json 文件中的工作方式有所不同.

Globs work differently in the package.json file.

诀窍是将路径匹配器用单引号引起来,以便在将其传递给eslint之前在shell级别进行扩展.

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'"
}
// ...

这篇关于使用npm run-script运行时,ESLint会产生不同的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆