/
drndsv
/
react
Обзор
Документация
Войти
/
drndsv
/
react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
node_modules/eslint/lib/cli-engine/load-rules.js
46 строк
1 KB
drndsv
Initial commit
14 апр 2025, 22:53
14 апр 2025, 22:53
641ac8a
Код
Авторство
О чём код?
/** * @fileoverview Module for loading rules from files and directories. * @author Michael Ficarra */ "use strict"; //------------------------------------------------------------------------------ // Requirements //------------------------------------------------------------------------------ const fs = require("fs"), path = require("path"); const rulesDirCache = {}; //------------------------------------------------------------------------------ // Public Interface //------------------------------------------------------------------------------ /** * Load all rule modules from specified directory. * @param {string} relativeRulesDir Path to rules directory, may be relative. * @param {string} cwd Current working directory * @returns {Object} Loaded rule modules. */ module.exports = function(relativeRulesDir, cwd) { const rulesDir = path.resolve(cwd, relativeRulesDir); // cache will help performance as IO operation are expensive if (rulesDirCache[rulesDir]) { return rulesDirCache[rulesDir]; } const rules = Object.create(null); fs.readdirSync(rulesDir).forEach(file => { if (path.extname(file) !== ".js") { return; } rules[file.slice(0, -3)] = require(path.join(rulesDir, file)); }); rulesDirCache[rulesDir] = rules; return rules; };