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

Add new Lint/DuplicateElsifCondition cop #8293

Merged
merged 1 commit into from Jul 9, 2020

Conversation

fatkodima
Copy link
Contributor

@fatkodima fatkodima commented Jul 9, 2020

This cop checks for duplicated conditions in elsifs. This is almost definitely a programmer mistake due to copy-paste, refactoring, etc.

# bad
if x == 1
  do_something
elsif x == 1
  do_something_else
end

# good
if x == 1
  do_something
elsif x == 2
  do_something_else
end

This cop is in addition to existing Lint/DuplicateCaseCondition.

@bbatsov
Copy link
Collaborator

bbatsov commented Jul 9, 2020

Seems to me this should be a Lint cop.

@bbatsov
Copy link
Collaborator

bbatsov commented Jul 9, 2020

Seems it's a Style cop only in the PR description and the commit message. :-)

@fatkodima fatkodima force-pushed the duplicate-elsif-condition-cop branch from dea8827 to 09dec60 Compare July 9, 2020 21:29
@fatkodima fatkodima changed the title Add new Style/DuplicateElsifCondition cop Add new Lint/DuplicateElsifCondition cop Jul 9, 2020
@fatkodima
Copy link
Contributor Author

Haha, yes, it is a bad copy-paste 😄

@bbatsov bbatsov merged commit 8fafbaf into rubocop:master Jul 9, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Jul 9, 2020

Thanks!

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 this pull request may close these issues.

None yet

2 participants