[英]eslint – how to know where a rule is “defined”
Given a project with its node's package.json
installing eslint and a few plugins, how can I know where a particular rule is set?给定一个项目,其节点的
package.json
安装了 eslint 和一些插件,我怎么知道在哪里设置了特定的规则?
I see a rule being applied ( space-before-function-paren
) but I cannot find it either in any of the .eslintrc
files in the project, or in the documentation of the plugins.我看到应用了一条规则(
space-before-function-paren
),但在项目的任何.eslintrc
文件或插件文档中都找不到它。
Additionally, I'm working with VSCode with some extensions such as ESLint itself, which could potentially be interfering here, but again I'm not sure how/where to check which part is applying that rule (though I think this is unlikely to be happening, as npm run lint
fails if the code fails against the mentioned rule.此外,我正在使用带有一些扩展的 VSCode,例如 ESLint 本身,这可能会在这里干扰,但我再次不确定如何/在哪里检查哪个部分正在应用该规则(尽管我认为这不太可能是发生,因为
npm run lint
如果代码违反上述规则失败。
I'm posting the relevant parts of the package.json file:我正在发布 package.json 文件的相关部分:
{
// ...
"scripts": {
"watch": "NODE_ENV=development node build/build.js --watch",
"build": "NODE_ENV=development node build/build.js",
"build:prod": "NODE_ENV=production node build/build.js",
"unit": "NODE_ENV=test jest --config test/unit/jest.conf.js --coverage",
"test": "npm run unit",
"lint": "eslint --ext .js,.vue src test/unit/specs",
"ci-lint": "eslint --ext .js,.vue src test/unit/specs --format checkstyle --output-file lint_out/unit_timeline.xml"
},
"devDependencies": {
"@vue/test-utils": "^1.0.0-beta.27",
"autoprefixer": "^8.2.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.2",
"babel-jest": "^22.4.3",
"babel-loader": "^7.1.4",
"babel-plugin-dynamic-import-node": "^2.2.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-2": "^6.24.1",
"chalk": "^2.3.2",
"copy-webpack-plugin": "^4.5.1",
"css-loader": "^0.28.11",
"cssnano": "^3.10.0",
"eslint": "^5.10.0",
"eslint-config-standard": "^12.0.0",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^2.1.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^5.0.0",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.11",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^3.1.0",
"jest": "^22.4.3",
"jest-junit": "^3.6.0",
"jest-serializer-vue": "^1.0.0",
"node-notifier": "^5.2.1",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^2.0.0",
"portfinder": "^1.0.13",
"postcss-import": "^11.1.0",
"postcss-loader": "^2.1.3",
"postcss-url": "^7.3.1",
"rimraf": "^2.6.2",
"sass-loader": "^6.0.7",
"semver": "^5.5.0",
"shelljs": "^0.8.1",
"uglifyjs-webpack-plugin": "^1.2.4",
"url-loader": "^1.0.1",
"vue-jest": "^2.3.0",
"vue-loader": "^14.2.2",
"vue-style-loader": "^4.1.0",
"vue-template-compiler": "^2.5.21",
"webpack": "^3.11.0",
"webpack-bundle-analyzer": "^2.11.1",
"webpack-file-list-plugin": "0.0.6",
"webpack-merge": "^4.1.2",
"yargs": "^11.0.0"
}
// ...
}
Unfortunately, it seems there's no "eslint" way to perform such a report.不幸的是,似乎没有“eslint”方式来执行这样的报告。
If you run eslint
with debug options, you get a lot of information about how the program runs: what file is processing, with which configuration, how it fails, etc., but not from where a rule was taken.如果你使用调试选项运行
eslint
,你会得到很多关于程序如何运行的信息:正在处理什么文件、使用哪种配置、它如何失败等等,但不是从哪里获取规则的。
I managed to find it by simply running a grep + find
within the node_modules
directory, and being sure which module was providing the rule by simply changing it and seeing the eslint
results afterwards.我设法通过简单地在
node_modules
目录中运行grep + find
来找到它,并通过简单地更改它并随后查看eslint
结果来确定哪个模块提供了规则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.