Skip to content

Commit f368c5a

Browse files
authored
fix(always-return): treat process.exit() or process.abort() as an acceptable "return" (#493)
1 parent 36d13f5 commit f368c5a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

__tests__/always-return.js

+8
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ ruleTester.run('always-return', rule, {
1717
'hey.then(x => { return; })',
1818
'hey.then(x => { return x ? x.id : null })',
1919
'hey.then(x => { return x * 10 })',
20+
'hey.then(x => { process.exit(0); })',
21+
'hey.then(x => { process.abort(); })',
2022
'hey.then(function() { return 42; })',
2123
'hey.then(function() { return new Promise(); })',
2224
'hey.then(function() { return "x"; }).then(doSomethingWicked)',
2325
'hey.then(x => x).then(function() { return "3" })',
2426
'hey.then(function() { throw new Error("msg"); })',
2527
'hey.then(function(x) { if (!x) { throw new Error("no x"); } return x; })',
2628
'hey.then(function(x) { if (x) { return x; } throw new Error("no x"); })',
29+
'hey.then(function(x) { if (x) { process.exit(0); } throw new Error("no x"); })',
30+
'hey.then(function(x) { if (x) { process.abort(); } throw new Error("no x"); })',
2731
'hey.then(x => { throw new Error("msg"); })',
2832
'hey.then(x => { if (!x) { throw new Error("no x"); } return x; })',
2933
'hey.then(x => { if (x) { return x; } throw new Error("no x"); })',
@@ -140,6 +144,10 @@ ruleTester.run('always-return', rule, {
140144
code: 'hey.then(function() { if (x) { } else { return x; }})',
141145
errors: [{ message }],
142146
},
147+
{
148+
code: 'hey.then(function() { if (x) { process.chdir(); } else { return x; }})',
149+
errors: [{ message }],
150+
},
143151
{
144152
code: 'hey.then(function() { if (x) { return you.then(function() { return x; }); } })',
145153
errors: [{ message }],

rules/always-return.js

+4
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ module.exports = {
202202
return {
203203
'ReturnStatement:exit': markCurrentBranchAsGood,
204204
'ThrowStatement:exit': markCurrentBranchAsGood,
205+
'ExpressionStatement > CallExpression > MemberExpression[object.name="process"][property.name="exit"]:exit':
206+
markCurrentBranchAsGood,
207+
'ExpressionStatement > CallExpression > MemberExpression[object.name="process"][property.name="abort"]:exit':
208+
markCurrentBranchAsGood,
205209

206210
/**
207211
* @param {CodePathSegment} segment

0 commit comments

Comments
 (0)