Skip to content

Commit 79d8d0d

Browse files
committed
fix(no-callback-in-promise): false positives when the exception is an argument
1 parent bbcfcbf commit 79d8d0d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

__tests__/no-callback-in-promise.js

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ ruleTester.run('no-callback-in-promise', rule, {
3434
code: 'a.then(() => next())',
3535
options: [{ exceptions: ['next'] }],
3636
},
37+
{
38+
code: 'a.then(() => next()).catch((err) => next(err))',
39+
options: [{ exceptions: ['next'] }],
40+
},
41+
{
42+
code: 'a.then(next)',
43+
options: [{ exceptions: ['next'] }],
44+
},
45+
{
46+
code: 'a.then(next).catch(next)',
47+
options: [{ exceptions: ['next'] }],
48+
},
3749
],
3850

3951
invalid: [

rules/no-callback-in-promise.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const hasPromiseCallback = require('./lib/has-promise-callback')
1010
const isInsidePromise = require('./lib/is-inside-promise')
1111
const isCallback = require('./lib/is-callback')
1212

13+
const CB_BLACKLIST = ['callback', 'cb', 'next', 'done']
14+
1315
module.exports = {
1416
meta: {
1517
type: 'suggestion',
@@ -47,12 +49,7 @@ module.exports = {
4749
if (hasPromiseCallback(node)) {
4850
const name =
4951
node.arguments && node.arguments[0] && node.arguments[0].name
50-
if (
51-
name === 'callback' ||
52-
name === 'cb' ||
53-
name === 'next' ||
54-
name === 'done'
55-
) {
52+
if (!exceptions.includes(name) && CB_BLACKLIST.includes(name)) {
5653
context.report({
5754
node: node.arguments[0],
5855
messageId: 'callback',

0 commit comments

Comments
 (0)