Skip to content

Commit

Permalink
fix: no-callback-literal ignore unknown nodes (#163)
Browse files Browse the repository at this point in the history
fixes #162
  • Loading branch information
aladdin-add committed Jan 9, 2024
1 parent c191101 commit 5fc2198
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/rules/no-callback-literal.js
Expand Up @@ -62,7 +62,8 @@ function couldBeError(node) {
case "TaggedTemplateExpression":
case "YieldExpression":
return true // possibly an error object.

case "Literal":
return node.value == null
case "AssignmentExpression":
return couldBeError(node.right)

Expand All @@ -76,8 +77,7 @@ function couldBeError(node) {

case "ConditionalExpression":
return couldBeError(node.consequent) || couldBeError(node.alternate)

default:
return node.value === null
return true // assuming unknown nodes can be error objects.
}
}
6 changes: 6 additions & 0 deletions tests/lib/rules/no-callback-literal.js
Expand Up @@ -6,6 +6,7 @@

const RuleTester = require("eslint").RuleTester
const rule = require("../../../lib/rules/no-callback-literal")
const tsParser = require("@typescript-eslint/parser")

const ruleTester = new RuleTester({ env: { node: true, es6: true } })
ruleTester.run("no-callback-literal", rule, {
Expand Down Expand Up @@ -40,6 +41,11 @@ ruleTester.run("no-callback-literal", rule, {
"cb(null)",
'cb(undefined, "super")',
'cb(null, "super")',
// https://github.com/eslint-community/eslint-plugin-n/issues/162
{
code: "cb(e as Error)",
languageOptions: { parser: tsParser },
},
],

invalid: [
Expand Down

0 comments on commit 5fc2198

Please sign in to comment.