eslint: Falsy error in `array-callback-return`
Returning something inside a try/catch
block inside arr.map
will sometimes falsely report an error. The following code should be perfectly valid (since there’s an process.exit()
which should imply that it should return or exit). Currently I have to assign my return to a variable and return it outside the try/catch
.
arr.map(() => {
try {
return require('foo');
} catch (err) {
console.error(err);
process.exit(1);
}
});
Using ESLint version 2.9.0
and the failing rule is array-callback-return
.
Ref https://github.com/imagemin/imagemin-cli/pull/6#discussion_r61607411.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 5
- Comments: 19 (14 by maintainers)
I have added node/process-exit-as-throw rule experimentally to eslint-plugin-node. If this rule is turned on, ESLint’s code path analysis will address
process.exit()
asthrow
. This might help this issue.Just want to go on the record and clarify my position: I don’t believe a rule that isn’t already runtime-specific should become runtime-specific by handling runtime-specific cases. That was what I meant in my initial reply. On May 1, 2016 8:41 AM, “Sindre Sorhus” notifications@github.com wrote: