-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (46 loc) · 1.86 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module.exports = {
configs: {
recommended: {
plugins: ['no-expectsaga-without-return'],
rules: {
// Error
"no-expectsaga-without-return/mandatory-return": 2
}
}
},
rules: {
'mandatory-return': {
meta: {
fixable: 'code'
},
create: function(context) {
return {
"BlockStatement > ExpressionStatement > CallExpression Identifier[name='expectSaga']": node => {
const parents = context.getAncestors().reverse();
let expressionNode;
for (const parent of parents) {
// Skip call chains to the closes ExpressionStatement, return or arrow function
if (!['CallExpression', 'MemberExpression'].includes(parent.type)) {
if (['ReturnStatement', 'ArrowFunctionExpression', 'AwaitExpression'].includes(parent.type)) {
return;
} else if (parent.type === 'ExpressionStatement') {
expressionNode = parent;
}
break;
}
}
context.report({
node,
message: "expectSaga without return",
fix(fixer) {
if (expressionNode) {
return fixer.insertTextBefore(expressionNode, "return ");
}
}
});
}
}
}
}
}
}