Skip to content

Commit

Permalink
Chore: remove dead code for loading rules (#11334)
Browse files Browse the repository at this point in the history
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 authored Jan 30, 2019
1 parent c464e27 commit 36e3356
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
8 changes: 3 additions & 5 deletions conf/eslint-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions lib/config/config-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//------------------------------------------------------------------------------

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

const rules = new Rules();

Expand Down Expand Up @@ -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;

Expand Down
7 changes: 2 additions & 5 deletions lib/load-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/config/config-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 36e3356

Please sign in to comment.