繁体   English   中英

eslint 应该列在项目的依赖项中,而不是 devDependencies

[英]eslint should be listed in the project's dependencies, not devDependencies

要么我不理解节点 100% 中的dependencies项与devDependencies ,要么 eslint 在这里是错误的(无法正确分析):

   3:1   error  'chai' should be listed in the project's dependencies, not devDependencies              import/no-extraneous-dependencies
   4:1   error  'chai-enzyme' should be listed in the project's dependencies, not devDependencies       import/no-extraneous-dependencies
   5:1   error  'enzyme' should be listed in the project's dependencies, not devDependencies            import/no-extraneous-dependencies
   7:1   error  'sinon' should be listed in the project's dependencies, not devDependencies             import/no-extraneous-dependencies
   9:1   error  'redux-mock-store' should be listed in the project's dependencies, not devDependencies  import/no-extraneous-dependencies

这些是测试依赖项,为什么说它们应该列在dependencies中?

附加说明:我们使用 Travis 作为我们的 CI,所以我也不知道这是否会有所作为。

将此添加到我的.eslintrc解决了它:

"import/no-extraneous-dependencies": ["error", {"devDependencies": true}]

[no-extraneous-dependencies]添加异常? #422

根据此用户的回复

您可以在测试文件夹中的.eslintrc中设置选项devDependencies:true:

规则:import / no-extraneous-dependencies:[error,{devDependencies:true}]然后,您将获得所引用的任何未包含依赖项或devDependencies的包的报告。 然后你得到了规则的优点,没有来自禁用评论的噪音

我想这可能对你有用吗? 在您的情况下,这就是我将使用该规则的方式,因为您将测试代码分隔为测试目录。

这篇文章也有助于确认我不想在我的依赖列表中不想要其中的一些Sharable ESLint Config

如果要允许在测试文件中导入devDependencies ,则只能使用array of globs ,因为no-extraneous-dependencies文档指出:

使用globs数组时,如果要绘制的文件的名称与数组中的单个glob匹配,则设置将设置为true(未报告错误),否则为false。

以下设置将仅禁用测试文件的lint。

"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.ts", "**/*.test.tsx"]}]

这样,从devDependencies导入仍然会报告为错误。

我能够通过将缺少的包(在我的情况下,Typescript 和 Storybook)添加到.eslintrc plugins目录来解决它。

我在这篇文章中给出了细节: ESLint error: '@storybook/react' 应该列在项目的依赖项中,而不是 devDependencies

我通过使用修复它

 'import/no-extraneous-dependencies': [
      'error',
      {
        projectDependencies: false,
      },
    ],

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM