Skip to content

Commit

Permalink
Fix: no-compare-relation-boolean crash when passing <2 args (#234)
Browse files Browse the repository at this point in the history
* Fix no-compare-relation-boolean error when passing <2 args

* add test for 1-arg call

* fix test failures
  • Loading branch information
dwickern committed Jun 8, 2022
1 parent 23fa36d commit f25a525
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/rules/no-compare-relation-boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ module.exports = {

function checkAssertArguments(callExprNode) {
const args = [...callExprNode.arguments];
if (args.length < 2) {
return;
}

const firstTwoArgsSorted = args.slice(0, 2).sort(sortLiteralFirst);

Expand Down
6 changes: 5 additions & 1 deletion tests/lib/rules/no-compare-relation-boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ ruleTester.run("no-compare-relation-boolean", rule, {

// Comparing against something that isn't a boolean literal is fine
"assert.equal(a > b, 1);",
"assert.equal(a > b, c);"
"assert.equal(a > b, c);",

// Not enough arguments
"assert.strictEqual();",
"assert.strictEqual(a);"
].map(code => testUtils.wrapInTest(code)),

invalid: [
Expand Down

0 comments on commit f25a525

Please sign in to comment.