rubocop 0.77.0 → 0.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +39 -26
- data/lib/rubocop.rb +11 -2
- data/lib/rubocop/ast/builder.rb +43 -42
- data/lib/rubocop/ast/node/def_node.rb +11 -0
- data/lib/rubocop/ast/node/forward_args_node.rb +18 -0
- data/lib/rubocop/ast/traversal.rb +11 -3
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +7 -7
- data/lib/rubocop/cli/command/show_cops.rb +11 -4
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/config_loader.rb +19 -19
- data/lib/rubocop/config_obsoletion.rb +3 -3
- data/lib/rubocop/config_validator.rb +55 -95
- data/lib/rubocop/cop/autocorrect_logic.rb +7 -4
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
- data/lib/rubocop/cop/cop.rb +3 -1
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/generator.rb +3 -4
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +8 -4
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +4 -4
- data/lib/rubocop/cop/{metrics → layout}/line_length.rb +5 -78
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +14 -5
- data/lib/rubocop/cop/layout/space_around_operators.rb +31 -6
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
- data/lib/rubocop/cop/lint/debugger.rb +2 -2
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +3 -3
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +4 -4
- data/lib/rubocop/cop/migration/department_name.rb +16 -1
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -7
- data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
- data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +6 -3
- data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
- data/lib/rubocop/cop/offense.rb +11 -0
- data/lib/rubocop/cop/registry.rb +7 -2
- data/lib/rubocop/cop/style/attr.rb +8 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
- data/lib/rubocop/cop/style/guard_clause.rb +3 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +38 -3
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +4 -207
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +168 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +54 -0
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +5 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +4 -3
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +7 -7
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +16 -1
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/formatter/json_formatter.rb +6 -5
- data/lib/rubocop/node_pattern.rb +1 -1
- data/lib/rubocop/options.rb +8 -8
- data/lib/rubocop/result_cache.rb +2 -0
- data/lib/rubocop/rspec/shared_contexts.rb +5 -0
- data/lib/rubocop/runner.rb +5 -1
- data/lib/rubocop/target_ruby.rb +151 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +12 -5
data/lib/rubocop/result_cache.rb
CHANGED
@@ -186,6 +186,8 @@ module RuboCop
|
|
186
186
|
options.to_s.gsub(/[^a-z]+/i, '_')
|
187
187
|
end
|
188
188
|
|
189
|
+
# The external dependency checksums are cached per RuboCop team so that
|
190
|
+
# the checksums don't need to be recomputed for each file.
|
189
191
|
def team_checksum(team)
|
190
192
|
@checksum_by_team ||= {}
|
191
193
|
@checksum_by_team[team.object_id] ||= team.external_dependency_checksum
|
@@ -52,6 +52,7 @@ RSpec.shared_context 'config', :config do
|
|
52
52
|
cop_name = described_class.cop_name
|
53
53
|
hash[cop_name] = RuboCop::ConfigLoader
|
54
54
|
.default_configuration[cop_name]
|
55
|
+
.merge('Enabled' => true) # in case it is 'pending'
|
55
56
|
.merge(cop_config)
|
56
57
|
end
|
57
58
|
|
@@ -88,3 +89,7 @@ end
|
|
88
89
|
RSpec.shared_context 'ruby 2.6', :ruby26 do
|
89
90
|
let(:ruby_version) { 2.6 }
|
90
91
|
end
|
92
|
+
|
93
|
+
RSpec.shared_context 'ruby 2.7', :ruby27 do
|
94
|
+
let(:ruby_version) { 2.7 }
|
95
|
+
end
|
data/lib/rubocop/runner.rb
CHANGED
@@ -214,7 +214,7 @@ module RuboCop
|
|
214
214
|
@config_store.for(Dir.pwd).for_all_cops['UseCache']) &&
|
215
215
|
# When running --auto-gen-config, there's some processing done in the
|
216
216
|
# cops related to calculating the Max parameters for Metrics cops. We
|
217
|
-
# need to do that processing and
|
217
|
+
# need to do that processing and cannot use caching.
|
218
218
|
!@options[:auto_gen_config] &&
|
219
219
|
# We can't cache results from code which is piped in to stdin
|
220
220
|
!@options[:stdin]
|
@@ -366,6 +366,10 @@ module RuboCop
|
|
366
366
|
end
|
367
367
|
end
|
368
368
|
|
369
|
+
# A Cop::Team instance is stateful and may change when inspecting.
|
370
|
+
# The "standby" team for a given config is an initialized but
|
371
|
+
# otherwise dormant team that can be used for config- and option-
|
372
|
+
# level caching in ResultCache.
|
369
373
|
def standby_team(config)
|
370
374
|
@team_by_config ||= {}
|
371
375
|
@team_by_config[config.object_id] ||=
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
# The kind of Ruby that code inspected by RuboCop is written in.
|
5
|
+
class TargetRuby
|
6
|
+
KNOWN_RUBIES = [2.3, 2.4, 2.5, 2.6, 2.7].freeze
|
7
|
+
DEFAULT_VERSION = KNOWN_RUBIES.first
|
8
|
+
|
9
|
+
OBSOLETE_RUBIES = {
|
10
|
+
1.9 => '0.50', 2.0 => '0.50', 2.1 => '0.58', 2.2 => '0.69'
|
11
|
+
}.freeze
|
12
|
+
private_constant :KNOWN_RUBIES, :OBSOLETE_RUBIES
|
13
|
+
|
14
|
+
# A place where information about a target ruby version is found.
|
15
|
+
class Source
|
16
|
+
attr_reader :version, :name
|
17
|
+
|
18
|
+
def initialize(config)
|
19
|
+
@config = config
|
20
|
+
@version = find_version
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# The target ruby version may be configured in RuboCop's config.
|
29
|
+
class RuboCopConfig < Source
|
30
|
+
def name
|
31
|
+
"`TargetRubyVersion` parameter (in #{@config.smart_loaded_path})"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def find_version
|
37
|
+
@config.for_all_cops['TargetRubyVersion']&.to_f
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# The target ruby version may be found in a .ruby-version file.
|
42
|
+
class RubyVersionFile < Source
|
43
|
+
FILENAME = '.ruby-version'
|
44
|
+
|
45
|
+
def name
|
46
|
+
"`#{FILENAME}`"
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def find_version
|
52
|
+
file = ruby_version_file
|
53
|
+
return unless file && File.file?(file)
|
54
|
+
|
55
|
+
File.read(file).match(/\A(ruby-)?(?<version>\d+\.\d+)/) do |md|
|
56
|
+
md[:version].to_f
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def ruby_version_file
|
61
|
+
@ruby_version_file ||=
|
62
|
+
@config.find_file_upwards(FILENAME,
|
63
|
+
@config.base_dir_for_path_parameters)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# The lock file of Bundler may identify the target ruby version.
|
68
|
+
class BundlerLockFile < Source
|
69
|
+
def name
|
70
|
+
"`#{bundler_lock_file_path}`"
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def find_version
|
76
|
+
lock_file_path = bundler_lock_file_path
|
77
|
+
return nil unless lock_file_path
|
78
|
+
|
79
|
+
in_ruby_section = false
|
80
|
+
File.foreach(lock_file_path) do |line|
|
81
|
+
# If ruby is in Gemfile.lock or gems.lock, there should be two lines
|
82
|
+
# towards the bottom of the file that look like:
|
83
|
+
# RUBY VERSION
|
84
|
+
# ruby W.X.YpZ
|
85
|
+
# We ultimately want to match the "ruby W.X.Y.pZ" line, but there's
|
86
|
+
# extra logic to make sure we only start looking once we've seen the
|
87
|
+
# "RUBY VERSION" line.
|
88
|
+
in_ruby_section ||= line.match(/^\s*RUBY\s*VERSION\s*$/)
|
89
|
+
next unless in_ruby_section
|
90
|
+
|
91
|
+
# We currently only allow this feature to work with MRI ruby. If
|
92
|
+
# jruby (or something else) is used by the project, it's lock file
|
93
|
+
# will have a line that looks like:
|
94
|
+
# RUBY VERSION
|
95
|
+
# ruby W.X.YpZ (jruby x.x.x.x)
|
96
|
+
# The regex won't match in this situation.
|
97
|
+
result = line.match(/^\s*ruby\s+(\d+\.\d+)[p.\d]*\s*$/)
|
98
|
+
return result.captures.first.to_f if result
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def bundler_lock_file_path
|
103
|
+
@config.bundler_lock_file_path
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# If all else fails, a default version will be picked.
|
108
|
+
class Default < Source
|
109
|
+
def name
|
110
|
+
'default'
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def find_version
|
116
|
+
DEFAULT_VERSION
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.supported_versions
|
121
|
+
KNOWN_RUBIES
|
122
|
+
end
|
123
|
+
|
124
|
+
SOURCES = [RuboCopConfig, RubyVersionFile, BundlerLockFile, Default].freeze
|
125
|
+
private_constant :SOURCES
|
126
|
+
|
127
|
+
def initialize(config)
|
128
|
+
@config = config
|
129
|
+
end
|
130
|
+
|
131
|
+
def source
|
132
|
+
@source ||= SOURCES.each.lazy.map { |c| c.new(@config) }.detect(&:version)
|
133
|
+
end
|
134
|
+
|
135
|
+
def version
|
136
|
+
source.version
|
137
|
+
end
|
138
|
+
|
139
|
+
def supported?
|
140
|
+
KNOWN_RUBIES.include?(version)
|
141
|
+
end
|
142
|
+
|
143
|
+
def rubocop_version_with_support
|
144
|
+
if supported?
|
145
|
+
RuboCop::Version.version
|
146
|
+
else
|
147
|
+
OBSOLETE_RUBIES[version]
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
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.79.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:
|
13
|
+
date: 2020-01-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jaro_winkler
|
@@ -46,14 +46,14 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
49
|
+
version: 2.7.0.1
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
56
|
+
version: 2.7.0.1
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: rainbow
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/rubocop/ast/node/ensure_node.rb
|
164
164
|
- lib/rubocop/ast/node/float_node.rb
|
165
165
|
- lib/rubocop/ast/node/for_node.rb
|
166
|
+
- lib/rubocop/ast/node/forward_args_node.rb
|
166
167
|
- lib/rubocop/ast/node/hash_node.rb
|
167
168
|
- lib/rubocop/ast/node/if_node.rb
|
168
169
|
- lib/rubocop/ast/node/int_node.rb
|
@@ -302,6 +303,7 @@ files:
|
|
302
303
|
- lib/rubocop/cop/layout/initial_indentation.rb
|
303
304
|
- lib/rubocop/cop/layout/leading_comment_space.rb
|
304
305
|
- lib/rubocop/cop/layout/leading_empty_lines.rb
|
306
|
+
- lib/rubocop/cop/layout/line_length.rb
|
305
307
|
- lib/rubocop/cop/layout/multiline_array_brace_layout.rb
|
306
308
|
- lib/rubocop/cop/layout/multiline_array_line_breaks.rb
|
307
309
|
- lib/rubocop/cop/layout/multiline_assignment_layout.rb
|
@@ -380,6 +382,7 @@ files:
|
|
380
382
|
- lib/rubocop/cop/lint/nested_method_definition.rb
|
381
383
|
- lib/rubocop/cop/lint/nested_percent_literal.rb
|
382
384
|
- lib/rubocop/cop/lint/next_without_accumulator.rb
|
385
|
+
- lib/rubocop/cop/lint/non_deterministic_require_order.rb
|
383
386
|
- lib/rubocop/cop/lint/non_local_exit_from_iterator.rb
|
384
387
|
- lib/rubocop/cop/lint/number_conversion.rb
|
385
388
|
- lib/rubocop/cop/lint/ordered_magic_comments.rb
|
@@ -429,7 +432,6 @@ files:
|
|
429
432
|
- lib/rubocop/cop/metrics/block_nesting.rb
|
430
433
|
- lib/rubocop/cop/metrics/class_length.rb
|
431
434
|
- lib/rubocop/cop/metrics/cyclomatic_complexity.rb
|
432
|
-
- lib/rubocop/cop/metrics/line_length.rb
|
433
435
|
- lib/rubocop/cop/metrics/method_length.rb
|
434
436
|
- lib/rubocop/cop/metrics/module_length.rb
|
435
437
|
- lib/rubocop/cop/metrics/parameter_lists.rb
|
@@ -464,6 +466,7 @@ files:
|
|
464
466
|
- lib/rubocop/cop/mixin/ignored_pattern.rb
|
465
467
|
- lib/rubocop/cop/mixin/integer_node.rb
|
466
468
|
- lib/rubocop/cop/mixin/interpolation.rb
|
469
|
+
- lib/rubocop/cop/mixin/line_length_help.rb
|
467
470
|
- lib/rubocop/cop/mixin/match_range.rb
|
468
471
|
- lib/rubocop/cop/mixin/method_complexity.rb
|
469
472
|
- lib/rubocop/cop/mixin/method_preference.rb
|
@@ -483,6 +486,7 @@ files:
|
|
483
486
|
- lib/rubocop/cop/mixin/preceding_following_alignment.rb
|
484
487
|
- lib/rubocop/cop/mixin/preferred_delimiters.rb
|
485
488
|
- lib/rubocop/cop/mixin/range_help.rb
|
489
|
+
- lib/rubocop/cop/mixin/rational_literal.rb
|
486
490
|
- lib/rubocop/cop/mixin/rescue_node.rb
|
487
491
|
- lib/rubocop/cop/mixin/safe_assignment.rb
|
488
492
|
- lib/rubocop/cop/mixin/space_after_punctuation.rb
|
@@ -590,6 +594,8 @@ files:
|
|
590
594
|
- lib/rubocop/cop/style/lambda_call.rb
|
591
595
|
- lib/rubocop/cop/style/line_end_concatenation.rb
|
592
596
|
- lib/rubocop/cop/style/method_call_with_args_parentheses.rb
|
597
|
+
- lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb
|
598
|
+
- lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
|
593
599
|
- lib/rubocop/cop/style/method_call_without_args_parentheses.rb
|
594
600
|
- lib/rubocop/cop/style/method_called_on_do_end_block.rb
|
595
601
|
- lib/rubocop/cop/style/method_def_parentheses.rb
|
@@ -744,6 +750,7 @@ files:
|
|
744
750
|
- lib/rubocop/string_interpreter.rb
|
745
751
|
- lib/rubocop/string_util.rb
|
746
752
|
- lib/rubocop/target_finder.rb
|
753
|
+
- lib/rubocop/target_ruby.rb
|
747
754
|
- lib/rubocop/token.rb
|
748
755
|
- lib/rubocop/version.rb
|
749
756
|
- lib/rubocop/warning.rb
|