no-return-in-finally.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict'
  2. const getDocsUrl = require('./lib/get-docs-url')
  3. const isPromise = require('./lib/is-promise')
  4. module.exports = {
  5. meta: {
  6. type: 'problem',
  7. docs: {
  8. url: getDocsUrl('no-return-in-finally'),
  9. },
  10. },
  11. create(context) {
  12. return {
  13. CallExpression(node) {
  14. if (isPromise(node)) {
  15. if (
  16. node.callee &&
  17. node.callee.property &&
  18. node.callee.property.name === 'finally'
  19. ) {
  20. if (
  21. node.arguments &&
  22. node.arguments[0] &&
  23. node.arguments[0].body &&
  24. node.arguments[0].body.body
  25. ) {
  26. if (
  27. node.arguments[0].body.body.some((statement) => {
  28. return statement.type === 'ReturnStatement'
  29. })
  30. ) {
  31. context.report({
  32. node: node.callee.property,
  33. message: 'No return in finally',
  34. })
  35. }
  36. }
  37. }
  38. }
  39. },
  40. }
  41. },
  42. }