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

New Cop: Explicit enum definition #78

Closed
pocke opened this issue Jun 24, 2019 · 1 comment · Fixed by #94 or #95
Closed

New Cop: Explicit enum definition #78

pocke opened this issue Jun 24, 2019 · 1 comment · Fixed by #94 or #95
Labels
feature request Request for new functionality

Comments

@pocke
Copy link
Contributor

pocke commented Jun 24, 2019

Is your feature request related to a problem? Please describe.

Enum has two definition styles.

class Item
  enum category: %i[bar baz]
  enum category: {
    bar: 0,
    baz: 1,
  }
end

They have the same meaning. But I like the latter style.
If I add foo categorybeforebar, the enum breaks! Because the order will be changed by adding foo`.

class Item
  enum category: %i[foo bar baz]
end

We can avoid the bug by using the explicit style.

Describe the solution you'd like

Add a cop to detect enum with an array.

Describe alternatives you've considered

Probably we can make the cop configurable to enforce the opposite style.
Personally I think we do not need configurable cop at least the first implementation.

I do not oppose implementing the configuration, but we should mention the risk of the implicit style in the documentation.

Additional context

none

@pocke pocke added the feature request Request for new functionality label Jun 24, 2019
@Drenmi
Copy link
Contributor

Drenmi commented Jun 24, 2019

+1 for this cop. 🙂

Perhaps HashEnum would be more descriptive?

tejasbubane added a commit to tejasbubane/rails-style-guide that referenced this issue Jul 8, 2019
tejasbubane added a commit to tejasbubane/rails-style-guide that referenced this issue Jul 8, 2019
tejasbubane added a commit to tejasbubane/rails-style-guide that referenced this issue Jul 8, 2019
santib pushed a commit to santib/rubocop-rails that referenced this issue Jul 24, 2019
santib pushed a commit to santib/rubocop-rails that referenced this issue Jul 24, 2019
santib pushed a commit to santib/rubocop-rails that referenced this issue Jul 24, 2019
santib pushed a commit to santib/rubocop-rails that referenced this issue Jul 24, 2019
santib added a commit to santib/rubocop-rails that referenced this issue Jul 24, 2019
santib added a commit to santib/rubocop-rails that referenced this issue Jul 24, 2019
brunvez pushed a commit to santib/rubocop-rails that referenced this issue Jul 24, 2019
brunvez pushed a commit to santib/rubocop-rails that referenced this issue Jul 24, 2019
santib pushed a commit to santib/rubocop-rails that referenced this issue Jul 25, 2019
santib pushed a commit to santib/rubocop-rails that referenced this issue Jul 25, 2019
santib added a commit to santib/rubocop-rails that referenced this issue Jul 25, 2019
@koic koic closed this as completed in #94 Jul 25, 2019
koic added a commit that referenced this issue Jul 25, 2019
santib added a commit to santib/rubocop-rails that referenced this issue Jul 25, 2019
santib added a commit to santib/rubocop-rails that referenced this issue Jul 25, 2019
santib added a commit to santib/rubocop-rails that referenced this issue Jul 25, 2019
santib added a commit to santib/rubocop-rails that referenced this issue Jul 26, 2019
santib added a commit to santib/rubocop-rails that referenced this issue Jul 26, 2019
santib added a commit to santib/rubocop-rails that referenced this issue Jul 26, 2019
koic added a commit that referenced this issue Jul 29, 2019
Worldboss-tech added a commit to Worldboss-tech/rails-style-guide that referenced this issue Aug 15, 2023
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
2 participants