Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support auto-correction comments at rubocop v1.26.0 #577

Merged
merged 1 commit into from Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rubocop_challenger/rubocop/rule.rb
Expand Up @@ -27,7 +27,8 @@ def <=>(other)
end

def auto_correctable?
contents.include?('# Cop supports --auto-correct')
contents.include?('# Cop supports --auto-correct') || # for rubocop < v1.26.0
contents.match?(/# This cop supports (un)?safe auto-correction/) # for rubocop >= v1.26.0
end

def rubydoc_url
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/.expected_rubocop_todo.yml
Expand Up @@ -17,13 +17,13 @@ Style/Documentation:
- 'lib/rubocop_challenger/rubocop/todo_reader.rb'

# Offense count: 2
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
Style/ExpandPathArguments:
Exclude:
- 'rubocop_challenger.gemspec'

# Offense count: 13
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: when_needed, always, never
Style/FrozenStringLiteralComment:
Expand Down
6 changes: 3 additions & 3 deletions spec/fixtures/.rubocop_todo.yml
Expand Up @@ -7,7 +7,7 @@
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Expand All @@ -25,13 +25,13 @@ Style/Documentation:
- 'lib/rubocop_challenger/rubocop/todo_reader.rb'

# Offense count: 2
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
Style/ExpandPathArguments:
Exclude:
- 'rubocop_challenger.gemspec'

# Offense count: 13
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: when_needed, always, never
Style/FrozenStringLiteralComment:
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/rubocop_challenger/github/pr_template_spec.rb
Expand Up @@ -8,7 +8,7 @@

let(:rule) { RubocopChallenger::Rubocop::Rule.new(<<~CONTENTS) }
# Offense count: 2
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
Style/Alias:
Enabled: false
CONTENTS
Expand Down
46 changes: 35 additions & 11 deletions spec/lib/rubocop_challenger/rubocop/rule_spec.rb
Expand Up @@ -19,7 +19,7 @@
describe '#offense_count' do
let(:rule) { described_class.new(<<~CONTENTS) }
# Offense count: 27
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Expand Down Expand Up @@ -59,7 +59,7 @@

let(:rule) { described_class.new(<<~CONTENTS) }
# Offense count: 2
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax:
Expand All @@ -70,7 +70,7 @@
context 'when the rule title is same to other one' do
let(:other) { described_class.new(<<~CONTENTS) }
# Offense count: 1
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
Style/HashSyntax:
Exclude:
- 'rubocop_challenger.gemspec'
Expand All @@ -82,7 +82,7 @@
context 'when the rule title is different to other one' do
let(:other) { described_class.new(<<~CONTENTS) }
# Offense count: 1
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
Layout/LeadingBlankLines:
Exclude:
- 'rubocop_challenger.gemspec'
Expand All @@ -97,7 +97,7 @@

let(:rule) { described_class.new(<<~CONTENTS) }
# Offense count: 2
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax:
Expand All @@ -108,7 +108,7 @@
context 'when the rule offense count greater than other one' do
let(:other) { described_class.new(<<~CONTENTS) }
# Offense count: 1
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
Layout/LeadingBlankLines:
Exclude:
- 'rubocop_challenger.gemspec'
Expand All @@ -120,7 +120,7 @@
context 'when the rule offense count is equal to other one' do
let(:other) { described_class.new(<<~CONTENTS) }
# Offense count: 2
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
Style/ExpandPathArguments:
Exclude:
- 'rubocop_challenger.gemspec'
Expand All @@ -146,7 +146,7 @@
describe '#auto_correctable?' do
subject { rule.auto_correctable? }

context 'when the rule supports auto correct' do
context 'with auto-correction comment: Cop supports --auto-correct' do
let(:rule) { described_class.new(<<~CONTENTS) }
# Offense count: 1
# Cop supports --auto-correct.
Expand All @@ -158,7 +158,31 @@
it { is_expected.to be_truthy }
end

context 'when the rule does not support auto correct' do
context 'with auto-correction comment: This cop supports safe auto-correction' do
let(:rule) { described_class.new(<<~CONTENTS) }
# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
Performance/StringReplacement:
Exclude:
- 'lib/rubocop_challenger.rb'
CONTENTS

it { is_expected.to be_truthy }
end

context 'with auto-correction comment: This cop supports unsafe auto-correction' do
let(:rule) { described_class.new(<<~CONTENTS) }
# Offense count: 1
# This cop supports unsafe auto-correction (--auto-correct-all).
Performance/StringReplacement:
Exclude:
- 'lib/rubocop_challenger.rb'
CONTENTS

it { is_expected.to be_truthy }
end

context 'without auto-correction comment' do
let(:rule) { described_class.new(<<~CONTENTS) }
# Offense count: 1
Metrics/AbcSize:
Expand All @@ -173,7 +197,7 @@
context 'when the rule is included in the rubocop gem' do
let(:rule) { described_class.new(<<~CONTENTS) }
# Offense count: 1
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
Style/RedundantSelf:
Exclude:
- 'lib/rubocop_challenger/rubocop/rule.rb'
Expand All @@ -188,7 +212,7 @@
context 'when the rule is included in the rubocop-rspec gem' do
let(:rule) { described_class.new(<<~CONTENTS) }
# Offense count: 1
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: CustomTransform, IgnoredWords.
RSpec/ExampleWording:
Exclude:
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/rubocop_challenger/rubocop/todo_reader_spec.rb
Expand Up @@ -8,7 +8,7 @@
let(:autocorrectable_rule_which_offence_count_is_1) do
RubocopChallenger::Rubocop::Rule.new(<<~CONTENTS)
# Offense count: 1
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Expand All @@ -20,7 +20,7 @@
let(:autocorrectable_rule_which_offence_count_is_2) do
RubocopChallenger::Rubocop::Rule.new(<<~CONTENTS)
# Offense count: 2
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
Style/ExpandPathArguments:
Exclude:
- 'rubocop_challenger.gemspec'
Expand All @@ -30,7 +30,7 @@
let(:autocorrectable_rule_which_offence_count_is_13) do
RubocopChallenger::Rubocop::Rule.new(<<~CONTENTS)
# Offense count: 13
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: when_needed, always, never
Style/FrozenStringLiteralComment:
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/rubocop_challenger/rubocop/todo_writer_spec.rb
Expand Up @@ -11,7 +11,7 @@
let(:expected) { File.read('spec/fixtures/.expected_rubocop_todo.yml') }
let(:rule) { RubocopChallenger::Rubocop::Rule.new(<<~CONTENTS) }
# Offense count: 1
# Cop supports --auto-correct.
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Expand Down