-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Cop idea: redundant if-else statement #11945
Labels
Comments
Maybe one-liner? my_field = Time.now.utc if(unless) condition? If the last def some_meth(my_field)
return Time.now.utc if(unless) condition
my_field
end |
I think that's what Style/RedundantSelfAssignmentBranch is for. For example, this: foo = cond? ? foo : bar gets flagged with foo = bar unless cond? However, if the branch is an expression, the cop doesn't detect it 🤔 foo = cond? ? foo : Time.now # no offense |
8 tasks
koic
added a commit
to koic/rubocop
that referenced
this issue
Jun 14, 2023
…gnmentBranch` Fixes rubocop#11945. This PR fixes a false negative for `Style/RedundantSelfAssignmentBranch` when using method chaining or arguments in ternary branch.
koic
added a commit
that referenced
this issue
Jun 15, 2023
…dundant_self_assignment_branch [Fix #11945] Fix a false negative for `Style/RedundantSelfAssignmentBranch`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
I have the code samples:
a1)
a2)
b1)
b2)
Rubocop has not detected any offenses.
Describe the solution you'd like
I expected to have the following code samples:
a)
b)
The text was updated successfully, but these errors were encountered: