Skip to content

Commit

Permalink
Fix: export all rules when using eslint v5
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Jun 8, 2019
1 parent 9d3799f commit 9616040
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions lib/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

const fs = require("fs");
const path = require("path");
const builtin = require("eslint/lib/rules/index");
const eslintVersion = require("eslint/package.json").version;


/**
* Loads a given rule from the filesystem and generates its documentation URL
Expand All @@ -29,10 +30,25 @@ function loadRule(ruleName) {

const allRules = {};

for (const [ruleId, rule] of builtin) {
if (rule.meta.fixable) {
allRules[ruleId] = rule;
// eslint v6 restructed its codebase
// TODO: this might be unreliable
if (eslintVersion >= "6.0.0") {
const builtin = require("eslint/lib/rules");

for (const [ruleId, rule] of builtin) {
if (rule.meta.fixable) {
allRules[ruleId] = rule;
}
}
} else {
const builtin = require("eslint/lib/built-in-rules-index");

Object.keys(builtin)
.filter(rule => builtin[rule].meta.fixable)
.reduce((acc, cur) => {
acc[cur] = builtin[cur];
return acc;
}, allRules);
}

// import all rules in lib/rules
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"devDependencies": {
"@not-an-aardvark/node-release-script": "^0.1.0",
"@types/eslint": "^4.16.6",
"eslint": "https://github.com/eslint/eslint.git",
"eslint": "^5.16.0",
"eslint-config-eslint": "^5.0.1",
"eslint-plugin-eslint-plugin": "^2.0.1",
"eslint-plugin-node": "^9.1.0",
Expand Down

0 comments on commit 9616040

Please sign in to comment.