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-16.19.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-16.18.0 node_modules/sass-lint/lib/rules.js
govuk_publishing_components-16.17.0 node_modules/sass-lint/lib/rules.js
guard-sass-lint-0.1.2 node_modules/sass-lint/lib/rules.js
guard-sass-lint-0.1.1 node_modules/sass-lint/lib/rules.js