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 request: no-useless-return

See original GitHub issue

Please describe what the rule should do:

Forbid return; at the end of a function, as it is redundant. It’s often a leftover from refactoring some callback code.

What category of rule is this? (place an “X” next to just one item)

[x] Enforces code style [ ] Warns about a potential error [ ] Suggests an alternate way of doing something [ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

The common case:

function foo() {
  bar();
  return; // pointless!
}

Generalising to conditionals at the end of a function:

function foo() {
  if (something) {
    bar();
    return; // redundant
  } else if (otherThing) {
    baz();
    return; // redundant
  } else {
    boz();
  }
  // Nothing here, so the arms of the conditional are the last thing
  // in the function.
}

Examples where we wouldn’t warn:

function foo() {
  bar();
  return 1;
}

Why should this rule be included in ESLint (instead of a plugin)?

It’s totally generic and applicable to all JS developers I think.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
mysticateacommented, Oct 23, 2016

I also can implement this since I like code path analysis. 😄

1reaction
platinumazurecommented, Oct 5, 2016

Sounds great! I’ll endorse this. With two more endorsements and a champion, we can accept this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-useless-return - ESLint - Pluggable JavaScript Linter
A return; statement with nothing after it is redundant, and has no effect on the runtime behavior of a function. This can be...
Read more >
Disallow redundant return statements (no-useless-return)
A return; statement with nothing after it is redundant, and has no effect on the runtime behavior of a function. This can be...
Read more >
no-useless-return - Rules - ESLint - Pluggable JavaScript linter
A return; statement with nothing after it is redundant, and has no effect on the runtime behavior of a function.
Read more >
Disallow redundant return statements (no-useless-return) #694
A return statement with nothing after it is redundant, and has no effect on the runtime behavior of a function. This can be...
Read more >
No-useless-return - ESLint - W3cubDocs
A return; statement with nothing after it is redundant, and has no effect on the runtime behavior of a function. This can be...
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