Skip to content

Commit

Permalink
[Fix rubocop#790] Make Style/HashExcept aware of TargetRubyVersion:…
Browse files Browse the repository at this point in the history
… 2.x

Fixes rubocop#790.

This PR makes `Style/HashExcept` aware of TargetRubyVersion: 2.x
because Rails has `Hash#except`.
So Ruby version is irrelevant when used in Rails.
  • Loading branch information
koic committed Sep 22, 2022
1 parent 7e37f65 commit 8a61964
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#790](https://github.com/rubocop/rubocop-rails/issues/790): Make `Style/HashExcept` aware of TargetRubyVersion: 2.x because Rails has `Hash#except`. ([@koic][])
2 changes: 2 additions & 0 deletions lib/rubocop-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

require_relative 'rubocop/cop/rails_cops'

RuboCop::Cop::Style::HashExcept.minimum_target_ruby_version(2.0)

RuboCop::Cop::Style::MethodCallWithArgsParentheses.singleton_class.prepend(
Module.new do
def autocorrect_incompatible_with
Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/cli/autocorrect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,20 @@
self&.bar&.baz
RUBY
end

it 'corrects `Style/HashExcept` with `TargetRubyVersion: 2.0`' do
create_file('.rubocop.yml', <<~YAML)
AllCops:
TargetRubyVersion: 2.0
YAML

create_file('example.rb', <<~RUBY)
{foo: 1, bar: 2, baz: 3}.reject {|k, v| k == :bar }
RUBY

expect(cli.run(['-a', '--only', 'Style/HashExcept'])).to eq(0)
expect(File.read('example.rb')).to eq(<<~RUBY)
{foo: 1, bar: 2, baz: 3}.except(:bar)
RUBY
end
end

0 comments on commit 8a61964

Please sign in to comment.