Skip to content

Commit

Permalink
Fix RuboCop offenses after rebase
Browse files Browse the repository at this point in the history
Rebasing the branch on top of new changes added some offenses.
Refactor to get rid of these.
  • Loading branch information
jonas054 authored and bbatsov committed Jul 16, 2019
1 parent f2f6c95 commit 2738c5d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 42 deletions.
40 changes: 10 additions & 30 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-06-29 13:38:41 +0900 using RuboCop version 0.72.0.
# on 2019-07-14 17:34:07 +0200 using RuboCop version 0.72.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 78
# Offense count: 79
InternalAffairs/NodeDestructuring:
Enabled: false

Expand All @@ -26,7 +26,7 @@ Lint/UnneededCopDisableDirective:
- 'spec/rubocop/cop/lint/multiple_compare_spec.rb'
- 'spec/rubocop/formatter/disabled_config_formatter_spec.rb'

# Offense count: 58
# Offense count: 57
Metrics/AbcSize:
Max: 17

Expand All @@ -35,39 +35,31 @@ Metrics/AbcSize:
Metrics/ClassLength:
Max: 174

# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 7

# Offense count: 218
# Offense count: 219
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 14

# Offense count: 5
# Offense count: 6
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 141

# Offense count: 1
Metrics/PerceivedComplexity:
Max: 8

# Offense count: 7
# Offense count: 10
RSpec/AnyInstance:
Exclude:
- 'spec/rubocop/cli_spec.rb'
- 'spec/rubocop/cop/lint/duplicate_methods_spec.rb'
- 'spec/rubocop/cop/team_spec.rb'
- 'spec/rubocop/target_finder_spec.rb'

# Offense count: 1088
# Offense count: 1106
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Enabled: false

# Offense count: 3334
# Offense count: 3363
# Configuration parameters: Max.
RSpec/ExampleLength:
Enabled: false
Expand All @@ -86,17 +78,11 @@ RSpec/ExpectOutput:
- 'spec/rubocop/result_cache_spec.rb'
- 'spec/rubocop/target_finder_spec.rb'

# Offense count: 461
# Offense count: 467
# Configuration parameters: AggregateFailuresByDefault.
RSpec/MultipleExpectations:
Max: 25

# Offense count: 3
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Exclude:
- 'spec/rubocop/cli/cli_disable_uncorrectable_spec.rb'

# Offense count: 13
RSpec/SubjectStub:
Exclude:
Expand All @@ -105,13 +91,7 @@ RSpec/SubjectStub:
- 'spec/rubocop/formatter/json_formatter_spec.rb'
- 'spec/rubocop/formatter/progress_formatter_spec.rb'

# Offense count: 2
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/rubocop/cop/cop_spec.rb'

# Offense count: 95
# Offense count: 94
# Cop supports --auto-correct.
Style/IfUnlessModifier:
Enabled: false
Expand Down
13 changes: 10 additions & 3 deletions lib/rubocop/cop/cop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,8 @@ def duplicate_location?(location)
end

def correct(node)
return :unsupported unless correctable?
return :uncorrected unless autocorrect?
return :already_corrected if @corrected_nodes.key?(node)
reason = reason_to_not_correct(node)
return reason if reason

@corrected_nodes[node] = true
if support_autocorrect?
Expand All @@ -167,6 +166,14 @@ def correct(node)
:corrected
end

def reason_to_not_correct(node)
return :unsupported unless correctable?
return :uncorrected unless autocorrect?
return :already_corrected if @corrected_nodes.key?(node)

nil
end

def config_to_allow_offenses
Formatter::DisabledConfigFormatter
.config_to_allow_offenses[cop_name] ||= {}
Expand Down
16 changes: 8 additions & 8 deletions spec/rubocop/cli/cli_disable_uncorrectable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
subject(:cli) { described_class.new }

describe '--disable-uncorrectable' do
subject do
let(:exit_code) do
cli
.run(%w[--auto-correct --format emacs --disable-uncorrectable --except Style/FrozenStringLiteralComment --no-display-cop-names])
end

it 'does not disable anything for cops that support autocorrect' do
create_file('example.rb', 'puts 1==2')
expect(subject).to eq(0)
expect(exit_code).to eq(0)
expect($stderr.string).to eq('')
expect($stdout.string)
.to eq("#{abs('example.rb')}:1:7: C: [Corrected] Surrounding " \
"space missing for operator `==`.\n")
expect(IO.read('example.rb')).to eq("puts 1 == 2\n")
expect($stdout.string).to eq(<<-OUTPUT.strip_indent)
#{abs('example.rb')}:1:7: C: [Corrected] Surrounding space missing for operator `==`.
OUTPUT
expect(IO.readlines('example.rb').map(&:chomp)).to eq(['puts 1 == 2'])
end

it 'adds one-line disable statement for one-line offenses' do
create_file('example.rb', ['def is_example',
' true',
'end'])
expect(subject).to eq(0)
expect(exit_code).to eq(0)
expect($stderr.string).to eq('')
expect($stdout.string)
.to eq("#{abs('example.rb')}:1:5: C: [Corrected] Rename `is_example` " \
Expand All @@ -45,7 +45,7 @@
" puts 'line 1'",
" puts 'line 2'",
'end'])
expect(subject).to eq(0)
expect(exit_code).to eq(0)
expect($stderr.string).to eq('')
expect($stdout.string)
.to eq("#{abs('example.rb')}:1:1: C: [Corrected] Method " \
Expand Down
7 changes: 6 additions & 1 deletion spec/rubocop/cop/cop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@
allow(cop).to receive(:disable_uncorrectable?).and_return(true)
end

let(:node) { double(location: double(expression: location)) }
let(:node) do
instance_double(RuboCop::AST::Node,
location: instance_double(Parser::Source::Map,
expression: location,
line: 1))
end

it 'is set to true' do
cop.add_offense(node, location: location, message: 'message')
Expand Down

0 comments on commit 2738c5d

Please sign in to comment.