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
  • Loading branch information
ahce committed Aug 26, 2023
1 parent bbcfcbf commit 79d8d0d
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 @@ -10,6 +10,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 @@ -47,12 +49,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 79d8d0d

Please sign in to comment.