[英]eslint don't deal with multiple package.json
My project have two package.json 我的项目有两个package.json
root folder
└ app ---- /public
└ /styles
└ /src
└ package.json
└ eslintrc.json
└ webpack.config.js
└ server - /something
└ /something
└ package.json
└ ...etc
atom editor shows lint error 原子编辑器显示lint错误
import React from 'react';
// 'react' should be listed in the project's dependencies. Run 'npm i -S react' to add it (import/no-extraneous-dependencies)
In package.json 在package.json中
"dependencies": {
"@types/chart.js": "^2.6.8",
"@types/react": "^16.0.10",
"@types/react-dom": "^16.0.1",
"bootstrap": "^4.0.0-beta",
"chart.js": "2.6.0",
"font-awesome": "^4.7.0",
"history": "4.7.2",
"jwt-decode": "^2.2.0",
"prop-types": "^15.6.0",
"react": "^15.6.1",
"react-chartjs-2": "2.6.1",
"react-dom": "^15.6.1",
"react-router-dom": "4.2.2",
"react-transition-group": "^1.2.0",
"reactstrap": "^4.8.0",
"simple-line-icons": "^2.4.1"
},
and in eslintrc.json 在eslintrc.json
module.exports = {
"extends": "airbnb",
"env": {
"browser": true,
"node": true
},
"rules": {
"no-mixed-operators": [2, { "allowSamePrecedence": true }],
"react/no-find-dom-node": 1,
"react/no-string-refs": 1,
"react/no-unused-prop-types": 1, // TODO: enable
"jsx-a11y/no-static-element-interactions": 1, // TODO: enable
"no-plusplus": 1, // TODO: enable
"no-console": 0, // TODO: enable
"no-alert": 0,
"max-len": ["error", 120],
"no-underscore-dangle": ["error", { "allow": ["_isMounted"] }],
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
},
};
I think that eslint recognize package.json in root folder as standard. 我认为eslint将root文件夹中的package.json识别为标准。 But I want that it ignores package.json in root folder and recognize package.json in src folder.
但我希望它忽略root文件夹中的package.json并识别src文件夹中的package.json。
How can I do? 我能怎么做?
This may be unrelated, but the first item I'd note is that you might need to rename your ESLint configuration from eslintrc.json
to .eslintrc.json
(with a dot before the name). 这可能是不相关的,但我要注意的第一项是您可能需要将ESLint配置从
eslintrc.json
重命名为.eslintrc.json
(名称前面有一个点)。 May not be the source of the trouble, but could possibly be interfering with the hierarchical resolution. 可能不是问题的根源,但可能会干扰分层解决方案。 You can look into the multiple configuration extension formats here: https://eslint.org/docs/user-guide/configuring#configuration-file-formats .
您可以在此处查看多种配置扩展格式: https : //eslint.org/docs/user-guide/configuring#configuration-file-formats 。
Regarding the import/no-extraneous-dependencies
rule specifically, I think the configuration option you might be looking for is packageDir
. 关于
import/no-extraneous-dependencies
规则,我认为您可能正在寻找的配置选项是packageDir
。 Quoting the docs in their repo: 在他们的回购中引用文档:
Also there is one more option called
packageDir
, this option is to specify the path to the folder containingpackage.json
and is relative to the current working directory.还有一个名为
packageDir
选项,该选项用于指定包含package.json
的文件夹的路径,并且相对于当前工作目录。
"import/no-extraneous-dependencies": ["error", {"packageDir": './some-dir/'}]
Hope this helps! 希望这可以帮助!
Source: 资源:
https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
I solved this problem myself. 我自己解决了这个问题。
Added "packageDir": "./src" in .eslintrc.json 在.eslintrc.json中添加了“packageDir”:“。/ src”
"rules" : {
""import/no-extraneous-dependencies": ["error", {"devDependencies": true, "packageDir": "./src"}],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.