Skip to content

Commit dca2330

Browse files
authored
fix(no-callback-literal): report object, array, and template literals (#552)
1 parent 3ff929d commit dca2330

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

lib/rules/no-callback-literal.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ function couldBeError(node) {
5959
return true // possibly an error object.
6060
case "Literal":
6161
return node.value == null
62+
case "ArrayExpression":
63+
case "ObjectExpression":
64+
case "TemplateLiteral":
65+
return false
6266
case "AssignmentExpression":
6367
return couldBeError(node.right)
6468

tests/lib/rules/no-callback-literal.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,33 @@ ruleTester.run("no-callback-literal", rule, {
105105
},
106106
],
107107
},
108+
{
109+
code: "cb({ a: 1 })",
110+
errors: [
111+
{
112+
message:
113+
"Unexpected literal in error position of callback.",
114+
},
115+
],
116+
},
117+
{
118+
code: "cb([])",
119+
errors: [
120+
{
121+
message:
122+
"Unexpected literal in error position of callback.",
123+
},
124+
],
125+
},
126+
{
127+
code: "cb(`message ${value}`)",
128+
errors: [
129+
{
130+
message:
131+
"Unexpected literal in error position of callback.",
132+
},
133+
],
134+
},
108135
{
109136
code: "callback((a, 1), data)",
110137
errors: [

0 commit comments

Comments
 (0)