-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools: enable array-callback-return ESLint rule #17858
Conversation
lib/readline.js
Outdated
@@ -501,7 +501,7 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) { | |||
|
|||
// If there is a common prefix to all matches, then apply that portion. | |||
var f = completions.filter(function completionFilter(e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be reduced to completions.filter(e => e)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I was being cautious. MDN indicates that the callback should return true
or false
and makes no mention of truthy or falsy values. But now I've looked at the ECMA-262 spec and it makes it explicit that the callback may return a value that is coercible to a Boolean. I'll change it to your suggestion to minimize the unnecessary changes here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Might not bother with the change to arrow function just to keep the diff as small as possible. I assume there's no strong preference there.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d go for it. +1 -3 vs. +1 -1 are both really small, and I don’t think this line is interesting enough for people to use git blame on it either way.
lib/readline.js
Outdated
@@ -501,7 +501,7 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) { | |||
|
|||
// If there is a common prefix to all matches, then apply that portion. | |||
var f = completions.filter(function completionFilter(e) { | |||
if (e) return e; | |||
return !!e; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: using Boolean(e)
here might be more readable
Use construct that always returns a boolean for `filter()` callback.
Two tests were using Array.prototype.map() without returning values in the callback. In other words, they were using it where a `.forEach()` was called for. Change to `.forEach()`.
For array methods that depend on a callback (such as `.filter()` or `.map()`), require a return value from the callback.
CI failures look unrelated. |
Use construct that always returns a boolean for `filter()` callback. PR-URL: #17858 Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Two tests were using Array.prototype.map() without returning values in the callback. In other words, they were using it where a `.forEach()` was called for. Change to `.forEach()`. PR-URL: #17858 Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
For array methods that depend on a callback (such as `.filter()` or `.map()`), require a return value from the callback. PR-URL: #17858 Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Use construct that always returns a boolean for `filter()` callback. PR-URL: #17858 Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Two tests were using Array.prototype.map() without returning values in the callback. In other words, they were using it where a `.forEach()` was called for. Change to `.forEach()`. PR-URL: #17858 Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
For array methods that depend on a callback (such as `.filter()` or `.map()`), require a return value from the callback. PR-URL: #17858 Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Use construct that always returns a boolean for `filter()` callback. PR-URL: #17858 Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Two tests were using Array.prototype.map() without returning values in the callback. In other words, they were using it where a `.forEach()` was called for. Change to `.forEach()`. PR-URL: #17858 Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
For array methods that depend on a callback (such as `.filter()` or `.map()`), require a return value from the callback. PR-URL: #17858 Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Use construct that always returns a boolean for `filter()` callback. PR-URL: #17858 Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Two tests were using Array.prototype.map() without returning values in the callback. In other words, they were using it where a `.forEach()` was called for. Change to `.forEach()`. PR-URL: #17858 Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
For array methods that depend on a callback (such as `.filter()` or `.map()`), require a return value from the callback. PR-URL: #17858 Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Assuming this doesn't need to be backported, raise a PR if you disagree. |
For array methods that depend on a callback (such as
.filter()
or.map()
), require a return value from the callback.First two commits fix a few issues in our code base that would be flagged by this rule.
Third commit enables the rule itself.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
tools readline test