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.

Rule proposal: Prefer `else`

See original GitHub issue

In following case, use else is more readable than continue and return, but only the else block is small.

Fail

for (const element of array) {
  if (foo) {
    bar();
    continue;
  }

  baz();
}
function a() {
  if (foo) {
    bar();
    return;
  }

  baz();
}

Pass

for (const element of array) {
  if (foo) {
    bar();
  } else {
    baz();
  }
}
function a() {
  if (foo) {
    bar();
  } else {
    baz();
  }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
sindresorhuscommented, Feb 23, 2021

Can you elaborate on why you think it’s more readable? Because I personally find the continue/return version more readable, for the same reasons I prefer early-returns: less nesting.

0reactions
fiskercommented, Mar 14, 2021

I agree this case should do early exit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposed rule: Private Fund Advisers - SEC.gov
We propose to require registered investment advisers to private funds to provide transparency to their investors regarding the full cost of ...
Read more >
Basic components of a proposal | Foundation Relations
Demonstrate your knowledge of the field. Provide convincing evidence that what you are proposing does not duplicate other work. Replication of someone else's...
Read more >
26 Signs You Should Propose ASAP - WeddingWire
It may seem like a small grammatical change, but it's actually huge. ... in-law relationship (and if they haven't met yet, get on...
Read more >
DO NOT Interrupt a Disney Proposal Like This Woman Did
A Guest decided to get down on one knee and propose to his love, ... something wonderful happen for someone else — like...
Read more >
Wikipedia:Perennial proposals
Consensus can change, and some proposals that remained on this page for a long time have finally been proposed in a way that...
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