Skip to content

Commit 5e4546d

Browse files
authored
fix(no-callback-in-promise): false positives when the exception is an argument (#446)
1 parent c0c716b commit 5e4546d

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
@@ -11,6 +11,8 @@ const hasPromiseCallback = require('./lib/has-promise-callback')
1111
const isInsidePromise = require('./lib/is-inside-promise')
1212
const isCallback = require('./lib/is-callback')
1313

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

0 commit comments

Comments
 (0)