Skip to content

Commit

Permalink
[Fix #1377] Fix an error for Rails/EnumSyntax
Browse files Browse the repository at this point in the history
Fixes #1377

This PR fixes an error for `Rails/EnumSyntax`
when positional arguments are used and options are not passed as keyword arguments.
  • Loading branch information
koic committed Oct 18, 2024
1 parent ec31d1b commit 3ca913d
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, { clow: 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 3ca913d

Please sign in to comment.