Skip to content

Commit 5dc42d5

Browse files
authored
Merge pull request #1363 from koic/fix_false_positives_for_rails_enum_syntax
[Fix #1362] Fix false positives for `Rails/EnumSyntax`
2 parents 210f42e + 50fe9a7 commit 5dc42d5

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1362](https://github.com/rubocop/rubocop-rails/issues/1362): Fix false positives for `Rails/EnumSyntax` when using Ruby 2.7. ([@koic][])

lib/rubocop/cop/rails/enum_syntax.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ module Rails
1717
#
1818
class EnumSyntax < Base
1919
extend AutoCorrector
20+
extend TargetRubyVersion
2021
extend TargetRailsVersion
2122

23+
minimum_target_ruby_version 3.0
2224
minimum_target_rails_version 7.0
2325

2426
MSG = 'Enum defined with keyword arguments in `%<enum>s` enum declaration. Use positional arguments instead.'

spec/rubocop/cop/rails/enum_syntax_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
RSpec.describe RuboCop::Cop::Rails::EnumSyntax, :config do
4-
context 'Rails >= 7.0', :rails70 do
4+
context 'Rails >= 7.0 and Ruby >= 3.0', :rails70, :ruby30 do
55
context 'when keyword arguments are used' do
66
context 'with %i[] syntax' do
77
it 'registers an offense' do
@@ -148,6 +148,18 @@
148148
end
149149
end
150150

151+
context 'Rails >= 7.0 and Ruby <= 2.7', :rails70, :ruby27, unsupported_on: :prism do
152+
context 'when keyword arguments are used' do
153+
context 'with %i[] syntax' do
154+
it 'does not register an offense' do
155+
expect_no_offenses(<<~RUBY)
156+
enum status: %i[active archived], _prefix: true
157+
RUBY
158+
end
159+
end
160+
end
161+
end
162+
151163
context 'Rails <= 6.1', :rails61 do
152164
context 'when keyword arguments are used' do
153165
context 'with %i[] syntax' do

0 commit comments

Comments
 (0)