Sha256: 133151e02e684f14153153c309d613911910d5c050bc2a4f29e5699c546d3bee

Contents?: true

Size: 1.48 KB

Versions: 43

Compression:

Stored size: 1.48 KB

Contents

/**
 * Rule: no-callback-in-promise
 * Avoid calling back inside of a promise
 */

'use strict'

const getDocsUrl = require('./lib/get-docs-url')
const hasPromiseCallback = require('./lib/has-promise-callback')
const isInsidePromise = require('./lib/is-inside-promise')
const isCallback = require('./lib/is-callback')

module.exports = {
  meta: {
    docs: {
      url: getDocsUrl('no-callback-in-promise')
    },
    messages: {
      callback: 'Avoid calling back inside of a promise.'
    }
  },
  create(context) {
    return {
      CallExpression(node) {
        const options = context.options[0] || {}
        const exceptions = options.exceptions || []
        if (!isCallback(node, exceptions)) {
          // in general we send you packing if you're not a callback
          // but we also need to watch out for whatever.then(cb)
          if (hasPromiseCallback(node)) {
            const name =
              node.arguments && node.arguments[0] && node.arguments[0].name
            if (
              name === 'callback' ||
              name === 'cb' ||
              name === 'next' ||
              name === 'done'
            ) {
              context.report({
                node: node.arguments[0],
                messageId: 'callback'
              })
            }
          }
          return
        }
        if (context.getAncestors().some(isInsidePromise)) {
          context.report({
            node,
            messageId: 'callback'
          })
        }
      }
    }
  }
}

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-callback-in-promise.js
govuk_publishing_components-17.21.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.20.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.19.1 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.19.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.18.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.17.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.16.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.15.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.14.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.13.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.12.2 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.12.1 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.12.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.11.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.10.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.9.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.8.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.7.0 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js
govuk_publishing_components-17.6.1 node_modules/eslint-plugin-promise/rules/no-callback-in-promise.js