Skip to content

Commit

Permalink
Merge pull request #20 from xjamundx/no-callback-literal-false
Browse files Browse the repository at this point in the history
Don't allow `false` in "no-callback-literal"
  • Loading branch information
xjamundx committed Mar 2, 2017
2 parents a936b4f + 84dee91 commit c9a1dfb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ There are several rules that were created specifically for the `standard` linter
- `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.
- `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.
- `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.
- `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.
- `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.

4 changes: 2 additions & 2 deletions rules/no-callback-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function couldBeError (node) {
return couldBeError(node.consequent) || couldBeError(node.alternate)

default:
return node.value === null || node.value === false
return node.value === null
}
}

Expand Down Expand Up @@ -67,7 +67,7 @@ module.exports = {
context.report(node, 'Unexpected literal in error position of callback.')
} else if (node.arguments.length > 1 && errorArg.type === 'Identifier') {
if (errorArg.name === 'undefined') {
context.report(node, 'Expected null instead found undefined.')
context.report(node, 'Expected "null" instead of "undefined" in error position of callback.')
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions tests/no-callback-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ ruleTester.run('no-callback-literal', rule, {
'callback(undefined)',
'callback(null)',
'callback(x)',
'callback(false)',
'callback(new Error("error"))',
'callback(friendly, data)',
'callback(null, data)',
Expand All @@ -40,7 +39,6 @@ ruleTester.run('no-callback-literal', rule, {

// cb()
'cb()',
'cb(false)',
'cb(undefined)',
'cb(null)',
'cb(null, "super")',
Expand All @@ -50,7 +48,6 @@ ruleTester.run('no-callback-literal', rule, {
'next(undefined)',
'next(null)',
'next(null, "super")',
'next(false, "super")',

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

invalid: [
// callback
{ code: 'callback(undefined, "snork")', errors: [{ message: 'Expected null instead found undefined.' }] },
{ code: 'callback(undefined, "snork")', errors: [{ message: 'Expected "null" instead of "undefined" in error position of callback.' }] },
{ code: 'callback(false, "snork")', errors: [{ message: 'Unexpected literal in error position of callback.' }] },
{ code: 'callback("help")', errors: [{ message: 'Unexpected literal in error position of callback.' }] },
{ code: 'callback("help", data)', errors: [{ message: 'Unexpected literal in error position of callback.' }] },

// cb
{ code: 'cb(undefined, "snork")', errors: [{ message: 'Expected null instead found undefined.' }] },
{ code: 'cb(undefined, "snork")', errors: [{ message: 'Expected "null" instead of "undefined" in error position of callback.' }] },
{ code: 'cb(false)', errors: [{ message: 'Unexpected literal in error position of callback.' }] },
{ code: 'cb("help")', errors: [{ message: 'Unexpected literal in error position of callback.' }] },
{ code: 'cb("help", data)', errors: [{ message: 'Unexpected literal in error position of callback.' }] },

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

Expand Down

0 comments on commit c9a1dfb

Please sign in to comment.