Sha256: 165841ce982b11bcb7b61c5922bd624608a219fef368e6a2c55252d0b6f3fad1

Contents?: true

Size: 1.42 KB

Versions: 45

Compression:

Stored size: 1.42 KB

Contents

'use strict';

var merge = require('merge'),
    path = require('path'),
    fs = require('fs');

var searchArray = function (haystack, needle) {
  var i;
  for (i = 0; i < haystack.length; i++) {
    if (haystack[i].indexOf(needle) >= 0) {
      return i;
    }
  }
  return -1;
};

module.exports = function (config) {
  var handlers = [],
      i,
      rules;

  rules = fs.readdirSync(path.join(__dirname, 'rules'));
  for (i = 0; i < rules.length; i++) {
    rules[i] = path.join(__dirname, 'rules', rules[i]);
  }

  Object.keys(config.rules).forEach(function (rule) {
    var fullRule = config.rules[rule],
        loadRule,
        severity,
        options,
        ruleSearch;

    if (typeof fullRule === 'number') {
      severity = fullRule;
      options = {};
    }
    else {
      severity = fullRule[0];
      options = fullRule[1];
    }

    // Only seek out rules that are enabled
    if (severity !== 0) {
      var fileName = path.normalize(path.join('/', rule + '.js'));

      ruleSearch = searchArray(rules, fileName);

      if (ruleSearch >= 0) {
        loadRule = require(rules[ruleSearch]);

        options = merge.recursive(true, loadRule.defaults, options);

        handlers.push({
          'rule': loadRule,
          'severity': severity,
          'options': options
        });
      }
      else {
        throw new Error('Rule `' + rule + '` could not be found!');
      }
    }
  });

  return handlers;
};

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.21.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.20.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.19.1 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.19.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.18.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.17.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.16.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.15.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.14.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.13.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.12.2 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.12.1 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.12.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.11.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.10.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.9.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.8.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.7.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-17.6.1 node_modules/sass-lint/lib/rules.js