Skip to content

Commit 8a61964

Browse files
committed
[Fix rubocop#790] Make Style/HashExcept aware of TargetRubyVersion: 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.
1 parent 7e37f65 commit 8a61964

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#790](https://github.com/rubocop/rubocop-rails/issues/790): Make `Style/HashExcept` aware of TargetRubyVersion: 2.x because Rails has `Hash#except`. ([@koic][])

lib/rubocop-rails.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
require_relative 'rubocop/cop/rails_cops'
1616

17+
RuboCop::Cop::Style::HashExcept.minimum_target_ruby_version(2.0)
18+
1719
RuboCop::Cop::Style::MethodCallWithArgsParentheses.singleton_class.prepend(
1820
Module.new do
1921
def autocorrect_incompatible_with

spec/rubocop/cli/autocorrect_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,20 @@
4040
self&.bar&.baz
4141
RUBY
4242
end
43+
44+
it 'corrects `Style/HashExcept` with `TargetRubyVersion: 2.0`' do
45+
create_file('.rubocop.yml', <<~YAML)
46+
AllCops:
47+
TargetRubyVersion: 2.0
48+
YAML
49+
50+
create_file('example.rb', <<~RUBY)
51+
{foo: 1, bar: 2, baz: 3}.reject {|k, v| k == :bar }
52+
RUBY
53+
54+
expect(cli.run(['-a', '--only', 'Style/HashExcept'])).to eq(0)
55+
expect(File.read('example.rb')).to eq(<<~RUBY)
56+
{foo: 1, bar: 2, baz: 3}.except(:bar)
57+
RUBY
58+
end
4359
end

0 commit comments

Comments
 (0)