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 | docs: {
|
15 | url: getDocsUrl('no-promise-in-callback')
|
16 | }
|
17 | },
|
18 | create(context) {
|
19 | return {
|
20 | CallExpression(node) {
|
21 | if (!isPromise(node)) return
|
22 |
|
23 |
|
24 |
|
25 | if (node.parent.type === 'ReturnStatement') return
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | if (context.getAncestors().some(isInsideCallback)) {
|
31 | context.report({
|
32 | node: node.callee,
|
33 | message: 'Avoid using promises inside of callbacks.'
|
34 | })
|
35 | }
|
36 | }
|
37 | }
|
38 | }
|
39 | }
|