|
7 | 7 |
|
8 | 8 | const { getAncestors } = require('./lib/eslint-compat')
|
9 | 9 | const getDocsUrl = require('./lib/get-docs-url')
|
| 10 | +const hasPromiseCallback = require('./lib/has-promise-callback') |
10 | 11 | const isInsidePromise = require('./lib/is-inside-promise')
|
11 | 12 | const isCallback = require('./lib/is-callback')
|
12 | 13 |
|
@@ -67,20 +68,29 @@ module.exports = {
|
67 | 68 | const options = context.options[0] || {}
|
68 | 69 | const exceptions = options.exceptions || []
|
69 | 70 | if (!isCallback(node, exceptions)) {
|
70 |
| - const callingName = node.callee.name || node.callee.property?.name |
71 |
| - const name = |
72 |
| - node.arguments && node.arguments[0] && node.arguments[0].name |
73 |
| - if ( |
74 |
| - !exceptions.includes(name) && |
75 |
| - CB_BLACKLIST.includes(name) && |
76 |
| - (timeoutsErr || !TIMEOUT_WHITELIST.includes(callingName)) |
77 |
| - ) { |
78 |
| - context.report({ |
79 |
| - node: node.arguments[0], |
80 |
| - messageId: 'callback', |
81 |
| - }) |
| 71 | + const name = node.arguments?.[0]?.name |
| 72 | + if (hasPromiseCallback(node)) { |
| 73 | + const callingName = node.callee.name || node.callee.property?.name |
| 74 | + if ( |
| 75 | + !exceptions.includes(name) && |
| 76 | + CB_BLACKLIST.includes(name) && |
| 77 | + (timeoutsErr || !TIMEOUT_WHITELIST.includes(callingName)) |
| 78 | + ) { |
| 79 | + context.report({ |
| 80 | + node: node.arguments[0], |
| 81 | + messageId: 'callback', |
| 82 | + }) |
| 83 | + } |
| 84 | + return |
| 85 | + } |
| 86 | + if (!timeoutsErr) { |
| 87 | + return |
| 88 | + } |
| 89 | + |
| 90 | + if (!name) { |
| 91 | + // Will be handled elsewhere |
| 92 | + return |
82 | 93 | }
|
83 |
| - return |
84 | 94 | }
|
85 | 95 |
|
86 | 96 | const ancestors = getAncestors(context, node)
|
|
0 commit comments