source: imaps-frontend/node_modules/eslint/lib/cli-engine/load-rules.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[d565449]1/**
2 * @fileoverview Module for loading rules from files and directories.
3 * @author Michael Ficarra
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Requirements
10//------------------------------------------------------------------------------
11
12const fs = require("fs"),
13 path = require("path");
14
15const rulesDirCache = {};
16
17//------------------------------------------------------------------------------
18// Public Interface
19//------------------------------------------------------------------------------
20
21/**
22 * Load all rule modules from specified directory.
23 * @param {string} relativeRulesDir Path to rules directory, may be relative.
24 * @param {string} cwd Current working directory
25 * @returns {Object} Loaded rule modules.
26 */
27module.exports = function(relativeRulesDir, cwd) {
28 const rulesDir = path.resolve(cwd, relativeRulesDir);
29
30 // cache will help performance as IO operation are expensive
31 if (rulesDirCache[rulesDir]) {
32 return rulesDirCache[rulesDir];
33 }
34
35 const rules = Object.create(null);
36
37 fs.readdirSync(rulesDir).forEach(file => {
38 if (path.extname(file) !== ".js") {
39 return;
40 }
41 rules[file.slice(0, -3)] = require(path.join(rulesDir, file));
42 });
43 rulesDirCache[rulesDir] = rules;
44
45 return rules;
46};
Note: See TracBrowser for help on using the repository browser.