最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - eslint – how to know where a rule is "defined" - Stack Overflow

programmeradmin1浏览0评论

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?

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.

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.

I'm posting the relevant parts of the package.json file:

{
  // ...
  "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-monjs": "^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-piler": "^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"
  }
  // ...
}

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?

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.

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.

I'm posting the relevant parts of the package.json file:

{
  // ...
  "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-monjs": "^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-piler": "^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"
  }
  // ...
}
Share Improve this question asked Sep 14, 2020 at 17:16 PipetusPipetus 1,1361 gold badge13 silver badges30 bronze badges 2
  • Are you sure you're not extending a configuration that has that rule? – VLAZ Commented Sep 14, 2020 at 17:20
  • Do you refer to any .eslintrc file that could reside in the project? – Pipetus Commented Sep 14, 2020 at 18:45
Add a ment  | 

1 Answer 1

Reset to default 4

Unfortunately, it seems there's no "eslint" way to perform such a report.

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.

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.

发布评论

评论列表(0)

  1. 暂无评论