ags
This commit is contained in:
parent
eddf7cecb8
commit
aea798d119
16631 changed files with 1480363 additions and 257 deletions
43
home/ags/node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
generated
vendored
Normal file
43
home/ags/node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
generated
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* Rule: no-promise-in-callback
|
||||
* Discourage using promises inside of callbacks.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const { getAncestors } = require('./lib/eslint-compat')
|
||||
const getDocsUrl = require('./lib/get-docs-url')
|
||||
const isPromise = require('./lib/is-promise')
|
||||
const isInsideCallback = require('./lib/is-inside-callback')
|
||||
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Disallow using promises inside of callbacks.',
|
||||
url: getDocsUrl('no-promise-in-callback'),
|
||||
},
|
||||
schema: [],
|
||||
},
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!isPromise(node)) return
|
||||
|
||||
// if i'm returning the promise, it's probably not really a callback
|
||||
// function, and I should be okay....
|
||||
if (node.parent.type === 'ReturnStatement') return
|
||||
|
||||
// what about if the parent is an ArrowFunctionExpression
|
||||
// would that imply an implicit return?
|
||||
|
||||
if (getAncestors(context, node).some(isInsideCallback)) {
|
||||
context.report({
|
||||
node: node.callee,
|
||||
message: 'Avoid using promises inside of callbacks.',
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue