[英]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.