Skip to content

Commit 84dee91

Browse files
committed
Don't allow false in "no-callback-literal"
1 parent 20357ba commit 84dee91

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ There are several rules that were created specifically for the `standard` linter
2525
- `object-curly-even-spacing` - Like `object-curly-spacing` from ESLint except it has an `either` option which lets you have 1 or 0 spaces padding.
2626
- `array-bracket-even-spacing` - Like `array-bracket-even-spacing` from ESLint except it has an `either` option which lets you have 1 or 0 spacing padding.
2727
- `computed-property-even-spacing` - Like `computed-property-spacing` around ESLint except is has an `even` option which lets you have 1 or 0 spacing padding.
28-
- `no-callback-literal` - Ensures that we strictly follow the callback pattern with `undefined`, `false`, `null` or an error object in the first position of a callback.
28+
- `no-callback-literal` - Ensures that we strictly follow the callback pattern with `undefined`, `null` or an error object in the first position of a callback.
2929

rules/no-callback-literal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function couldBeError (node) {
3838
return couldBeError(node.consequent) || couldBeError(node.alternate)
3939

4040
default:
41-
return node.value === null || node.value === false
41+
return node.value === null
4242
}
4343
}
4444

@@ -67,7 +67,7 @@ module.exports = {
6767
context.report(node, 'Unexpected literal in error position of callback.')
6868
} else if (node.arguments.length > 1 && errorArg.type === 'Identifier') {
6969
if (errorArg.name === 'undefined') {
70-
context.report(node, 'Expected null instead found undefined.')
70+
context.report(node, 'Expected "null" instead of "undefined" in error position of callback.')
7171
}
7272
}
7373
}

tests/no-callback-literal.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ ruleTester.run('no-callback-literal', rule, {
3131
'callback(undefined)',
3232
'callback(null)',
3333
'callback(x)',
34-
'callback(false)',
3534
'callback(new Error("error"))',
3635
'callback(friendly, data)',
3736
'callback(null, data)',
@@ -40,7 +39,6 @@ ruleTester.run('no-callback-literal', rule, {
4039

4140
// cb()
4241
'cb()',
43-
'cb(false)',
4442
'cb(undefined)',
4543
'cb(null)',
4644
'cb(null, "super")',
@@ -50,7 +48,6 @@ ruleTester.run('no-callback-literal', rule, {
5048
'next(undefined)',
5149
'next(null)',
5250
'next(null, "super")',
53-
'next(false, "super")',
5451

5552
// custom callback
5653
{
@@ -61,17 +58,20 @@ ruleTester.run('no-callback-literal', rule, {
6158

6259
invalid: [
6360
// callback
64-
{ code: 'callback(undefined, "snork")', errors: [{ message: 'Expected null instead found undefined.' }] },
61+
{ code: 'callback(undefined, "snork")', errors: [{ message: 'Expected "null" instead of "undefined" in error position of callback.' }] },
62+
{ code: 'callback(false, "snork")', errors: [{ message: 'Unexpected literal in error position of callback.' }] },
6563
{ code: 'callback("help")', errors: [{ message: 'Unexpected literal in error position of callback.' }] },
6664
{ code: 'callback("help", data)', errors: [{ message: 'Unexpected literal in error position of callback.' }] },
6765

6866
// cb
69-
{ code: 'cb(undefined, "snork")', errors: [{ message: 'Expected null instead found undefined.' }] },
67+
{ code: 'cb(undefined, "snork")', errors: [{ message: 'Expected "null" instead of "undefined" in error position of callback.' }] },
68+
{ code: 'cb(false)', errors: [{ message: 'Unexpected literal in error position of callback.' }] },
7069
{ code: 'cb("help")', errors: [{ message: 'Unexpected literal in error position of callback.' }] },
7170
{ code: 'cb("help", data)', errors: [{ message: 'Unexpected literal in error position of callback.' }] },
7271

7372
// next
74-
{ code: 'next(undefined, "snork")', errors: [{ message: 'Expected null instead found undefined.' }] },
73+
{ code: 'next(undefined, "snork")', errors: [{ message: 'Expected "null" instead of "undefined" in error position of callback.' }] },
74+
{ code: 'next(false, "snork")', errors: [{ message: 'Unexpected literal in error position of callback.' }] },
7575
{ code: 'next("help")', errors: [{ message: 'Unexpected literal in error position of callback.' }] },
7676
{ code: 'next("help", data)', errors: [{ message: 'Unexpected literal in error position of callback.' }] },
7777

0 commit comments

Comments
 (0)