Skip to content
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

Disallow redundant return statements (no-useless-return) #694

Closed
feross opened this issue Nov 22, 2016 · 5 comments
Closed

Disallow redundant return statements (no-useless-return) #694

feross opened this issue Nov 22, 2016 · 5 comments

Comments

@feross
Copy link
Member

feross commented Nov 22, 2016

A return statement with nothing after it is redundant, and has no effect on the runtime behavior of a function. This can be confusing, so it’s better to disallow these redundant statements.

http://eslint.org/docs/rules/no-useless-return

@feross feross added this to the standard v9 milestone Nov 22, 2016
@yoshuawuyts
Copy link
Contributor

Yup, sounds good

On Tue, Nov 22, 2016 at 10:18 PM Feross Aboukhadijeh <
[email protected]> wrote:

A return statement with nothing after it is redundant, and has no effect
on the runtime behavior of a function. This can be confusing, so it’s
better to disallow these redundant statements.

http://eslint.org/docs/rules/no-useless-return


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#694, or mute the thread
https://github.com/notifications/unsubscribe-auth/ACWleky_IxPMCeyVGJlZdtWdJdXdxi34ks5rA1wMgaJpZM4K5861
.

@dcousens
Copy link
Member

dcousens commented Nov 23, 2016

What about early exits?
Would:

if (!param) return

return 2 + 3

Still work?

Or

if (cond) {
  foo()
  return
}

bar()

@feross
Copy link
Member Author

feross commented Nov 23, 2016

@dcousens Yep, those will still work. The rule only prevents useless returns like:

function foo () {
  if (cond) {
    console.log('hi')
    return
  }
}

@dcousens
Copy link
Member

ACK then

feross added a commit to standard/eslint-config-standard that referenced this issue Feb 9, 2017
@feross
Copy link
Member Author

feross commented Feb 9, 2017

This will be part of standard v9. The ecosystem impact is 3 repos, with one statement in each requiring modification.

@feross feross closed this as completed Feb 9, 2017
feross added a commit to standard/eslint-config-standard that referenced this issue Feb 9, 2017
@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

3 participants