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

Cop to check for duplicate scopes #427

Closed
dvandersluis opened this issue Jan 26, 2021 · 2 comments
Closed

Cop to check for duplicate scopes #427

dvandersluis opened this issue Jan 26, 2021 · 2 comments
Labels
feature request Request for new functionality

Comments

@dvandersluis
Copy link
Member

I accidentally wrote the following code:

scope :visible, -> { where(visible: true) }
scope :hidden, -> { where(visible: true) }

It'd be great to detect that the same scope is defined twice, because this most likely is always an error.

Describe the solution you'd like

Register an offense when multiple scopes have identical bodies.

Describe alternatives you've considered

N/A

Additional context

N/A

@koic koic added the feature request Request for new functionality label Jan 26, 2021
natematykiewicz added a commit to natematykiewicz/rubocop-rails that referenced this issue Dec 29, 2021
@natematykiewicz
Copy link
Contributor

I made a PR for this #607

natematykiewicz added a commit to natematykiewicz/rubocop-rails that referenced this issue Feb 14, 2022
natematykiewicz added a commit to natematykiewicz/rubocop-rails that referenced this issue Feb 14, 2022
natematykiewicz added a commit to natematykiewicz/rubocop-rails that referenced this issue Feb 14, 2022
natematykiewicz added a commit to natematykiewicz/rubocop-rails that referenced this issue Feb 14, 2022
natematykiewicz added a commit to natematykiewicz/rubocop-rails that referenced this issue Feb 14, 2022
@koic koic closed this as completed in 4177112 Feb 16, 2022
koic added a commit that referenced this issue Feb 16, 2022
@lulalala
Copy link
Contributor

Hi @natematykiewicz I want to ask you if you think the following use case can be included as part of the DuplicateScope cop:

We accidentally declared the scope with the same name twice, but with different scoping. This has caused some confusion as to why the scope behaves differently.

The case is different to what you are covering. I want to write a cop for such case, but am wondering if making it part of your cop makes sense. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for new functionality
Projects
None yet
Development

No branches or pull requests

4 participants