Skip to content

Commit

Permalink
fix: use unique deprecation code for rules
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jun 29, 2022
1 parent 279d14b commit 6905616
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
17 changes: 8 additions & 9 deletions lib/rule-tester/rule-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,7 @@ class RuleTester {
util.deprecate(
() => {},
`"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules`,
"DEP_ESLINT_LEGACY_RULE_API"
)();
}

if (typeof rule === "object" && rule.meta && typeof rule.meta.schema === "undefined") {
util.deprecate(
() => {},
`"${ruleName}" rule is using the object-style format but is missing the "meta.schema" property. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas`,
"DEP_ESLINT_MISSING_RULE_SCHEMA"
`DEP_ESLINT_LEGACY_RULE_API_${ruleName.replace(/-/giu, "_").toUpperCase()}`
)();
}

Expand Down Expand Up @@ -593,6 +585,13 @@ class RuleTester {

if (hasOwnProperty(item, "options")) {
assert(Array.isArray(item.options), "options must be an array");
if (item.options.length > 0 && typeof rule === "object" && rule.meta && typeof rule.meta.schema === "undefined") {
util.deprecate(
() => {},
`"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas`,
`DEP_ESLINT_MISSING_SCHEMA_${ruleName.replace(/-/giu, "_").toUpperCase()}`
)();
}
config.rules[ruleName] = [1].concat(item.options);
} else {
config.rules[ruleName] = 1;
Expand Down
14 changes: 7 additions & 7 deletions tests/lib/rule-tester/rule-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -2314,7 +2314,7 @@ describe("RuleTester", () => {

const spy = sinon.spy(util, "deprecate");

ruleTester.run("functionStyleRule", functionStyleRule, {
ruleTester.run("function-style-rule", functionStyleRule, {
valid: [],
invalid: [
{ code: "var foo = bar;", errors: 1 }
Expand All @@ -2324,9 +2324,9 @@ describe("RuleTester", () => {
assert.strictEqual(spy.callCount, 1, "calls `util.deprecate()` once");
assert.strictEqual(
spy.getCall(0).args[1],
"\"functionStyleRule\" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules"
"\"function-style-rule\" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules"
);
assert.strictEqual(spy.getCall(0).args[2], "DEP_ESLINT_LEGACY_RULE_API");
assert.strictEqual(spy.getCall(0).args[2], "DEP_ESLINT_LEGACY_RULE_API_FUNCTION_STYLE_RULE");

spy.restore();
});
Expand All @@ -2347,7 +2347,7 @@ describe("RuleTester", () => {

const spy = sinon.spy(util, "deprecate");

ruleTester.run("ruleWithNoOptions", ruleWithNoSchema, {
ruleTester.run("rule-with-no-options", ruleWithNoSchema, {
valid: [],
invalid: [
{ code: "var foo = bar;", options: [{ foo: true }], errors: 1 }
Expand All @@ -2357,9 +2357,9 @@ describe("RuleTester", () => {
assert.strictEqual(spy.callCount, 1, "calls `console.warn` once");
assert.strictEqual(
spy.getCall(0).args[1],
"\"ruleWithNoOptions\" rule is using the object-style format but is missing the \"meta.schema\" property. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas"
"\"rule-with-no-options\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas"
);
assert.strictEqual(spy.getCall(0).args[2], "DEP_ESLINT_MISSING_RULE_SCHEMA");
assert.strictEqual(spy.getCall(0).args[2], "DEP_ESLINT_MISSING_SCHEMA_RULE_WITH_NO_OPTIONS");

spy.restore();
});
Expand All @@ -2381,7 +2381,7 @@ describe("RuleTester", () => {

const spy = sinon.spy(util, "deprecate");

ruleTester.run("ruleWithNoOptions", ruleWithEmptySchema, {
ruleTester.run("rule-with-no-options", ruleWithEmptySchema, {
valid: [],
invalid: [{ code: "var foo = bar;", errors: 1 }]
});
Expand Down

0 comments on commit 6905616

Please sign in to comment.