Skip to content

Commit

Permalink
Merge pull request #9937 from jonas054/9922_fix_DoubleCopDisableDirec…
Browse files Browse the repository at this point in the history
…tive

[Fix #9922] Replace extra disable directives with comma
  • Loading branch information
koic committed Jul 16, 2021
2 parents 117511e + 49b3999 commit 82d7122
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
@@ -0,0 +1 @@
* [#9922](https://github.com/rubocop/rubocop/issues/9922): Make better auto-corrections in `Style/DoubleCopDisableDirective`. ([@jonas054][])
8 changes: 1 addition & 7 deletions lib/rubocop/cop/style/double_cop_disable_directive.rb
Expand Up @@ -36,13 +36,7 @@ def on_new_investigation
next unless comment.text.scan(/# rubocop:(?:disable|todo)/).size > 1

add_offense(comment) do |corrector|
prefix = if comment.text.start_with?('# rubocop:disable')
'# rubocop:disable'
else
'# rubocop:todo'
end

corrector.replace(comment, comment.text[/#{prefix} \S+/])
corrector.replace(comment, comment.text.gsub(%r{ # rubocop:(disable|todo)}, ','))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cli/disable_uncorrectable_spec.rb
Expand Up @@ -177,7 +177,7 @@ def choose_move(who_to_move)
class Chess
# rubocop:todo Metrics/MethodLength
# rubocop:todo Metrics/AbcSize
def choose_move(who_to_move) # rubocop:todo Metrics/CyclomaticComplexity
def choose_move(who_to_move) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
legal_moves = all_legal_moves_that_dont_put_me_in_check(who_to_move)
return nil if legal_moves.empty?
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/style/double_cop_disable_directive_spec.rb
Expand Up @@ -9,7 +9,7 @@ def choose_move(who_to_move) # rubocop:disable Metrics/CyclomaticComplexity # ru
RUBY

expect_correction(<<~RUBY)
def choose_move(who_to_move) # rubocop:disable Metrics/CyclomaticComplexity
def choose_move(who_to_move) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
end
RUBY
end
Expand All @@ -22,7 +22,7 @@ def choose_move(who_to_move) # rubocop:todo Metrics/CyclomaticComplexity # ruboc
RUBY

expect_correction(<<~RUBY)
def choose_move(who_to_move) # rubocop:todo Metrics/CyclomaticComplexity
def choose_move(who_to_move) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
end
RUBY
end
Expand Down

0 comments on commit 82d7122

Please sign in to comment.