Sha256: cc1a8e0e2b63bb24f4830c08bac98d53daad7b53a02b75a3c240da868a129bf9

Contents?: true

Size: 987 Bytes

Versions: 43

Compression:

Stored size: 987 Bytes

Contents

/**
 * Rule: no-promise-in-callback
 * Discourage using promises inside of callbacks.
 */

'use strict'

const getDocsUrl = require('./lib/get-docs-url')
const isPromise = require('./lib/is-promise')
const isInsideCallback = require('./lib/is-inside-callback')

module.exports = {
  meta: {
    docs: {
      url: getDocsUrl('no-promise-in-callback')
    }
  },
  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 (context.getAncestors().some(isInsideCallback)) {
          context.report({
            node: node.callee,
            message: 'Avoid using promises inside of callbacks.'
          })
        }
      }
    }
  }
}

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.21.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.20.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.19.1 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.19.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.18.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.17.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.16.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.15.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.14.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.13.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.12.2 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.12.1 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.12.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.11.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.10.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.9.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.8.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.7.0 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js
govuk_publishing_components-17.6.1 node_modules/eslint-plugin-promise/rules/no-promise-in-callback.js