Skip to content

Conversation

@Trott
Copy link
Member

@Trott Trott commented Feb 4, 2017

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), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

tools test lib benchmark

@Trott Trott added benchmark Issues and PRs related to the benchmark subsystem. lib / src Issues and PRs related to general changes in the lib or src directory. test Issues and PRs related to the tests. tools Issues and PRs related to the tools directory. labels Feb 4, 2017
@nodejs-github-bot nodejs-github-bot added dont-land-on-v4.x lib / src Issues and PRs related to general changes in the lib or src directory. tools Issues and PRs related to the tools directory. whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Feb 4, 2017
Copy link
Contributor

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.

Copy link
Member

@joyeecheung joyeecheung left a 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off

Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off

Copy link
Contributor

@thefourtheye thefourtheye left a 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.

Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.

@not-an-aardvark
Copy link
Contributor

I am not sure how the linter missed the indentation problems.

Currently, it does not check the indentation of comments. This is planned to change in the next major release.

Copy link
Contributor

@cjihrig cjihrig left a 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.

@silverwind
Copy link
Contributor

I personally find it easier to visually parse code with the else branch intact, even if it's not strictly necessary.

lib/url.js Outdated
Copy link
Contributor

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.

Copy link
Member Author

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.

@joyeecheung
Copy link
Member

Also if we were using const or let in the else-branch before, be careful there can be TDZs...

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.
@Trott
Copy link
Member Author

Trott commented Feb 21, 2017

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.

@Trott Trott closed this Feb 21, 2017
@sam-github
Copy link
Contributor

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.

@Trott Trott deleted the no-else-return branch January 13, 2022 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmark Issues and PRs related to the benchmark subsystem. lib / src Issues and PRs related to general changes in the lib or src directory. test Issues and PRs related to the tests. tools Issues and PRs related to the tools directory. whatwg-url Issues and PRs related to the WHATWG URL implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants