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/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];
},
};