-
Notifications
You must be signed in to change notification settings - Fork 0
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 for enum starting value #57
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entry in the changelog should be under # main
This reverts commit 3ccf7e9. :q!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had some error when trying it our project. Sometimes, the enum value is a constant, example
undefined method `value' for s(:const, nil, :SomeConstant):RuboCop::AST::ConstNode
/Users/jfbastien/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/bundler/gems/rubocop-petal-f6edf46de432/lib/rubocop/cop/rails/enum_starting_value.rb:35:in `block in start_with_zero?'
/Users/jfbastien/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/bundler/gems/rubocop-petal-f6edf46de432/lib/rubocop/cop/rails/enum_starting_value.rb:34:in `any?'
/Users/jfbastien/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/bundler/gems/rubocop-petal-f6edf46de432/lib/rubocop/cop/rails/enum_starting_value.rb:34:in `start_with_zero?'
/Users/jfbastien/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/bundler/gems/rubocop-petal-f6edf46de432/lib/rubocop/cop/rails/enum_starting_value.rb:30:in `on_send'
it 'expects an offense' do | ||
expect_offense(<<~RUBY) | ||
class MyModel | ||
enum my_enum: {state1: 0, state2: 2} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may sound weird, but can you add a specs to that check that no value should be 0.
Like
enum my_enum: {state1: 1, state2: 0}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks
It is in response to this issue: #56