1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict'
|
7 |
|
8 | const getDocsUrl = require('./lib/get-docs-url')
|
9 | const isPromise = require('./lib/is-promise')
|
10 | const isInsideCallback = require('./lib/is-inside-callback')
|
11 |
|
12 | module.exports = {
|
13 | meta: {
|
14 | type: 'suggestion',
|
15 | docs: {
|
16 | url: getDocsUrl('no-promise-in-callback'),
|
17 | },
|
18 | schema: [],
|
19 | },
|
20 | create(context) {
|
21 | return {
|
22 | CallExpression(node) {
|
23 | if (!isPromise(node)) return
|
24 |
|
25 |
|
26 |
|
27 | if (node.parent.type === 'ReturnStatement') return
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | if (context.getAncestors().some(isInsideCallback)) {
|
33 | context.report({
|
34 | node: node.callee,
|
35 | message: 'Avoid using promises inside of callbacks.',
|
36 | })
|
37 | }
|
38 | },
|
39 | }
|
40 | },
|
41 | }
|