Skip to content

Commit f66b8f7

Browse files
authored
Merge pull request #1378 from koic/fix_an_error_for_rails_enum_syntax
[Fix #1377] Fix an error for `Rails/EnumSyntax`
2 parents ec31d1b + 94a8370 commit f66b8f7

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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][])

lib/rubocop/cop/rails/enum_syntax.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def enum_name(elem)
106106
end
107107

108108
def option_key?(pair)
109+
return false unless pair.respond_to?(:key)
110+
109111
UNDERSCORED_OPTION_NAMES.include?(pair.key.source)
110112
end
111113

spec/rubocop/cop/rails/enum_syntax_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@
146146
expect_no_offenses('enum')
147147
end
148148
end
149+
150+
context 'when positional arguments are used and options are not passed as keyword arguments' do
151+
it 'does not register an offense' do
152+
expect_no_offenses(<<~RUBY)
153+
enum :status, { active: 0, archived: 1 }, prefix
154+
RUBY
155+
end
156+
end
149157
end
150158

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

0 commit comments

Comments
 (0)