UNPKG

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