Skip to content

Commit

Permalink
[Fix #1045] Fix an incorrect autocorrect for Rails/NegateInclude
Browse files Browse the repository at this point in the history
Fixes #1045.

This PR fixes an incorrect autocorrect for `Rails/NegateInclude`
when using `Style/InverseMethods`'s autocorrection together.
  • Loading branch information
koic committed Aug 16, 2023
1 parent 34376e0 commit 93ee728
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1045](https://github.com/rubocop/rubocop-rails/issues/1045): Fix an incorrect autocorrect for `Rails/NegateInclude` when using `Style/InverseMethods`'s autocorrection together. ([@koic][])
8 changes: 8 additions & 0 deletions lib/rubocop-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@

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

RuboCop::Cop::Style::InverseMethods.singleton_class.prepend(
Module.new do
def autocorrect_incompatible_with
super.push(RuboCop::Cop::Rails::NegateInclude)
end
end
)

RuboCop::Cop::Style::MethodCallWithArgsParentheses.singleton_class.prepend(
Module.new do
def autocorrect_incompatible_with
Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cli/autocorrect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
RUBY
end

it 'corrects `Rails/NegateInclude,` with `Style/InverseMethods`' do
create_file('example.rb', <<~RUBY)
array.select { |item| !do_something.include?(item) }
RUBY

expect(cli.run(['-A', '--only', 'Rails/NegateInclude,Style/InverseMethods'])).to eq(0)
expect(File.read('example.rb')).to eq(<<~RUBY)
array.reject { |item| do_something.include?(item) }
RUBY
end

it 'corrects `Rails/SafeNavigation` with `Style/RedundantSelf`' do
create_file('.rubocop.yml', <<~YAML)
Rails/SafeNavigation:
Expand Down

0 comments on commit 93ee728

Please sign in to comment.