Update eslint-plugin-rulesdir to 0.2.0
DISABLE_THIRD_PARTY_CHECK=node_modules update
Bug: none
Change-Id: I0314c61235e97459facf879aec4bc8b9e1029099
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2753149
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
Auto-Submit: Jack Franklin <jacktfranklin@chromium.org>
diff --git a/node_modules/eslint-plugin-rulesdir/.eslintrc.js b/node_modules/eslint-plugin-rulesdir/.eslintrc-multiple-rulesdir.js
similarity index 83%
copy from node_modules/eslint-plugin-rulesdir/.eslintrc.js
copy to node_modules/eslint-plugin-rulesdir/.eslintrc-multiple-rulesdir.js
index b70f5cb..f92ef31 100644
--- a/node_modules/eslint-plugin-rulesdir/.eslintrc.js
+++ b/node_modules/eslint-plugin-rulesdir/.eslintrc-multiple-rulesdir.js
@@ -13,7 +13,7 @@
fs.symlinkSync(__dirname, SYMLINK_LOCATION);
}
-require('.').RULES_DIR = path.resolve('tests');
+require('.').RULES_DIR = [path.resolve('fake-rule-dir-one'), path.resolve('fake-rule-dir-two')];
module.exports = {
extends: 'airbnb-base',
@@ -24,6 +24,7 @@
'global-require': 'off',
'import/no-dynamic-require': 'off',
'rulesdir/fake-rule': 'error',
+ 'rulesdir/another-fake-rule': 'error',
},
plugins: [PACKAGE_NAME],
};
diff --git a/node_modules/eslint-plugin-rulesdir/.eslintrc.js b/node_modules/eslint-plugin-rulesdir/.eslintrc-single-rulesdir.js
similarity index 91%
rename from node_modules/eslint-plugin-rulesdir/.eslintrc.js
rename to node_modules/eslint-plugin-rulesdir/.eslintrc-single-rulesdir.js
index b70f5cb..3373a5b 100644
--- a/node_modules/eslint-plugin-rulesdir/.eslintrc.js
+++ b/node_modules/eslint-plugin-rulesdir/.eslintrc-single-rulesdir.js
@@ -13,7 +13,7 @@
fs.symlinkSync(__dirname, SYMLINK_LOCATION);
}
-require('.').RULES_DIR = path.resolve('tests');
+require('.').RULES_DIR = path.resolve('fake-rule-dir-one');
module.exports = {
extends: 'airbnb-base',
diff --git a/node_modules/eslint-plugin-rulesdir/.npmignore b/node_modules/eslint-plugin-rulesdir/.npmignore
deleted file mode 100644
index c2658d7..0000000
--- a/node_modules/eslint-plugin-rulesdir/.npmignore
+++ /dev/null
@@ -1 +0,0 @@
-node_modules/
diff --git a/node_modules/eslint-plugin-rulesdir/README.md b/node_modules/eslint-plugin-rulesdir/README.md
index 5a94c8c..470526b 100644
--- a/node_modules/eslint-plugin-rulesdir/README.md
+++ b/node_modules/eslint-plugin-rulesdir/README.md
@@ -22,12 +22,15 @@
## Usage
-To use this plugin, you must load it manually first and set its `RULES_DIR` property to a path. The path is resolved from the current working directory, and indicates where you would like the plugin to load your rules from. This is easiest if you use a JavaScript config file (`.eslintrc.js`), and use a local installation of ESLint.
+To use this plugin, you must load it manually first and set its `RULES_DIR` property to a path, or an array of paths. The paths are resolved from the current working directory, and indicates where you would like the plugin to load your rules from. This is easiest if you use a JavaScript config file (`.eslintrc.js`), and use a local installation of ESLint.
```js
// .eslintrc.js
const rulesDirPlugin = require('eslint-plugin-rulesdir');
rulesDirPlugin.RULES_DIR = 'tools/eslint-rules'; // (an example folder where your rules might be stored)
+
+// You can also provide an array if you have multiple folders with rules in:
+rulesDirPlugin.RULES_DIR = ['tools/eslint-rules', 'tools/other-eslint-rules'];
```
Then you should add `rulesdir` to the plugins section of your `.eslintrc.js` file.
diff --git a/node_modules/eslint-plugin-rulesdir/tests/fake-rule.js b/node_modules/eslint-plugin-rulesdir/fake-rule-dir-one/fake-rule.js
similarity index 100%
rename from node_modules/eslint-plugin-rulesdir/tests/fake-rule.js
rename to node_modules/eslint-plugin-rulesdir/fake-rule-dir-one/fake-rule.js
diff --git a/node_modules/eslint-plugin-rulesdir/tests/fake-rule.js b/node_modules/eslint-plugin-rulesdir/fake-rule-dir-two/another-fake-rule.js
similarity index 100%
copy from node_modules/eslint-plugin-rulesdir/tests/fake-rule.js
copy to node_modules/eslint-plugin-rulesdir/fake-rule-dir-two/another-fake-rule.js
diff --git a/node_modules/eslint-plugin-rulesdir/index.js b/node_modules/eslint-plugin-rulesdir/index.js
index 7ad98c9..5dbdc0d 100644
--- a/node_modules/eslint-plugin-rulesdir/index.js
+++ b/node_modules/eslint-plugin-rulesdir/index.js
@@ -20,15 +20,27 @@
module.exports = {
get rules() {
const RULES_DIR = module.exports.RULES_DIR;
- if (typeof module.exports.RULES_DIR !== 'string') {
- throw new Error('To use eslint-plugin-rulesdir, you must load it beforehand and set the `RULES_DIR` property on the module to a string.');
+ if (typeof module.exports.RULES_DIR !== 'string' && !Array.isArray(RULES_DIR)) {
+ throw new Error('To use eslint-plugin-rulesdir, you must load it beforehand and set the `RULES_DIR` property on the module to a string or an array of strings.');
}
- if (!cache[RULES_DIR]) {
- cache[RULES_DIR] = fs.readdirSync(RULES_DIR)
- .filter(filename => filename.endsWith('.js'))
- .map(filename => path.resolve(RULES_DIR, filename))
- .reduce((rules, absolutePath) => Object.assign(rules, { [path.basename(absolutePath, '.js')]: require(absolutePath) }), {});
+ const cacheKey = JSON.stringify(RULES_DIR);
+ if (!cache[cacheKey]) {
+ const rules = Array.isArray(RULES_DIR) ? RULES_DIR : [RULES_DIR];
+ const rulesObject = {};
+ rules.forEach((rulesDir) => {
+ fs.readdirSync(rulesDir)
+ .filter(filename => filename.endsWith('.js'))
+ .map(filename => path.resolve(rulesDir, filename))
+ .forEach((absolutePath) => {
+ const ruleName = path.basename(absolutePath, '.js');
+ if (rulesObject[ruleName]) {
+ throw new Error(`eslint-plugin-rulesdir found two rules with the same name: ${ruleName}`);
+ }
+ rulesObject[ruleName] = require(absolutePath);
+ });
+ });
+ cache[cacheKey] = rulesObject;
}
- return cache[RULES_DIR];
+ return cache[cacheKey];
},
};
diff --git a/node_modules/eslint-plugin-rulesdir/package.json b/node_modules/eslint-plugin-rulesdir/package.json
index a545e17..38205a4 100644
--- a/node_modules/eslint-plugin-rulesdir/package.json
+++ b/node_modules/eslint-plugin-rulesdir/package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-rulesdir",
- "version": "0.1.0",
+ "version": "0.2.0",
"description": "Allows a local ESLint rules directory to be used without a command-line flag",
"license": "MIT",
"keywords": [
@@ -10,8 +10,9 @@
],
"author": "Teddy Katz",
"scripts": {
- "test": "npm run lint",
- "lint": "eslint .eslintrc.js *.js **/*.js"
+ "test": "npm run lint-single-rulesdir && npm run lint-multiple-rulesdir",
+ "lint-single-rulesdir": "eslint --config .eslintrc-single-rulesdir.js *.js **/*.js",
+ "lint-multiple-rulesdir": "eslint --config .eslintrc-multiple-rulesdir.js *.js **/*.js"
},
"devDependencies": {
"eslint": ">=3",