简体   繁体   English

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

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

Either I don't understand dependencies vs. devDependencies in node 100% yet or eslint is just wrong here (not capable of analyzing this correctly):要么我不理解节点 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

These are test dependencies, so why is it saying that they should be listed in dependencies ?这些是测试依赖项,为什么说它们应该列在dependencies中?

Additional note: We're using Travis as our CI so I don't know if it makes a difference for that at all either.附加说明:我们使用 Travis 作为我们的 CI,所以我也不知道这是否会有所作为。

Solved it with adding this to my .eslintrc : 将此添加到我的.eslintrc解决了它:

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

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

Based on this user's reply : 根据此用户的回复

you could set the option devDependencies: true in an .eslintrc in your test folder: 您可以在测试文件夹中的.eslintrc中设置选项devDependencies:true:

rules: import/no-extraneous-dependencies: [error, { devDependencies: true }] Then you'll get reports of any packages referenced that are not included dependencies or devDependencies. 规则:import / no-extraneous-dependencies:[error,{devDependencies:true}]然后,您将获得所引用的任何未包含依赖项或devDependencies的包的报告。 Then you get the goodness of the rule, with no noise from the disable comments . 然后你得到了规则的优点,没有来自禁用评论的噪音

I think that might work for you? 我想这可能对你有用吗? This is how I would use the rule, in your case, since you have your test code separated into a test directory. 在您的情况下,这就是我将使用该规则的方式,因为您将测试代码分隔为测试目录。

Also this post was helpful to confirm I wasn't insane to not want some of these in my dependencies list : Sharable ESLint Config 这篇文章也有助于确认我不想在我的依赖列表中不想要其中的一些Sharable ESLint Config

If you want to allow imports of devDependencies in test files only you can use an array of globs , as the documentation of no-extraneous-dependencies states: 如果要允许在测试文件中导入devDependencies ,则只能使用array of globs ,因为no-extraneous-dependencies文档指出:

When using an array of globs, the setting will be set to true (no errors reported) if the name of the file being linted matches a single glob in the array, and false otherwise. 使用globs数组时,如果要绘制的文件的名称与数组中的单个glob匹配,则设置将设置为true(未报告错误),否则为false。

The following setting will disable the lint for test files only. 以下设置将仅禁用测试文件的lint。

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

That way imports from devDependencies are still reported as errors. 这样,从devDependencies导入仍然会报告为错误。

I was able to solve it by adding the missing packages (in my case, Typescript and Storybook) to my plugins directory in .eslintrc .我能够通过将缺少的包(在我的情况下,Typescript 和 Storybook)添加到.eslintrc plugins目录来解决它。

I give the specifics in this post: ESLint error: '@storybook/react' should be listed in the project's dependencies, not devDependencies我在这篇文章中给出了细节: ESLint error: '@storybook/react' 应该列在项目的依赖项中,而不是 devDependencies

I fixed it by using我通过使用修复它

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

暂无
暂无

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

相关问题 eslint 'html-webpack-plugin' 应该列在项目的依赖中,而不是 devDependencies 中。 (导入/无外部依赖项) - eslint 'html-webpack-plugin' should be listed in the project's dependencies, not devDependencies. (import/no-extraneous-dependencies) 'prop-types' 应该列在项目的依赖项中,而不是 devDependencies - 'prop-types' should be listed in the project's dependencies, not devDependencies 无法将我的商店文件导入App.js错误:“商店”应列在项目的依赖项中 - Cannot import my store file into App.js error: 'store' should be listed in the project's dependencies 是否应该将 refs 列为 useEffect 等的依赖项? - Should refs be in listed as dependencies for useEffect and such? 将 devDependencies 和依赖项与 yarn 一起安装 - Install devDependencies and dependencies together with yarn 你把Babel和Webpack放在devDependencies或Dependencies中吗? - Do you put Babel and Webpack in devDependencies or Dependencies? 在Mocha测试中绕过ESLint的`no-unused-var` for Should - Bypass ESLint's `no-unused-var` for Should in a Mocha test 全局 ESLint 覆盖项目 ESLint - Global ESLint overrides project ESLint 如果Node devDependencies嵌套在依赖关系中,它们是否包含在版本中? - Are Node devDependencies included as part of a release if they are nested within dependencies? NPM:我应该使用依赖项之一的依赖项,还是应该在根级别将其明确安装到项目中? - NPM: should I use one of my dependencies' dependencies, or should I explicitly install it into the project at the root level?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM