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] Add exceptions? #422
根据该用户的回复:
you could set the option devDependencies: true in an .eslintrc in your
test folder:
rules: import/no-extraneous-dependencies: [error, { devDependencies:
true }] Then you'll get reports of any packages referenced that are
not included dependencies or 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.
此外,这个 post 有助于确认我不想在我的依赖项列表中加入其中的一些内容:Sharable ESLint Config
如果您只想在 测试文件中允许导入 devDependencies
,您可以使用 array of globs
作为 documentation 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.
以下设置将仅对测试文件禁用 lint。
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.ts", "**/*.test.tsx"]}]
这样,从 devDependencies
导入的内容仍会报告为错误。
我可以通过将缺少的包(在我的例子中是 Typescript 和 Storybook)添加到我 .eslintrc
中的 plugins
目录来解决它。
我在这个post中给出具体细节:ESLint error: '@storybook/react' 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] Add exceptions? #422
根据该用户的回复:
you could set the option devDependencies: true in an .eslintrc in your test folder:
rules: import/no-extraneous-dependencies: [error, { devDependencies: true }] Then you'll get reports of any packages referenced that are not included dependencies or 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.
此外,这个 post 有助于确认我不想在我的依赖项列表中加入其中的一些内容:Sharable ESLint Config
如果您只想在 测试文件中允许导入 devDependencies
,您可以使用 array of globs
作为 documentation 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.
以下设置将仅对测试文件禁用 lint。
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.ts", "**/*.test.tsx"]}]
这样,从 devDependencies
导入的内容仍会报告为错误。
我可以通过将缺少的包(在我的例子中是 Typescript 和 Storybook)添加到我 .eslintrc
中的 plugins
目录来解决它。
我在这个post中给出具体细节:ESLint error: '@storybook/react' should be listed in the project's dependencies, not devDependencies