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

Rails/EnumSyntax crash when the 3rd argument is not kwargs #1377

Closed
Tietew opened this issue Oct 18, 2024 · 0 comments · Fixed by #1378
Closed

Rails/EnumSyntax crash when the 3rd argument is not kwargs #1377

Tietew opened this issue Oct 18, 2024 · 0 comments · Fixed by #1378
Labels
bug Something isn't working

Comments

@Tietew
Copy link
Contributor

Tietew commented Oct 18, 2024

Expected behavior

rubocop works with no errors.

Actual behavior

rubocop reports Rails/EnumSyntax crashes:

$ bundle exec rubocop -d
(snip)
An error occurred while Rails/EnumSyntax cop was inspecting ***.
undefined method `key' for nil
.../rubocop-rails-2.26.2/lib/rubocop/cop/rails/enum_syntax.rb:109:in `option_key?'
.../rubocop-rails-2.26.2/lib/rubocop/cop/rails/enum_syntax.rb:62:in `block (2 levels) in check_enum_options'
.../rubocop-rails-2.26.2/lib/rubocop/cop/rails/enum_syntax.rb:61:in `each'
.../rubocop-rails-2.26.2/lib/rubocop/cop/rails/enum_syntax.rb:61:in `block in check_enum_options'
.../rubocop-rails-2.26.2/lib/rubocop/cop/rails/enum_syntax.rb:48:in `enum_with_options?'
.../rubocop-rails-2.26.2/lib/rubocop/cop/rails/enum_syntax.rb:60:in `check_enum_options'
.../rubocop-rails-2.26.2/lib/rubocop/cop/rails/enum_syntax.rb:44:in `on_send'
(snip)

Steps to reproduce the problem

Inspect following code:

class User < ApplicationRecord
  enum :card, { clow: 1 }, prefix
end

Note: the 3rd argument prefix is a typo for prefix: true.

RuboCop version

1.67.0 (using Parser 3.3.5.0, rubocop-ast 1.32.3, analyzing as Ruby 3.3, running on ruby 3.3.5) [x86_64-linux]
  - rubocop-capybara 2.21.0
  - rubocop-factory_bot 2.26.1
  - rubocop-performance 1.22.1
  - rubocop-rails 2.26.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 3.1.0
  - rubocop-rspec_rails 2.30.0
@koic koic added the bug Something isn't working label Oct 18, 2024
koic added a commit to koic/rubocop-rails that referenced this issue Oct 18, 2024
Fixes rubocop#1377

This PR fixes an error for `Rails/EnumSyntax`
when positional arguments are used and options are not passed as keyword arguments.
koic added a commit to koic/rubocop-rails that referenced this issue Oct 18, 2024
Fixes rubocop#1377

This PR fixes an error for `Rails/EnumSyntax`
when positional arguments are used and options are not passed as keyword arguments.
@koic koic closed this as completed in 94a8370 Oct 18, 2024
koic added a commit that referenced this issue Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants