mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-28 13:13:37 +08:00
This is need to be able to move to flat config which I am handling in a separate CL. The overrides are there as these packages got update today, so we need to way, but they were last touched 3 years ago, so reviewing their changes upstream as well. Bug: none Change-Id: I61534f881fd4e747c716b42b773f8f7f3e9bc761 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6063618 Commit-Queue: Nikolay Vitkov <nvitkov@chromium.org> Reviewed-by: Danil Somsikov <dsv@chromium.org>
50 lines
1.8 KiB
JavaScript
50 lines
1.8 KiB
JavaScript
/**
|
|
* @fileoverview Allows a local ESLint rules directory to be used without a command-line flag
|
|
* @author Teddy Katz
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Requirements
|
|
//------------------------------------------------------------------------------
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Plugin Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
const cache = {};
|
|
|
|
const ruleExtensions = new Set(['.js', '.cjs', '.mjs', '.ts', '.cts', '.mts']);
|
|
|
|
module.exports = {
|
|
get rules() {
|
|
const RULES_DIR = module.exports.RULES_DIR;
|
|
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.');
|
|
}
|
|
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 => ruleExtensions.has(path.extname(filename)))
|
|
.map(filename => path.resolve(rulesDir, filename))
|
|
.forEach((absolutePath) => {
|
|
const ruleName = path.basename(absolutePath, path.extname(absolutePath));
|
|
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[cacheKey];
|
|
},
|
|
};
|