Skip to content

Commit

Permalink
fix: correctly handle null default config in RuleTester (#17023)
Browse files Browse the repository at this point in the history
* fix: correctly handle `null` default config in `RuleTester`

* fix: update flatruletester
  • Loading branch information
bradzacher committed Mar 28, 2023
1 parent ec2d830 commit 619f3fd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/rule-tester/flat-rule-tester.js
Expand Up @@ -345,7 +345,7 @@ class FlatRuleTester {
* @returns {void}
*/
static setDefaultConfig(config) {
if (typeof config !== "object") {
if (typeof config !== "object" || config === null) {
throw new TypeError("FlatRuleTester.setDefaultConfig: config must be an object");
}
sharedDefaultConfig = config;
Expand Down
2 changes: 1 addition & 1 deletion lib/rule-tester/rule-tester.js
Expand Up @@ -412,7 +412,7 @@ class RuleTester {
* @returns {void}
*/
static setDefaultConfig(config) {
if (typeof config !== "object") {
if (typeof config !== "object" || config === null) {
throw new TypeError("RuleTester.setDefaultConfig: config must be an object");
}
defaultConfig = config;
Expand Down
14 changes: 8 additions & 6 deletions tests/lib/rule-tester/flat-rule-tester.js
Expand Up @@ -142,12 +142,14 @@ describe("FlatRuleTester", () => {
FlatRuleTester.setDefaultConfig(config);
};
}
assert.throw(setConfig());
assert.throw(setConfig(1));
assert.throw(setConfig(3.14));
assert.throw(setConfig("foo"));
assert.throw(setConfig(null));
assert.throw(setConfig(true));
const errorMessage = "FlatRuleTester.setDefaultConfig: config must be an object";

assert.throw(setConfig(), errorMessage);
assert.throw(setConfig(1), errorMessage);
assert.throw(setConfig(3.14), errorMessage);
assert.throw(setConfig("foo"), errorMessage);
assert.throw(setConfig(null), errorMessage);
assert.throw(setConfig(true), errorMessage);
});

it("should pass-through the globals config to the tester then to the to rule", () => {
Expand Down
14 changes: 8 additions & 6 deletions tests/lib/rule-tester/rule-tester.js
Expand Up @@ -1412,12 +1412,14 @@ describe("RuleTester", () => {
RuleTester.setDefaultConfig(config);
};
}
assert.throw(setConfig());
assert.throw(setConfig(1));
assert.throw(setConfig(3.14));
assert.throw(setConfig("foo"));
assert.throw(setConfig(null));
assert.throw(setConfig(true));
const errorMessage = "RuleTester.setDefaultConfig: config must be an object";

assert.throw(setConfig(), errorMessage);
assert.throw(setConfig(1), errorMessage);
assert.throw(setConfig(3.14), errorMessage);
assert.throw(setConfig("foo"), errorMessage);
assert.throw(setConfig(null), errorMessage);
assert.throw(setConfig(true), errorMessage);
});

it("should pass-through the globals config to the tester then to the to rule", () => {
Expand Down

0 comments on commit 619f3fd

Please sign in to comment.