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

Comments

3 participants
@feross
Copy link
Member

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 the enhancement label Nov 22, 2016

@feross feross added this to the standard v9 milestone Nov 22, 2016

@yoshuawuyts

This comment has been minimized.

Copy link
Contributor

commented Nov 22, 2016

Yup, sounds good

On Tue, Nov 22, 2016 at 10:18 PM Feross Aboukhadijeh <
notifications@github.com> 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

This comment has been minimized.

Copy link
Member

commented Nov 23, 2016

What about early exits?
Would:

if (!param) return

return 2 + 3

Still work?

Or

if (cond) {
  foo()
  return
}

bar()
@feross

This comment has been minimized.

Copy link
Member Author

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

This comment has been minimized.

Copy link
Member

commented Nov 23, 2016

ACK then

feross added a commit to standard/eslint-config-standard that referenced this issue Feb 9, 2017

@feross

This comment has been minimized.

Copy link
Member Author

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 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.
You can’t perform that action at this time.