Sha256: d592d0f226362b05eaf4f36a826ad63ea31863e79b881dc1b118e08dcc3959f5

Contents?: true

Size: 1.43 KB

Versions: 43

Compression:

Stored size: 1.43 KB

Contents

/**
 * @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. Defaults to `lib/rules`.
 * @param {string} cwd Current working directory
 * @returns {Object} Loaded rule modules by rule ids (file names).
 */
module.exports = function(relativeRulesDir, cwd) {

    const rulesDir = relativeRulesDir
        ? path.resolve(cwd, relativeRulesDir)
        : path.join(__dirname, "rules");

    // 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)] = path.join(rulesDir, file);
    });
    rulesDirCache[rulesDir] = rules;

    return rules;
};

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
govuk_publishing_components-17.6.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-17.5.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-17.4.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-17.3.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-17.2.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-17.1.1 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-17.1.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-17.0.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-16.29.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-16.28.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-16.27.1 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-16.27.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-16.26.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-16.25.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-16.24.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-16.23.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-16.22.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-16.21.0 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-16.20.1 node_modules/standard/node_modules/eslint/lib/load-rules.js
govuk_publishing_components-16.20.0 node_modules/standard/node_modules/eslint/lib/load-rules.js