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

[Fix #1362] Fix false positives for Rails/EnumSyntax #1363

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_false_positives_for_rails_enum_syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1362](https://github.com/rubocop/rubocop-rails/issues/1362): Fix false positives for `Rails/EnumSyntax` when using Ruby 2.7. ([@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 @@ -17,8 +17,10 @@ module Rails
#
class EnumSyntax < Base
extend AutoCorrector
extend TargetRubyVersion
extend TargetRailsVersion

minimum_target_ruby_version 3.0
minimum_target_rails_version 7.0

MSG = 'Enum defined with keyword arguments in `%<enum>s` enum declaration. Use positional arguments instead.'
Expand Down
14 changes: 13 additions & 1 deletion spec/rubocop/cop/rails/enum_syntax_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Rails::EnumSyntax, :config do
context 'Rails >= 7.0', :rails70 do
context 'Rails >= 7.0 and Ruby >= 3.0', :rails70, :ruby30 do
context 'when keyword arguments are used' do
context 'with %i[] syntax' do
it 'registers an offense' do
Expand Down Expand Up @@ -148,6 +148,18 @@
end
end

context 'Rails >= 7.0 and Ruby <= 2.7', :rails70, :ruby27, unsupported_on: :prism do
context 'when keyword arguments are used' do
context 'with %i[] syntax' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
enum status: %i[active archived], _prefix: true
RUBY
end
end
end
end

context 'Rails <= 6.1', :rails61 do
context 'when keyword arguments are used' do
context 'with %i[] syntax' do
Expand Down