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

Style/RedundantReturn does not find redundant returns in conditional constructs preceded by other code #7493

Closed
buehmann opened this issue Nov 10, 2019 · 0 comments · Fixed by #7494

Comments

@buehmann
Copy link
Contributor

I noticed that Style/RedundantReturn does not detect the redundant returns in code like

def func
  x = foo
  if x
    return 1
  else
    return 2
  end
end

but only if there is nothing preceding the if/case expression at the end of a method:

def func
  if x
    return 1
  else
    return 2
  end
end
redundant_return.rb:3:5: C: Style/RedundantReturn: Redundant return detected.
    return 1
    ^^^^^^
redundant_return.rb:5:5: C: Style/RedundantReturn: Redundant return detected.
    return 2
    ^^^^^^

(Example taken from #3590 where looking into conditionals was introduced.)

I am going to add a PR fixing this shortly.

buehmann added a commit to buehmann/rubocop that referenced this issue Nov 13, 2019
Generalize specs to really check at end of method
koic added a commit that referenced this issue Nov 14, 2019
[Fix #7493] Detect redundant returns at end of longer methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant