question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Falsy error in `array-callback-return`

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:19 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
mysticateacommented, May 5, 2016

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() as throw. This might help this issue.

2reactions
platinumazurecommented, May 1, 2016

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:

I don’t really see the problem with it being Node.js specific. ESLint already have Node.js and browser specific rules. The use of process.exit() is a very common thing in CLI apps and workers. Maybe if the ESLint plugin API exposed a method to mark something as unreachable, in similar manner to markVariableAsUsed(), we could fix this ourselves. The alternative is having to reimplement this rule in userland, which would be a shame for such a small tweak.

My personal recommendation would be to use `// eslint-disable-line array-callback-return for just this invocation.

This issue wouldn’t have been opened if that was something we wanted. Not interested in littering our code with a myriad of eslint-disable statements.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/eslint/eslint/issues/6014#issuecomment-216042752

Read more comments on GitHub >

github_iconTop Results From Across the Web

array-callback-return - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
[array-callback-return] False positive when in a map that uses ...
I have read the FAQ and my problem is not listed. Repro. The rule array-callback-return is enabled with default settings. There are no...
Read more >
Callback function with a truthy value in JavaScript
The conditional callback(array[i]) verifies if the value of isEven() function passed as callback evaluates to true/false for array[i] .
Read more >
Mastering Hard Parts of JavaScript: Callbacks III
The callback will return either true or false. majority will iterate through the array and perform the callback on each element until it...
Read more >
JavaScript Array some: Check If at Least one Array Element ...
In this tutorial, you will learn how to use the JavaScript Array some() method ... causes the callback() to return true , the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found