Skip to content

Commit 7e37f65

Browse files
authored
Merge pull request rubocop#784 from koic/fix_an_incorrect_autocorrect_for_rails_eager_evaluation_log_message
[Fix rubocop#782] Fix an incorrect autocorrect for `Rails/EagerEvaluationLogMessage`
2 parents 57c2fd4 + f8bd176 commit 7e37f65

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#782](https://github.com/rubocop/rubocop-rails/issues/782): Fix an incorrect autocorrect for `Rails/EagerEvaluationLogMessage` when using `Style/MethodCallWithArgsParentheses`'s autocorrection together. ([@koic][])

lib/rubocop-rails.rb

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

1515
require_relative 'rubocop/cop/rails_cops'
1616

17+
RuboCop::Cop::Style::MethodCallWithArgsParentheses.singleton_class.prepend(
18+
Module.new do
19+
def autocorrect_incompatible_with
20+
super.push(RuboCop::Cop::Rails::EagerEvaluationLogMessage)
21+
end
22+
end
23+
)
24+
1725
RuboCop::Cop::Style::RedundantSelf.singleton_class.prepend(
1826
Module.new do
1927
def autocorrect_incompatible_with

lib/rubocop/cop/rails/eager_evaluation_log_message.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class EagerEvaluationLogMessage < Base
3737
)
3838
PATTERN
3939

40+
def self.autocorrect_incompatible_with
41+
[Style::MethodCallWithArgsParentheses]
42+
end
43+
4044
def on_send(node)
4145
return if node.parent&.block_type?
4246

spec/rubocop/cli/autocorrect_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99
RuboCop::ConfigLoader.default_configuration.for_all_cops['SuggestExtensions'] = false
1010
end
1111

12+
it 'corrects `Rails/EagerEvaluationLogMessage,` with `Style/MethodCallWithArgsParentheses`' do
13+
create_file('.rubocop.yml', <<~YAML)
14+
Rails/SafeNavigation:
15+
ConvertTry: true
16+
YAML
17+
18+
create_file('example.rb', <<~'RUBY')
19+
Rails.logger.debug "foo#{bar}"
20+
RUBY
21+
22+
expect(cli.run(['-a', '--only', 'Rails/EagerEvaluationLogMessage,Style/MethodCallWithArgsParentheses'])).to eq(0)
23+
expect(File.read('example.rb')).to eq(<<~'RUBY')
24+
Rails.logger.debug { "foo#{bar}" }
25+
RUBY
26+
end
27+
1228
it 'corrects `Rails/SafeNavigation` with `Style/RedundantSelf`' do
1329
create_file('.rubocop.yml', <<~YAML)
1430
Rails/SafeNavigation:

0 commit comments

Comments
 (0)