-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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 no-else-return ESLint rule #11159
Conversation
benchmark/_http-benchmarkers.js
Outdated
} | ||
return result.requests.average; | ||
|
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 think these blank lines should be removed.
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.
Rubber stamp-y LGTM except style nits
test/parallel/test-fs-utimes.js
Outdated
} | ||
// ensure mtime has been written to disk |
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.
Indentation is off
test/parallel/test-buffer-fill.js
Outdated
} | ||
elseWasLast = true; | ||
// Once buffer.js calls the C++ implemenation of fill, return -1 |
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.
Indentation is off
test/parallel/test-buffer-fill.js
Outdated
} | ||
elseWasLast = true; | ||
// Once buffer.js calls the C++ implemenation of fill, return -1 |
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.
Indentation is off
lib/url.js
Outdated
@@ -533,8 +533,7 @@ function autoEscapeStr(rest) { | |||
// There are ordinary characters at the end. | |||
if (lastEscapedPos < rest.length) | |||
return escaped + rest.slice(lastEscapedPos); | |||
else // The last character is escaped. | |||
return escaped; | |||
return escaped; |
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.
Comment is deleted
lib/path.js
Outdated
} | ||
for (i = path.length - 1; i >= start; --i) { | ||
const code = path.charCodeAt(i); | ||
if (code === 47/*/*/ || code === 92/*\*/) { | ||
// If we reached a path separator that was not part of a set of path |
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.
Indentation is off
lib/fs.js
Outdated
} | ||
// Windows symlinks don't tolerate forward slashes. |
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.
Indentation is off
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 am not sure how the linter missed the indentation problems.
lib/_stream_readable.js
Outdated
@@ -18,18 +18,18 @@ function prependListener(emitter, event, fn) { | |||
// event emitter implementation with them. | |||
if (typeof emitter.prependListener === 'function') { | |||
return emitter.prependListener(event, fn); | |||
} else { | |||
} | |||
// This is a hack to make sure that our error handler is attached before any |
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.
Indentation.
lib/path.js
Outdated
if (path.charCodeAt(i) === 47/*/*/) { | ||
} | ||
for (i = path.length - 1; i >= 0; --i) { | ||
if (path.charCodeAt(i) === 47/*/*/) { | ||
// If we reached a path separator that was not part of a set of path |
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.
Indentation.
Currently, it does not check the indentation of comments. This is planned to change in the next major release. |
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.
LGTM with the extra empty lines removed.
I personally find it easier to visually parse code with the |
@@ -533,8 +533,9 @@ function autoEscapeStr(rest) { | |||
// There are ordinary characters at the end. | |||
if (lastEscapedPos < rest.length) | |||
return escaped + rest.slice(lastEscapedPos); | |||
else // The last character is escaped. | |||
return escaped; | |||
|
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.
Still some blank lines like this.
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.
That's the only one, I think, and that one makes sense to me. Will remove it if anyone disagrees.
Also if we were using |
If there is a `return` in an `if` block, an `else` block is unnecessary. It can simply be moved after the `if` block. This is in preparation for a lint rule to enforce this practice.
1735e53
to
078670e
Compare
I'm going to honor the preference expressed by @silverwind and @addaleax and close this. I don't feel strongly about it and it doesn't seem to come up as something in PR review comments. If someone else feels far more strongly about this than I do, feel free to re-open, comment, or open another PR. |
I missed this until now, but belatedly, LGTM, I like the else-less style. It cuts down on indentation, and makes clear that once a conditional has been handled by return, code can continue indentless and read more linearly. But I don't feel really strong about it, I can read the code either way. |
If an if block contains a return statement, the else block becomes unnecessary. Its contents can be placed outside of the block.
Refs: http://eslint.org/docs/rules/no-else-return
Inspired by #11148
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
tools test lib benchmark