no-nesting.js 634 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * Rule: no-nesting
  3. * Avoid nesting your promises.
  4. */
  5. 'use strict'
  6. const getDocsUrl = require('./lib/get-docs-url')
  7. const hasPromiseCallback = require('./lib/has-promise-callback')
  8. const isInsidePromise = require('./lib/is-inside-promise')
  9. module.exports = {
  10. meta: {
  11. type: 'suggestion',
  12. docs: {
  13. url: getDocsUrl('no-nesting'),
  14. },
  15. },
  16. create(context) {
  17. return {
  18. CallExpression(node) {
  19. if (!hasPromiseCallback(node)) return
  20. if (context.getAncestors().some(isInsidePromise)) {
  21. context.report({ node, message: 'Avoid nesting promises.' })
  22. }
  23. },
  24. }
  25. },
  26. }