no-return-in-finally.js 1.0 KB

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