Skip to content

Commit efaf1b0

Browse files
jonas054bbatsov
authored andcommitted
Auto-correct previously undiscovered offenses
The bug fix in the previous commit makes the Layout/RedundantLineBreak cop discover more offenses.
1 parent f94cd24 commit efaf1b0

36 files changed

+81
-185
lines changed

lib/rubocop/cop/bundler/duplicated_gem.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ def on_new_investigation
4646

4747
duplicated_gem_nodes.each do |nodes|
4848
nodes[1..-1].each do |node|
49-
register_offense(
50-
node,
51-
node.first_argument.to_a.first,
52-
nodes.first.first_line
53-
)
49+
register_offense(node, node.first_argument.to_a.first, nodes.first.first_line)
5450
end
5551
end
5652
end

lib/rubocop/cop/gemspec/duplicated_assignment.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ def on_new_investigation
5252

5353
duplicated_assignment_method_nodes.each do |nodes|
5454
nodes[1..-1].each do |node|
55-
register_offense(
56-
node,
57-
node.method_name,
58-
nodes.first.first_line
59-
)
55+
register_offense(node, node.method_name, nodes.first.first_line)
6056
end
6157
end
6258
end

lib/rubocop/cop/layout/indentation_width.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ def select_check_member(member)
185185

186186
def check_members_for_indented_internal_methods_style(members)
187187
each_member(members) do |member, previous_modifier|
188-
check_indentation(previous_modifier, member,
189-
indentation_consistency_style)
188+
check_indentation(previous_modifier, member, indentation_consistency_style)
190189
end
191190
end
192191

lib/rubocop/cop/lint/syntax.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ class Syntax < Base
99
def on_other_file
1010
add_offense_from_error(processed_source.parser_error) if processed_source.parser_error
1111
processed_source.diagnostics.each do |diagnostic|
12-
add_offense_from_diagnostic(diagnostic,
13-
processed_source.ruby_version)
12+
add_offense_from_diagnostic(diagnostic, processed_source.ruby_version)
1413
end
1514
super
1615
end

lib/rubocop/cop/metrics/utils/abc_size_calculator.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ def compound_assignment(node)
101101
children = node.masgn_type? ? node.children[0].children : node.children
102102

103103
will_be_miscounted = children.count do |child|
104-
child.respond_to?(:setter_method?) &&
105-
!child.setter_method?
104+
child.respond_to?(:setter_method?) && !child.setter_method?
106105
end
107106
@assignment += will_be_miscounted
108107

lib/rubocop/cop/mixin/multiline_expression_indentation.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ def assignment_rhs(node)
196196

197197
def not_for_this_cop?(node)
198198
node.ancestors.any? do |ancestor|
199-
grouped_expression?(ancestor) ||
200-
inside_arg_list_parentheses?(node, ancestor)
199+
grouped_expression?(ancestor) || inside_arg_list_parentheses?(node, ancestor)
201200
end
202201
end
203202

lib/rubocop/cop/style/empty_case_condition.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ def on_case(case_node)
4747
branch_bodies = [*case_node.when_branches.map(&:body), case_node.else_branch].compact
4848

4949
return if branch_bodies.any? do |body|
50-
body.return_type? ||
51-
body.each_descendant.any?(&:return_type?)
50+
body.return_type? || body.each_descendant.any?(&:return_type?)
5251
end
5352

5453
add_offense(case_node.loc.keyword) { |corrector| autocorrect(corrector, case_node) }

lib/rubocop/cop/style/redundant_capital_w.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def on_percent_literal(node)
3737

3838
def requires_interpolation?(node)
3939
node.child_nodes.any? do |string|
40-
string.dstr_type? ||
41-
double_quotes_required?(string.source)
40+
string.dstr_type? || double_quotes_required?(string.source)
4241
end
4342
end
4443
end

lib/rubocop/cop/style/ternary_parentheses.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ def infinite_loop?
184184

185185
def unsafe_autocorrect?(condition)
186186
condition.children.any? do |child|
187-
unparenthesized_method_call?(child) ||
188-
below_ternary_precedence?(child)
187+
unparenthesized_method_call?(child) || below_ternary_precedence?(child)
189188
end
190189
end
191190

lib/rubocop/cop/style/trailing_method_end_statement.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ def on_def(node)
4242
return if node.endless? || !trailing_end?(node)
4343

4444
add_offense(node.loc.end) do |corrector|
45-
corrector.insert_before(
46-
node.loc.end,
47-
"\n#{' ' * node.loc.keyword.column}"
48-
)
45+
corrector.insert_before(node.loc.end, "\n#{' ' * node.loc.keyword.column}")
4946
end
5047
end
5148

lib/rubocop/formatter/offense_count_formatter.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ def report_summary(offense_counts)
5252
output.puts
5353

5454
per_cop_counts.each do |cop_name, count|
55-
output.puts "#{count.to_s.ljust(total_count.to_s.length + 2)}" \
56-
"#{cop_name}\n"
55+
output.puts "#{count.to_s.ljust(total_count.to_s.length + 2)}#{cop_name}\n"
5756
end
5857
output.puts '--'
5958
output.puts "#{total_count} Total"

lib/rubocop/formatter/worst_offenders_formatter.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def report_summary(offense_counts)
4040
output.puts
4141

4242
per_file_counts.each do |file_name, count|
43-
output.puts "#{count.to_s.ljust(total_count.to_s.length + 2)}" \
44-
"#{file_name}\n"
43+
output.puts "#{count.to_s.ljust(total_count.to_s.length + 2)}#{file_name}\n"
4544
end
4645
output.puts '--'
4746
output.puts "#{total_count} Total"

spec/project_spec.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,7 @@ def expected
199199
describe 'body' do
200200
let(:bodies) do
201201
entries.map do |entry|
202-
entry
203-
.gsub(/`[^`]+`/, '``')
204-
.sub(/^\*\s*(?:\[.+?\):\s*)?/, '')
205-
.sub(/\s*\([^)]+\)$/, '')
202+
entry.gsub(/`[^`]+`/, '``').sub(/^\*\s*(?:\[.+?\):\s*)?/, '').sub(/\s*\([^)]+\)$/, '')
206203
end
207204
end
208205

spec/rubocop/cli/autocorrect_spec.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,7 @@ def verify_section
702702

703703
describe 'caching' do
704704
let(:cache) do
705-
instance_double(RuboCop::ResultCache, 'valid?' => true,
706-
'load' => cached_offenses)
705+
instance_double(RuboCop::ResultCache, 'valid?' => true, 'load' => cached_offenses)
707706
end
708707
let(:source) { %(puts "Hi"\n) }
709708

spec/rubocop/cli/options_spec.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,7 @@ def full_description_of_cop(cop)
12601260
context 'and offenses come from the cache' do
12611261
context 'and a message has binary encoding' do
12621262
let(:message_from_cache) do
1263-
(+'Cyclomatic complexity for 文 is too high. [8/6]')
1264-
.force_encoding('ASCII-8BIT')
1263+
(+'Cyclomatic complexity for 文 is too high. [8/6]').force_encoding('ASCII-8BIT')
12651264
end
12661265
let(:data_from_cache) do
12671266
[

spec/rubocop/cop/commissioner_spec.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ def method
3535
let(:processed_source) { parse_source(source, 'file.rb') }
3636
let(:cop_offenses) { [] }
3737
let(:cop_report) do
38-
RuboCop::Cop::Base::InvestigationReport
39-
.new(nil, processed_source, cop_offenses, nil)
38+
RuboCop::Cop::Base::InvestigationReport.new(nil, processed_source, cop_offenses, nil)
4039
end
4140

4241
around { |example| RuboCop::Cop::Registry.with_temporary_global { example.run } }

spec/rubocop/cop/cop_spec.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@
102102
end
103103

104104
before do
105-
allow(processed_source.comment_config).to receive(:cop_enabled_at_line?)
106-
.and_return(false)
105+
allow(processed_source.comment_config).to receive(:cop_enabled_at_line?).and_return(false)
107106
end
108107

109108
context 'ignore_disable_comments is false' do

spec/rubocop/cop/generator/require_file_injector_spec.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
let(:stdout) { StringIO.new }
55
let(:root_file_path) { 'lib/root.rb' }
66
let(:injector) do
7-
described_class.new(
8-
source_path: source_path,
9-
root_file_path: root_file_path,
10-
output: stdout
11-
)
7+
described_class.new(source_path: source_path, root_file_path: root_file_path, output: stdout)
128
end
139

1410
around do |example|

spec/rubocop/cop/layout/line_end_string_concatenation_indentation_spec.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ def some_method
173173
['X =', '$x =', '@x =', 'x =', 'x +=', 'x ||='].each do |lhs_and_operator|
174174
context "for assignment with #{lhs_and_operator}" do
175175
let(:aligned_strings) do
176-
[%(#{lhs_and_operator} "a" \\),
177-
"#{' ' * lhs_and_operator.length} 'b'",
178-
''].join("\n")
176+
[%(#{lhs_and_operator} "a" \\), "#{' ' * lhs_and_operator.length} 'b'", ''].join("\n")
179177
end
180178

181179
it 'accepts aligned strings' do
@@ -263,9 +261,7 @@ def some_method
263261
['X =', '$x =', '@x =', 'x =', 'x +=', 'x ||='].each do |lhs_and_operator|
264262
context "for assignment with #{lhs_and_operator}" do
265263
let(:indented_strings) do
266-
[%(#{lhs_and_operator} "a" \\),
267-
" 'b'",
268-
''].join("\n")
264+
[%(#{lhs_and_operator} "a" \\), " 'b'", ''].join("\n")
269265
end
270266

271267
it 'accepts indented strings' do

spec/rubocop/cop/layout/redundant_line_break_spec.rb

+30-30
Original file line numberDiff line numberDiff line change
@@ -123,39 +123,39 @@
123123

124124
it 'registers an offense for a method without parentheses on multiple lines' do
125125
expect_offense(<<~RUBY)
126-
def resolve_inheritance_from_gems(hash)
127-
gems = hash.delete('inherit_gem')
128-
(gems || {}).each_pair do |gem_name, config_path|
129-
if gem_name == 'rubocop'
130-
raise ArgumentError,
131-
^^^^^^^^^^^^^^^^^^^^ Redundant line break detected.
132-
"can't inherit configuration from the rubocop gem"
133-
end
134-
135-
hash['inherit_from'] = Array(hash['inherit_from'])
136-
Array(config_path).reverse_each do |path|
137-
# Put gem configuration first so local configuration overrides it.
138-
hash['inherit_from'].unshift gem_config_path(gem_name, path)
139-
end
140-
end
141-
end
126+
def resolve_inheritance_from_gems(hash)
127+
gems = hash.delete('inherit_gem')
128+
(gems || {}).each_pair do |gem_name, config_path|
129+
if gem_name == 'rubocop'
130+
raise ArgumentError,
131+
^^^^^^^^^^^^^^^^^^^^ Redundant line break detected.
132+
"can't inherit configuration from the rubocop gem"
133+
end
134+
135+
hash['inherit_from'] = Array(hash['inherit_from'])
136+
Array(config_path).reverse_each do |path|
137+
# Put gem configuration first so local configuration overrides it.
138+
hash['inherit_from'].unshift gem_config_path(gem_name, path)
139+
end
140+
end
141+
end
142142
RUBY
143143

144144
expect_correction(<<~RUBY)
145-
def resolve_inheritance_from_gems(hash)
146-
gems = hash.delete('inherit_gem')
147-
(gems || {}).each_pair do |gem_name, config_path|
148-
if gem_name == 'rubocop'
149-
raise ArgumentError, "can't inherit configuration from the rubocop gem"
150-
end
151-
152-
hash['inherit_from'] = Array(hash['inherit_from'])
153-
Array(config_path).reverse_each do |path|
154-
# Put gem configuration first so local configuration overrides it.
155-
hash['inherit_from'].unshift gem_config_path(gem_name, path)
156-
end
157-
end
158-
end
145+
def resolve_inheritance_from_gems(hash)
146+
gems = hash.delete('inherit_gem')
147+
(gems || {}).each_pair do |gem_name, config_path|
148+
if gem_name == 'rubocop'
149+
raise ArgumentError, "can't inherit configuration from the rubocop gem"
150+
end
151+
152+
hash['inherit_from'] = Array(hash['inherit_from'])
153+
Array(config_path).reverse_each do |path|
154+
# Put gem configuration first so local configuration overrides it.
155+
hash['inherit_from'].unshift gem_config_path(gem_name, path)
156+
end
157+
end
158+
end
159159
RUBY
160160
end
161161
end

spec/rubocop/cop/lint/multiple_comparison_spec.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
end
1616

1717
%w[< > <= >=].repeated_permutation(2) do |operator1, operator2|
18-
include_examples 'Check to use two comparison operator',
19-
operator1, operator2
18+
include_examples 'Check to use two comparison operator', operator1, operator2
2019
end
2120

2221
it 'accepts to use one compare operator' do

spec/rubocop/cop/lint/void_spec.rb

+2-10
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,7 @@
103103

104104
context 'when checking for methods with no side effects' do
105105
let(:config) do
106-
RuboCop::Config.new(
107-
'Lint/Void' => {
108-
'CheckForMethodsWithNoSideEffects' => true
109-
}
110-
)
106+
RuboCop::Config.new('Lint/Void' => { 'CheckForMethodsWithNoSideEffects' => true })
111107
end
112108

113109
it 'registers an offense if not on last line' do
@@ -129,11 +125,7 @@
129125

130126
context 'when not checking for methods with no side effects' do
131127
let(:config) do
132-
RuboCop::Config.new(
133-
'Lint/Void' => {
134-
'CheckForMethodsWithNoSideEffects' => false
135-
}
136-
)
128+
RuboCop::Config.new('Lint/Void' => { 'CheckForMethodsWithNoSideEffects' => false })
137129
end
138130

139131
it 'does not register an offense for void nonmutating methods' do

spec/rubocop/cop/message_annotator_spec.rb

+2-8
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@
6262

6363
context 'when StyleGuide is set in the config' do
6464
let(:config) do
65-
RuboCop::Config.new(
66-
'Cop/Cop' => { 'StyleGuide' => 'http://example.org/styleguide' }
67-
)
65+
RuboCop::Config.new('Cop/Cop' => { 'StyleGuide' => 'http://example.org/styleguide' })
6866
end
6967

7068
it 'adds style guide url' do
@@ -158,11 +156,7 @@
158156
describe '#urls' do
159157
let(:urls) { annotator.urls }
160158
let(:config) do
161-
RuboCop::Config.new(
162-
'AllCops' => {
163-
'StyleGuideBaseURL' => 'http://example.org/styleguide'
164-
}
165-
)
159+
RuboCop::Config.new('AllCops' => { 'StyleGuideBaseURL' => 'http://example.org/styleguide' })
166160
end
167161

168162
it 'returns an empty array without StyleGuide URL' do

spec/rubocop/cop/naming/file_name_spec.rb

+4-16
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,7 @@ module A
278278

279279
context 'when CheckDefinitionPathHierarchy is false' do
280280
let(:cop_config) do
281-
super().merge(
282-
'ExpectMatchingDefinition' => true,
283-
'CheckDefinitionPathHierarchy' => false
284-
)
281+
super().merge('ExpectMatchingDefinition' => true, 'CheckDefinitionPathHierarchy' => false)
285282
end
286283

287284
context 'on a file with a matching class' do
@@ -417,10 +414,7 @@ module Foo
417414

418415
context 'with acronym namespace' do
419416
let(:cop_config) do
420-
super().merge(
421-
'ExpectMatchingDefinition' => true,
422-
'AllowedAcronyms' => ['CLI']
423-
)
417+
super().merge('ExpectMatchingDefinition' => true, 'AllowedAcronyms' => ['CLI'])
424418
end
425419

426420
it 'does not register an offense' do
@@ -437,10 +431,7 @@ class AdminUser
437431

438432
context 'with acronym class name' do
439433
let(:cop_config) do
440-
super().merge(
441-
'ExpectMatchingDefinition' => true,
442-
'AllowedAcronyms' => ['CLI']
443-
)
434+
super().merge('ExpectMatchingDefinition' => true, 'AllowedAcronyms' => ['CLI'])
444435
end
445436

446437
it 'does not register an offense' do
@@ -455,10 +446,7 @@ class CLI
455446

456447
context 'with include acronym name' do
457448
let(:cop_config) do
458-
super().merge(
459-
'ExpectMatchingDefinition' => true,
460-
'AllowedAcronyms' => ['HTTP']
461-
)
449+
super().merge('ExpectMatchingDefinition' => true, 'AllowedAcronyms' => ['HTTP'])
462450
end
463451

464452
it 'does not register an offense' do

0 commit comments

Comments
 (0)