Skip to content

Commit

Permalink
fix: update RuleTester JSDoc and deprecations (#17496)
Browse files Browse the repository at this point in the history
* RuleTester: Allow new-style rule definitions

* RuleTester: Add check for legacy rule API usage warning for defineRule()

* RuleTester: Move typedef import to correct location

* FlatRuleTester: Allow new-style rule definitions

* FlatRuleTester: Fix copypaste bug
  • Loading branch information
xkr47 committed Aug 25, 2023
1 parent 1fbb3b0 commit 7234f6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/rule-tester/flat-rule-tester.js
Expand Up @@ -32,6 +32,7 @@ const { ConfigArraySymbol } = require("@humanwhocodes/config-array");

/** @typedef {import("../shared/types").Parser} Parser */
/** @typedef {import("../shared/types").LanguageOptions} LanguageOptions */
/** @typedef {import("../shared/types").Rule} Rule */


/**
Expand Down Expand Up @@ -446,7 +447,7 @@ class FlatRuleTester {
/**
* Adds a new rule test to execute.
* @param {string} ruleName The name of the rule to run.
* @param {Function} rule The rule to test.
* @param {Function | Rule} rule The rule to test.
* @param {{
* valid: (ValidTestCase | string)[],
* invalid: InvalidTestCase[]
Expand Down
8 changes: 6 additions & 2 deletions lib/rule-tester/rule-tester.js
Expand Up @@ -62,6 +62,7 @@ const { SourceCode } = require("../source-code");
//------------------------------------------------------------------------------

/** @typedef {import("../shared/types").Parser} Parser */
/** @typedef {import("../shared/types").Rule} Rule */


/**
Expand Down Expand Up @@ -508,17 +509,20 @@ class RuleTester {
/**
* Define a rule for one particular run of tests.
* @param {string} name The name of the rule to define.
* @param {Function} rule The rule definition.
* @param {Function | Rule} rule The rule definition.
* @returns {void}
*/
defineRule(name, rule) {
if (typeof rule === "function") {
emitLegacyRuleAPIWarning(name);
}
this.rules[name] = rule;
}

/**
* Adds a new rule test to execute.
* @param {string} ruleName The name of the rule to run.
* @param {Function} rule The rule to test.
* @param {Function | Rule} rule The rule to test.
* @param {{
* valid: (ValidTestCase | string)[],
* invalid: InvalidTestCase[]
Expand Down

0 comments on commit 7234f6a

Please sign in to comment.