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