diff --git a/CHANGELOG.md b/CHANGELOG.md index 358357a04a2..f6dad9e4020 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * [#6946](https://github.com/rubocop-hq/rubocop/pull/6946): Allow `Rails/ReflectionClassName` to use string interpolation for `class_name`. ([@r7kamura][]) * [#6778](https://github.com/rubocop-hq/rubocop/issues/6778): Fix a false positive in `Style/HashSyntax` cop when a hash key is an interpolated string and EnforcedStyle is ruby19_no_mixed_keys. ([@tatsuyafw][]) * [#6902](https://github.com/rubocop-hq/rubocop/issues/6902): Fix a bug where `Naming/RescuedExceptionsVariableName` would handle an only first rescue for multiple rescue groups. ([@tatsuyafw][]) +* [#6860](https://github.com/rubocop-hq/rubocop/issues/6860): Prevent auto-correct conflict of `Style/InverseMethods` and `Style/Not`. ([@hoshinotsuyoshi][]) ### Changes diff --git a/lib/rubocop/cop/style/inverse_methods.rb b/lib/rubocop/cop/style/inverse_methods.rb index 002c575a992..5aa8ff833fd 100644 --- a/lib/rubocop/cop/style/inverse_methods.rb +++ b/lib/rubocop/cop/style/inverse_methods.rb @@ -37,6 +37,10 @@ class InverseMethods < Cop NEGATED_EQUALITY_METHODS = %i[!= !~].freeze CAMEL_CASE = /[A-Z]+[a-z]+/.freeze + def self.autocorrect_incompatible_with + [Style::Not] + end + def_node_matcher :inverse_candidate?, <<-PATTERN { (send $(send $(...) $_ $...) :!) diff --git a/spec/rubocop/cli/cli_autocorrect_spec.rb b/spec/rubocop/cli/cli_autocorrect_spec.rb index 2a6407fea74..ed2ddaea344 100644 --- a/spec/rubocop/cli/cli_autocorrect_spec.rb +++ b/spec/rubocop/cli/cli_autocorrect_spec.rb @@ -452,6 +452,21 @@ def verify_section expect(IO.read('example.rb')).to eq(corrected) end + it 'corrects Style/InverseMethods and Style/Not offenses' do + source = <<-'RUBY'.strip_indent + x.select {|y| not y.z } + RUBY + create_file('example.rb', source) + expect(cli.run([ + '--auto-correct', + '--only', 'Style/InverseMethods,Style/Not' + ])).to eq(0) + corrected = <<-'RUBY'.strip_indent + x.reject {|y| y.z } + RUBY + expect(IO.read('example.rb')).to eq(corrected) + end + describe 'caching' do let(:cache) do instance_double(RuboCop::ResultCache, 'valid?' => true,