Permalink
Browse files

Chore: remove dead code for loading rules (#11334)

The `lib/rules.js` file contains a code path that was previously needed to load core rules, but is no longer used as of aa56247.
  • Loading branch information...
not-an-aardvark committed Jan 30, 2019
1 parent c464e27 commit 36e335681d61cbe3c83b653b7cc5f95730f1d86e
Showing with 9 additions and 16 deletions.
  1. +3 −5 conf/eslint-all.js
  2. +2 −4 lib/config/config-rule.js
  3. +2 −5 lib/load-rules.js
  4. +2 −2 tests/lib/config/config-rule.js
@@ -9,16 +9,14 @@
// Requirements
//------------------------------------------------------------------------------

const load = require("../lib/load-rules"),
Rules = require("../lib/rules");
const rules = new Rules();
const builtInRules = require("../lib/built-in-rules-index");

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

const enabledRules = Object.keys(load()).reduce((result, ruleId) => {
if (!rules.get(ruleId).meta.deprecated) {
const enabledRules = Object.keys(builtInRules).reduce((result, ruleId) => {
if (!builtInRules[ruleId].meta.deprecated) {
result[ruleId] = "error";
}
return result;
@@ -10,7 +10,7 @@
//------------------------------------------------------------------------------

const Rules = require("../rules"),
loadRules = require("../load-rules");
builtInRules = require("../built-in-rules-index");

const rules = new Rules();

@@ -299,9 +299,7 @@ function generateConfigsFromSchema(schema) {
* @returns {rulesConfig} Hash of rule names and arrays of possible configurations
*/
function createCoreRuleConfigs() {
const ruleList = loadRules();

return Object.keys(ruleList).reduce((accumulator, id) => {
return Object.keys(builtInRules).reduce((accumulator, id) => {
const rule = rules.get(id);
const schema = (typeof rule === "function") ? rule.schema : rule.meta.schema;

@@ -20,15 +20,12 @@ const rulesDirCache = {};

/**
* Load all rule modules from specified directory.
* @param {string} [relativeRulesDir] Path to rules directory, may be relative. Defaults to `lib/rules`.
* @param {string} relativeRulesDir Path to rules directory, may be relative.
* @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");
const rulesDir = path.resolve(cwd, relativeRulesDir);

// cache will help performance as IO operation are expensive
if (rulesDirCache[rulesDir]) {
@@ -11,7 +11,7 @@

const assert = require("chai").assert,
ConfigRule = require("../../../lib/config/config-rule"),
loadRules = require("../../../lib/load-rules"),
builtInRules = require("../../../lib/built-in-rules-index"),
schema = require("../../fixtures/config-rule/schemas");

//------------------------------------------------------------------------------
@@ -294,7 +294,7 @@ describe("ConfigRule", () => {
const rulesConfig = ConfigRule.createCoreRuleConfigs();

it("should create a rulesConfig containing all core rules", () => {
const coreRules = loadRules(),
const coreRules = builtInRules,
expectedRules = Object.keys(coreRules),
actualRules = Object.keys(rulesConfig);

0 comments on commit 36e3356

Please sign in to comment.