rubocop 0.86.0 → 0.87.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +46 -4
- data/lib/rubocop.rb +7 -1
- data/lib/rubocop/cli.rb +0 -2
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +40 -5
- data/lib/rubocop/cli/command/show_cops.rb +1 -1
- data/lib/rubocop/config_loader.rb +22 -62
- data/lib/rubocop/config_obsoletion.rb +0 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +13 -23
- data/lib/rubocop/cop/base.rb +399 -0
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +10 -20
- data/lib/rubocop/cop/commissioner.rb +48 -50
- data/lib/rubocop/cop/cop.rb +85 -236
- data/lib/rubocop/cop/corrector.rb +38 -115
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/generator.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +11 -14
- data/lib/rubocop/cop/layout/case_indentation.rb +18 -19
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +1 -8
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +4 -0
- data/lib/rubocop/cop/layout/hash_alignment.rb +1 -2
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +0 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +19 -25
- data/lib/rubocop/cop/legacy/corrections_proxy.rb +49 -0
- data/lib/rubocop/cop/legacy/corrector.rb +29 -0
- data/lib/rubocop/cop/lint/interpolation_check.rb +13 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +8 -3
- data/lib/rubocop/cop/lint/rand_one.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +27 -23
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -2
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +8 -0
- data/lib/rubocop/cop/lint/syntax.rb +11 -26
- data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -1
- data/lib/rubocop/cop/metrics/block_length.rb +22 -0
- data/lib/rubocop/cop/metrics/class_length.rb +25 -2
- data/lib/rubocop/cop/metrics/method_length.rb +23 -0
- data/lib/rubocop/cop/metrics/module_length.rb +25 -2
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +129 -0
- data/lib/rubocop/cop/mixin/allowed_methods.rb +19 -0
- data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
- data/lib/rubocop/cop/mixin/code_length.rb +4 -0
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +3 -1
- data/lib/rubocop/cop/mixin/nil_methods.rb +3 -5
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +6 -1
- data/lib/rubocop/cop/mixin/surrounding_space.rb +7 -2
- data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -13
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +4 -2
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +27 -4
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +2 -2
- data/lib/rubocop/cop/naming/method_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +3 -5
- data/lib/rubocop/cop/naming/variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/variable_number.rb +1 -1
- data/lib/rubocop/cop/offense.rb +16 -2
- data/lib/rubocop/cop/style/accessor_grouping.rb +136 -0
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +121 -0
- data/lib/rubocop/cop/style/class_vars.rb +21 -0
- data/lib/rubocop/cop/style/date_time.rb +1 -1
- data/lib/rubocop/cop/style/dir.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +5 -5
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -0
- data/lib/rubocop/cop/style/multiline_block_chain.rb +10 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +4 -4
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -5
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +4 -10
- data/lib/rubocop/cop/style/redundant_assignment.rb +117 -0
- data/lib/rubocop/cop/style/redundant_exception.rb +14 -10
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +26 -7
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +7 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -1
- data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -1
- data/lib/rubocop/cop/style/signal_exception.rb +1 -1
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +2 -2
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +8 -7
- data/lib/rubocop/cop/style/zero_length_predicate.rb +2 -2
- data/lib/rubocop/cop/team.rb +97 -81
- data/lib/rubocop/cop/utils/format_string.rb +1 -2
- data/lib/rubocop/name_similarity.rb +1 -3
- data/lib/rubocop/options.rb +15 -8
- data/lib/rubocop/rake_task.rb +6 -9
- data/lib/rubocop/rspec/cop_helper.rb +4 -4
- data/lib/rubocop/rspec/expect_offense.rb +10 -16
- data/lib/rubocop/rspec/shared_contexts.rb +7 -7
- data/lib/rubocop/runner.rb +31 -29
- data/lib/rubocop/target_ruby.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +15 -7
- data/lib/rubocop/cop/mixin/classish_length.rb +0 -37
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'tmpdir'
|
4
|
-
require 'fileutils'
|
5
4
|
|
6
5
|
RSpec.shared_context 'isolated environment', :isolated_environment do
|
7
6
|
around do |example|
|
@@ -45,11 +44,11 @@ RSpec.shared_context 'config', :config do # rubocop:disable Metrics/BlockLength
|
|
45
44
|
let(:source) { 'code = {some: :ruby}' }
|
46
45
|
|
47
46
|
let(:cop_class) do
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
RuboCop::Cop::Cop
|
47
|
+
unless described_class.is_a?(Class) && described_class < RuboCop::Cop::Base
|
48
|
+
raise 'Specify which cop class to use (e.g `let(:cop_class) { RuboCop::Cop::Base }`, ' \
|
49
|
+
'or RuboCop::Cop::Cop for legacy)'
|
52
50
|
end
|
51
|
+
described_class
|
53
52
|
end
|
54
53
|
|
55
54
|
let(:cop_config) { {} }
|
@@ -95,8 +94,9 @@ RSpec.shared_context 'config', :config do # rubocop:disable Metrics/BlockLength
|
|
95
94
|
end
|
96
95
|
|
97
96
|
let(:cop) do
|
98
|
-
cop_class.new(config, cop_options)
|
99
|
-
|
97
|
+
cop_class.new(config, cop_options).tap do |cop|
|
98
|
+
cop.send :begin_investigation, processed_source
|
99
|
+
end
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
data/lib/rubocop/runner.rb
CHANGED
@@ -120,7 +120,8 @@ module RuboCop
|
|
120
120
|
file_offense_cache(file) do
|
121
121
|
source = get_processed_source(file)
|
122
122
|
source, offenses = do_inspection_loop(file, source)
|
123
|
-
add_redundant_disables(file, offenses.compact.sort, source)
|
123
|
+
offenses = add_redundant_disables(file, offenses.compact.sort, source)
|
124
|
+
offenses.sort.reject(&:disabled?).freeze
|
124
125
|
end
|
125
126
|
end
|
126
127
|
|
@@ -151,16 +152,30 @@ module RuboCop
|
|
151
152
|
end
|
152
153
|
|
153
154
|
def add_redundant_disables(file, offenses, source)
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
155
|
+
team_for_redundant_disables(file, offenses, source) do |team|
|
156
|
+
new_offenses, redundant_updated = inspect_file(source, team)
|
157
|
+
offenses += new_offenses
|
158
|
+
if redundant_updated
|
159
|
+
# Do one extra inspection loop if any redundant disables were
|
160
|
+
# removed. This is done in order to find rubocop:enable directives that
|
161
|
+
# have now become useless.
|
162
|
+
_source, new_offenses = do_inspection_loop(file,
|
163
|
+
get_processed_source(file))
|
164
|
+
offenses |= new_offenses
|
160
165
|
end
|
161
166
|
end
|
167
|
+
offenses
|
168
|
+
end
|
162
169
|
|
163
|
-
|
170
|
+
def team_for_redundant_disables(file, offenses, source)
|
171
|
+
return unless check_for_redundant_disables?(source)
|
172
|
+
|
173
|
+
config = @config_store.for_file(file)
|
174
|
+
team = Cop::Team.mobilize([Cop::Lint::RedundantCopDisableDirective], config, @options)
|
175
|
+
return if team.cops.empty?
|
176
|
+
|
177
|
+
team.cops.first.offenses_to_check = offenses
|
178
|
+
yield team
|
164
179
|
end
|
165
180
|
|
166
181
|
def check_for_redundant_disables?(source)
|
@@ -180,22 +195,6 @@ module RuboCop
|
|
180
195
|
@options[:except] || @options[:only]
|
181
196
|
end
|
182
197
|
|
183
|
-
def autocorrect_redundant_disables(file, source, cop, offenses)
|
184
|
-
cop.processed_source = source
|
185
|
-
|
186
|
-
team = Cop::Team.mobilize(RuboCop::Cop::Registry.new, nil, @options)
|
187
|
-
team.autocorrect(source.buffer, [cop])
|
188
|
-
|
189
|
-
return [] unless team.updated_source_file?
|
190
|
-
|
191
|
-
# Do one extra inspection loop if any redundant disables were
|
192
|
-
# removed. This is done in order to find rubocop:enable directives that
|
193
|
-
# have now become useless.
|
194
|
-
_source, new_offenses = do_inspection_loop(file,
|
195
|
-
get_processed_source(file))
|
196
|
-
new_offenses - offenses
|
197
|
-
end
|
198
|
-
|
199
198
|
def file_started(file)
|
200
199
|
puts "Scanning #{file}" if @options[:debug]
|
201
200
|
formatter_set.file_started(file,
|
@@ -293,13 +292,16 @@ module RuboCop
|
|
293
292
|
@processed_sources << checksum
|
294
293
|
end
|
295
294
|
|
296
|
-
def inspect_file(processed_source)
|
297
|
-
|
298
|
-
team = Cop::Team.mobilize(mobilized_cop_classes(config), config, @options)
|
299
|
-
offenses = team.inspect_file(processed_source)
|
295
|
+
def inspect_file(processed_source, team = mobilize_team(processed_source))
|
296
|
+
report = team.investigate(processed_source)
|
300
297
|
@errors.concat(team.errors)
|
301
298
|
@warnings.concat(team.warnings)
|
302
|
-
[offenses, team.updated_source_file?]
|
299
|
+
[report.offenses, team.updated_source_file?]
|
300
|
+
end
|
301
|
+
|
302
|
+
def mobilize_team(processed_source)
|
303
|
+
config = @config_store.for_file(processed_source.path)
|
304
|
+
Cop::Team.mobilize(mobilized_cop_classes(config), config, @options)
|
303
305
|
end
|
304
306
|
|
305
307
|
def mobilized_cop_classes(config)
|
data/lib/rubocop/target_ruby.rb
CHANGED
data/lib/rubocop/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.87.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-06
|
13
|
+
date: 2020-07-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parallel
|
@@ -32,14 +32,14 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 2.7.
|
35
|
+
version: 2.7.1.1
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 2.7.
|
42
|
+
version: 2.7.1.1
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: rainbow
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
requirements:
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: 0.0
|
97
|
+
version: 0.1.0
|
98
98
|
- - "<"
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '1.0'
|
@@ -104,7 +104,7 @@ dependencies:
|
|
104
104
|
requirements:
|
105
105
|
- - ">="
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version: 0.0
|
107
|
+
version: 0.1.0
|
108
108
|
- - "<"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1.0'
|
@@ -202,6 +202,7 @@ files:
|
|
202
202
|
- lib/rubocop/config_validator.rb
|
203
203
|
- lib/rubocop/cop/autocorrect_logic.rb
|
204
204
|
- lib/rubocop/cop/badge.rb
|
205
|
+
- lib/rubocop/cop/base.rb
|
205
206
|
- lib/rubocop/cop/bundler/duplicated_gem.rb
|
206
207
|
- lib/rubocop/cop/bundler/gem_comment.rb
|
207
208
|
- lib/rubocop/cop/bundler/insecure_protocol_source.rb
|
@@ -331,6 +332,8 @@ files:
|
|
331
332
|
- lib/rubocop/cop/layout/space_inside_string_interpolation.rb
|
332
333
|
- lib/rubocop/cop/layout/trailing_empty_lines.rb
|
333
334
|
- lib/rubocop/cop/layout/trailing_whitespace.rb
|
335
|
+
- lib/rubocop/cop/legacy/corrections_proxy.rb
|
336
|
+
- lib/rubocop/cop/legacy/corrector.rb
|
334
337
|
- lib/rubocop/cop/lint/ambiguous_block_association.rb
|
335
338
|
- lib/rubocop/cop/lint/ambiguous_operator.rb
|
336
339
|
- lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
|
@@ -428,15 +431,17 @@ files:
|
|
428
431
|
- lib/rubocop/cop/metrics/parameter_lists.rb
|
429
432
|
- lib/rubocop/cop/metrics/perceived_complexity.rb
|
430
433
|
- lib/rubocop/cop/metrics/utils/abc_size_calculator.rb
|
434
|
+
- lib/rubocop/cop/metrics/utils/code_length_calculator.rb
|
431
435
|
- lib/rubocop/cop/metrics/utils/iterating_block.rb
|
432
436
|
- lib/rubocop/cop/migration/department_name.rb
|
433
437
|
- lib/rubocop/cop/mixin/alignment.rb
|
438
|
+
- lib/rubocop/cop/mixin/allowed_methods.rb
|
434
439
|
- lib/rubocop/cop/mixin/annotation_comment.rb
|
435
440
|
- lib/rubocop/cop/mixin/array_min_size.rb
|
436
441
|
- lib/rubocop/cop/mixin/array_syntax.rb
|
442
|
+
- lib/rubocop/cop/mixin/auto_corrector.rb
|
437
443
|
- lib/rubocop/cop/mixin/check_assignment.rb
|
438
444
|
- lib/rubocop/cop/mixin/check_line_breakable.rb
|
439
|
-
- lib/rubocop/cop/mixin/classish_length.rb
|
440
445
|
- lib/rubocop/cop/mixin/code_length.rb
|
441
446
|
- lib/rubocop/cop/mixin/configurable_enforced_style.rb
|
442
447
|
- lib/rubocop/cop/mixin/configurable_formatting.rb
|
@@ -520,6 +525,7 @@ files:
|
|
520
525
|
- lib/rubocop/cop/security/yaml_load.rb
|
521
526
|
- lib/rubocop/cop/severity.rb
|
522
527
|
- lib/rubocop/cop/style/access_modifier_declarations.rb
|
528
|
+
- lib/rubocop/cop/style/accessor_grouping.rb
|
523
529
|
- lib/rubocop/cop/style/alias.rb
|
524
530
|
- lib/rubocop/cop/style/and_or.rb
|
525
531
|
- lib/rubocop/cop/style/array_join.rb
|
@@ -528,6 +534,7 @@ files:
|
|
528
534
|
- lib/rubocop/cop/style/auto_resource_cleanup.rb
|
529
535
|
- lib/rubocop/cop/style/bare_percent_literals.rb
|
530
536
|
- lib/rubocop/cop/style/begin_block.rb
|
537
|
+
- lib/rubocop/cop/style/bisected_attr_accessor.rb
|
531
538
|
- lib/rubocop/cop/style/block_comments.rb
|
532
539
|
- lib/rubocop/cop/style/block_delimiters.rb
|
533
540
|
- lib/rubocop/cop/style/case_equality.rb
|
@@ -639,6 +646,7 @@ files:
|
|
639
646
|
- lib/rubocop/cop/style/proc.rb
|
640
647
|
- lib/rubocop/cop/style/raise_args.rb
|
641
648
|
- lib/rubocop/cop/style/random_with_offset.rb
|
649
|
+
- lib/rubocop/cop/style/redundant_assignment.rb
|
642
650
|
- lib/rubocop/cop/style/redundant_begin.rb
|
643
651
|
- lib/rubocop/cop/style/redundant_capital_w.rb
|
644
652
|
- lib/rubocop/cop/style/redundant_condition.rb
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
# Common functionality for checking length of classes and modules.
|
6
|
-
module ClassishLength
|
7
|
-
include CodeLength
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def code_length(node)
|
12
|
-
body_line_numbers = line_range(node).to_a[1...-1]
|
13
|
-
|
14
|
-
target_line_numbers = body_line_numbers -
|
15
|
-
line_numbers_of_inner_nodes(node, :module, :class)
|
16
|
-
|
17
|
-
target_line_numbers.reduce(0) do |length, line_number|
|
18
|
-
source_line = processed_source[line_number]
|
19
|
-
next length if irrelevant_line(source_line)
|
20
|
-
|
21
|
-
length + 1
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def line_numbers_of_inner_nodes(node, *types)
|
26
|
-
line_numbers = Set.new
|
27
|
-
|
28
|
-
node.each_descendant(*types) do |inner_node|
|
29
|
-
line_range = line_range(inner_node)
|
30
|
-
line_numbers.merge(line_range)
|
31
|
-
end
|
32
|
-
|
33
|
-
line_numbers.to_a
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|