【问题标题】:ESLint producing different output when run with npm run-scriptESLint 在使用 npm run-script 运行时产生不同的输出
【发布时间】:2023-04-03 09:52:01
【问题描述】:

当我使用 eslint scripts/**/*.js 对代码进行 lint 时,我看到两个 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)

没关系。当我将该命令放入我的package.json 中的"scripts" 时,我只会收到一个错误。

// 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)

其他 linting 错误发生了什么?

编辑 我开始怀疑这是一个全局问题。缺少的 linting 错误位于不在 scripts 子目录中的文件中。

【问题讨论】:

    标签: npm eslint


    【解决方案1】:

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

    诀窍是将路径匹配器用单引号括起来,以便在将它们传递给 eslint 之前在 shell 级别扩展它们。

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

    【讨论】:

      【解决方案2】:

      听起来大卫的回答解决了他遇到的问题。但是,我的症状与所描述的问题相同。

      在我的情况下,问题是 npm 正在使用项目目录中的 node_modules,它的插件版本与全局 npm 文件夹的版本不同。

      从命令行运行 eslint 使用的是全局版本。协调这些版本解决了我的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-03-28
        • 2022-07-24
        • 2021-03-03
        • 2018-12-12
        • 2022-06-16
        • 2021-04-10
        • 2015-12-14
        • 2018-09-07
        相关资源
        最近更新 更多