Constnium/node_modules/eslint-plugin-promise/rules/no-nesting.js
2022-06-23 02:27:43 +02:00

30 lines
650 B
JavaScript

/**
* Rule: no-nesting
* Avoid nesting your promises.
*/
'use strict'
const getDocsUrl = require('./lib/get-docs-url')
const hasPromiseCallback = require('./lib/has-promise-callback')
const isInsidePromise = require('./lib/is-inside-promise')
module.exports = {
meta: {
type: 'suggestion',
docs: {
url: getDocsUrl('no-nesting'),
},
schema: [],
},
create(context) {
return {
CallExpression(node) {
if (!hasPromiseCallback(node)) return
if (context.getAncestors().some(isInsidePromise)) {
context.report({ node, message: 'Avoid nesting promises.' })
}
},
}
},
}