Skip to content

Commit

Permalink
Chore: ignore deprecated rules in fuzz tests (#11710)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane authored and not-an-aardvark committed May 16, 2019
1 parent af81cb3 commit 67c671f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/config/config-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,17 @@ function generateConfigsFromSchema(schema) {

/**
* Generate possible rule configurations for all of the core rules
* @param {boolean} noDeprecated Indicates whether ignores deprecated rules or not.
* @returns {rulesConfig} Hash of rule names and arrays of possible configurations
*/
function createCoreRuleConfigs() {
function createCoreRuleConfigs(noDeprecated = false) {
return Array.from(builtInRules).reduce((accumulator, [id, rule]) => {
const schema = (typeof rule === "function") ? rule.schema : rule.meta.schema;
const isDeprecated = (typeof rule === "function") ? rule.deprecated : rule.meta.deprecated;

if (noDeprecated && isDeprecated) {
return accumulator;
}

accumulator[id] = generateConfigsFromSchema(schema);
return accumulator;
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/config/config-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,22 @@ describe("ConfigRule", () => {
assert.sameMembers(actualRules, expectedRules);
});

it("should allow to ignore deprecated rules", () => {
const expectedRules = Array.from(builtInRules.entries())
.filter(([, rule]) => {
const isDeprecated = (typeof rule === "function") ? rule.deprecated : rule.meta.deprecated;

return !isDeprecated;
})
.map(([id]) => id),
actualRules = Object.keys(ConfigRule.createCoreRuleConfigs(true));

assert.sameMembers(actualRules, expectedRules);

// Make sure it doesn't contain deprecated rules.
assert.notInclude(actualRules, "newline-after-var");
});

it("should create arrays of configs for rules", () => {
assert.isArray(rulesConfig.quotes);
assert.include(rulesConfig.quotes, 2);
Expand Down
2 changes: 1 addition & 1 deletion tools/eslint-fuzzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const lodash = require("lodash");
const eslump = require("eslump");
const espree = require("espree");
const SourceCodeFixer = require("../lib/util/source-code-fixer");
const ruleConfigs = require("../lib/config/config-rule").createCoreRuleConfigs();
const ruleConfigs = require("../lib/config/config-rule").createCoreRuleConfigs(true);
const sampleMinimizer = require("./code-sample-minimizer");

//------------------------------------------------------------------------------
Expand Down

0 comments on commit 67c671f

Please sign in to comment.