Skip to content

Commit

Permalink
fix(no-callback-in-promise): false positives when the exception is an…
Browse files Browse the repository at this point in the history
… argument (#446)
  • Loading branch information
ahce authored May 27, 2024
1 parent c0c716b commit 5e4546d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 12 additions & 0 deletions __tests__/no-callback-in-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ ruleTester.run('no-callback-in-promise', rule, {
code: 'a.then(() => next())',
options: [{ exceptions: ['next'] }],
},
{
code: 'a.then(() => next()).catch((err) => next(err))',
options: [{ exceptions: ['next'] }],
},
{
code: 'a.then(next)',
options: [{ exceptions: ['next'] }],
},
{
code: 'a.then(next).catch(next)',
options: [{ exceptions: ['next'] }],
},
],

invalid: [
Expand Down
9 changes: 3 additions & 6 deletions rules/no-callback-in-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const hasPromiseCallback = require('./lib/has-promise-callback')
const isInsidePromise = require('./lib/is-inside-promise')
const isCallback = require('./lib/is-callback')

const CB_BLACKLIST = ['callback', 'cb', 'next', 'done']

module.exports = {
meta: {
type: 'suggestion',
Expand Down Expand Up @@ -48,12 +50,7 @@ module.exports = {
if (hasPromiseCallback(node)) {
const name =
node.arguments && node.arguments[0] && node.arguments[0].name
if (
name === 'callback' ||
name === 'cb' ||
name === 'next' ||
name === 'done'
) {
if (!exceptions.includes(name) && CB_BLACKLIST.includes(name)) {
context.report({
node: node.arguments[0],
messageId: 'callback',
Expand Down

0 comments on commit 5e4546d

Please sign in to comment.