Skip to content

Commit

Permalink
Merge pull request #1378 from koic/fix_an_error_for_rails_enum_syntax
Browse files Browse the repository at this point in the history
[Fix #1377] Fix an error for `Rails/EnumSyntax`
  • Loading branch information
koic authored Oct 18, 2024
2 parents ec31d1b + 94a8370 commit f66b8f7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_rails_enum_syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1377](https://github.com/rubocop/rubocop-rails/issues/1377): Fix an error for `Rails/EnumSyntax` when positional arguments are used and options are not passed as keyword arguments. ([@koic][])
2 changes: 2 additions & 0 deletions lib/rubocop/cop/rails/enum_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def enum_name(elem)
end

def option_key?(pair)
return false unless pair.respond_to?(:key)

UNDERSCORED_OPTION_NAMES.include?(pair.key.source)
end

Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rails/enum_syntax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@
expect_no_offenses('enum')
end
end

context 'when positional arguments are used and options are not passed as keyword arguments' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
enum :status, { active: 0, archived: 1 }, prefix
RUBY
end
end
end

context 'Rails >= 7.0 and Ruby <= 2.7', :rails70, :ruby27, unsupported_on: :prism do
Expand Down

0 comments on commit f66b8f7

Please sign in to comment.