Skip to content

Commit

Permalink
feat: add rule tester deprecation warnings for function-style rules a…
Browse files Browse the repository at this point in the history
…nd rules missing schemas
  • Loading branch information
bmish committed Apr 5, 2022
1 parent 27be985 commit cc83a0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/rule-tester/flat-rule-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ class FlatRuleTester {
].concat(scenarioErrors).join("\n"));
}

if (typeof rule === "function") {
console.warn("DEPRECATION WARNING: This rule is using the deprecated function-style format and will stop working in ESLint v9. Please convert to object-style rules: https://eslint.org/docs/developer-guide/working-with-rules This lint rule can assist with the conversion: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/main/docs/rules/prefer-object-rule.md")
}

const baseConfig = {
plugins: {

Expand Down Expand Up @@ -596,6 +600,9 @@ class FlatRuleTester {

if (hasOwnProperty(item, "options")) {
assert(Array.isArray(item.options), "options must be an array");
if (!rule.schema) {
console.warn("DEPRECATION WARNING: This test case specifies `options` but the rule is missing `meta.schema` and will stop working in ESLint v9. Please add `meta.schema`: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas This lint rule can assist with the conversion: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/main/docs/rules/require-meta-schema.md");
}
ruleConfig = [1, ...item.options];
}

Expand Down
6 changes: 6 additions & 0 deletions lib/rule-tester/rule-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ class RuleTester {
].concat(scenarioErrors).join("\n"));
}

if (typeof rule === "function") {
console.warn("DEPRECATION WARNING: This rule is using the deprecated function-style format and will stop working in ESLint v9. Please convert to object-style rules: https://eslint.org/docs/developer-guide/working-with-rules This lint rule can assist with the conversion: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/main/docs/rules/prefer-object-rule.md")
}

linter.defineRule(ruleName, Object.assign({}, rule, {

Expand Down Expand Up @@ -578,6 +581,9 @@ class RuleTester {

if (hasOwnProperty(item, "options")) {
assert(Array.isArray(item.options), "options must be an array");
if (!rule.schema) {
console.warn("DEPRECATION WARNING: This test case specifies `options` but the rule is missing `meta.schema` and will stop working in ESLint v9. Please add `meta.schema`: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas This lint rule can assist with the conversion: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/main/docs/rules/require-meta-schema.md");
}
config.rules[ruleName] = [1].concat(item.options);
} else {
config.rules[ruleName] = 1;
Expand Down

0 comments on commit cc83a0c

Please sign in to comment.