rubocop 1.92.1 → 1.92.3
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/lib/rubocop/#directive_comment.rb# +224 -0
- data/lib/rubocop/cache_config.rb +3 -0
- data/lib/rubocop/cli.rb +5 -4
- data/lib/rubocop/config.rb +16 -4
- data/lib/rubocop/config_obsoletion.rb +9 -0
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +9 -19
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +8 -18
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +27 -13
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +8 -4
- data/lib/rubocop/cop/layout/block_end_newline.rb +51 -5
- data/lib/rubocop/cop/layout/class_structure.rb +91 -13
- data/lib/rubocop/cop/layout/def_end_alignment.rb +9 -5
- data/lib/rubocop/cop/layout/else_alignment.rb +2 -0
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +5 -19
- data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +15 -7
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +32 -11
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +35 -5
- data/lib/rubocop/cop/layout/end_alignment.rb +6 -12
- data/lib/rubocop/cop/layout/extra_spacing.rb +22 -12
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +4 -1
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +7 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +21 -3
- data/lib/rubocop/cop/layout/indentation_style.rb +2 -2
- data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +23 -5
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +7 -2
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +9 -2
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +8 -4
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +11 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +31 -4
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +12 -0
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +15 -4
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_range_literal.rb +29 -11
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +4 -0
- data/lib/rubocop/cop/lint/ambiguous_operator_precedence.rb +4 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +2 -2
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +14 -4
- data/lib/rubocop/cop/lint/duplicate_methods.rb +6 -6
- data/lib/rubocop/cop/lint/duplicate_require.rb +8 -1
- data/lib/rubocop/cop/lint/hash_new_with_keyword_arguments_as_default.rb +19 -0
- data/lib/rubocop/cop/lint/interpolation_check.rb +27 -18
- data/lib/rubocop/cop/lint/literal_as_condition.rb +29 -18
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +50 -4
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +3 -0
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +42 -2
- data/lib/rubocop/cop/lint/number_conversion.rb +4 -0
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +66 -3
- data/lib/rubocop/cop/lint/percent_string_array.rb +75 -9
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +45 -8
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +14 -6
- data/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb +19 -1
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +27 -1
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +11 -4
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +62 -9
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +21 -1
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +4 -0
- data/lib/rubocop/cop/lint/triple_quotes.rb +4 -0
- data/lib/rubocop/cop/lint/useless_assignment.rb +26 -0
- data/lib/rubocop/cop/lint/useless_times.rb +13 -1
- data/lib/rubocop/cop/lint/void.rb +20 -9
- data/lib/rubocop/cop/message_annotator.rb +6 -8
- data/lib/rubocop/cop/mixin/comments_help.rb +2 -2
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +34 -18
- data/lib/rubocop/cop/mixin/endless_method_body_help.rb +45 -6
- data/lib/rubocop/cop/mixin/endless_method_rewriter.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +17 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +1 -0
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +12 -0
- data/lib/rubocop/cop/mixin/percent_array.rb +35 -2
- data/lib/rubocop/cop/mixin/project_index_help.rb +5 -6
- data/lib/rubocop/cop/mixin/range_help.rb +13 -0
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +11 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +14 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +4 -2
- data/lib/rubocop/cop/naming/block_forwarding.rb +9 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +7 -3
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +6 -2
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +15 -2
- data/lib/rubocop/cop/style/ambiguous_endless_method_definition.rb +5 -0
- data/lib/rubocop/cop/style/and_or.rb +41 -11
- data/lib/rubocop/cop/style/block_delimiters.rb +6 -1
- data/lib/rubocop/cop/style/case_equality.rb +14 -3
- data/lib/rubocop/cop/style/class_and_module_children.rb +12 -15
- data/lib/rubocop/cop/style/class_methods_definitions.rb +9 -1
- data/lib/rubocop/cop/style/combinable_loops.rb +1 -1
- data/lib/rubocop/cop/style/concat_array_literals.rb +13 -4
- data/lib/rubocop/cop/style/data_inheritance.rb +4 -0
- data/lib/rubocop/cop/style/def_with_parentheses.rb +9 -2
- data/lib/rubocop/cop/style/empty_class_definition.rb +2 -3
- data/lib/rubocop/cop/style/empty_literal.rb +7 -0
- data/lib/rubocop/cop/style/empty_method.rb +16 -4
- data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +11 -5
- data/lib/rubocop/cop/style/endless_method.rb +64 -16
- data/lib/rubocop/cop/style/explicit_block_argument.rb +19 -4
- data/lib/rubocop/cop/style/float_division.rb +16 -1
- data/lib/rubocop/cop/style/for.rb +59 -4
- data/lib/rubocop/cop/style/guard_clause.rb +56 -11
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +1 -1
- data/lib/rubocop/cop/style/hash_conversion.rb +3 -1
- data/lib/rubocop/cop/style/hash_fetch_chain.rb +1 -1
- data/lib/rubocop/cop/style/hash_lookup_method.rb +21 -2
- data/lib/rubocop/cop/style/hash_syntax.rb +3 -2
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +78 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +1 -1
- data/lib/rubocop/cop/style/if_with_semicolon.rb +32 -2
- data/lib/rubocop/cop/style/it_block_parameter.rb +11 -1
- data/lib/rubocop/cop/style/lambda.rb +13 -5
- data/lib/rubocop/cop/style/line_end_concatenation.rb +1 -1
- data/lib/rubocop/cop/style/map_into_array.rb +4 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +10 -2
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +38 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +12 -1
- data/lib/rubocop/cop/style/method_def_parentheses.rb +9 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +1 -1
- data/lib/rubocop/cop/style/nil_lambda.rb +18 -6
- data/lib/rubocop/cop/style/non_nil_check.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +7 -0
- data/lib/rubocop/cop/style/operator_method_call.rb +23 -24
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +20 -10
- data/lib/rubocop/cop/style/partition_instead_of_double_select.rb +1 -2
- data/lib/rubocop/cop/style/perl_backrefs.rb +3 -0
- data/lib/rubocop/cop/style/quoted_symbols.rb +5 -7
- data/lib/rubocop/cop/style/raise_args.rb +66 -7
- data/lib/rubocop/cop/style/reduce_to_hash.rb +32 -34
- data/lib/rubocop/cop/style/redundant_array_constructor.rb +4 -1
- data/lib/rubocop/cop/style/redundant_begin.rb +120 -18
- data/lib/rubocop/cop/style/redundant_each.rb +8 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +13 -9
- data/lib/rubocop/cop/style/redundant_interpolation.rb +36 -16
- data/lib/rubocop/cop/style/redundant_percent_q.rb +11 -2
- data/lib/rubocop/cop/style/redundant_self.rb +9 -1
- data/lib/rubocop/cop/style/redundant_sort.rb +5 -1
- data/lib/rubocop/cop/style/semicolon.rb +1 -1
- data/lib/rubocop/cop/style/send_with_literal_method_name.rb +8 -3
- data/lib/rubocop/cop/style/single_line_block_params.rb +3 -1
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +56 -19
- data/lib/rubocop/cop/style/single_line_methods.rb +26 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -0
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +2 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +28 -8
- data/lib/rubocop/cop/style/struct_inheritance.rb +14 -0
- data/lib/rubocop/cop/style/symbol_array.rb +1 -3
- data/lib/rubocop/cop/style/word_array.rb +1 -3
- data/lib/rubocop/cop/util.rb +2 -0
- data/lib/rubocop/cop/variable_force.rb +14 -1
- data/lib/rubocop/cops_documentation_generator.rb +1 -1
- data/lib/rubocop/formatter/junit_formatter.rb +13 -6
- data/lib/rubocop/plugin/configuration_integrator.rb +24 -3
- data/lib/rubocop/result_cache.rb +9 -3
- data/lib/rubocop/runner.rb +6 -1
- data/lib/rubocop/server/cache.rb +24 -5
- data/lib/rubocop/todo_audit.rb +61 -15
- data/lib/rubocop/version.rb +1 -1
- metadata +4 -3
|
@@ -105,18 +105,39 @@ module RuboCop
|
|
|
105
105
|
|
|
106
106
|
case rules.type
|
|
107
107
|
when :path
|
|
108
|
-
|
|
108
|
+
config = ConfigLoader.load_file(rules.value, check: false)
|
|
109
|
+
warn_about_obsolete_config(plugin, config)
|
|
110
|
+
[config, rules.value]
|
|
109
111
|
when :object
|
|
110
112
|
path = plugin.method(:rules).source_location[0]
|
|
111
113
|
[Config.create(rules.value, path, check: true), path]
|
|
112
114
|
when :error
|
|
113
|
-
plugin_name = plugin.about&.name || plugin.inspect
|
|
114
115
|
error_message = rules.value.respond_to?(:message) ? rules.value.message : rules.value
|
|
115
116
|
|
|
116
|
-
raise "Plugin `#{plugin_name}' failed to load with error: #{error_message}"
|
|
117
|
+
raise "Plugin `#{plugin_name(plugin)}' failed to load with error: #{error_message}"
|
|
117
118
|
end
|
|
118
119
|
end
|
|
119
120
|
|
|
121
|
+
# Plugin configuration is loaded without validation, so an obsolete key in a plugin's
|
|
122
|
+
# defaults used to surface only later, against the user's own file, once the two had
|
|
123
|
+
# been merged. Report it here, while the path is still the plugin's, and name the
|
|
124
|
+
# plugin: the file lives inside an installed gem, so the fix is to report it upstream.
|
|
125
|
+
# It is a warning whatever the rule's severity: a stale plugin is not the user's
|
|
126
|
+
# mistake and must not stop the run.
|
|
127
|
+
def warn_about_obsolete_config(plugin, config)
|
|
128
|
+
messages = ConfigObsoletion.new(config).messages
|
|
129
|
+
return if messages.empty?
|
|
130
|
+
|
|
131
|
+
warn Rainbow(<<~WARNING).yellow
|
|
132
|
+
Warning: obsolete configuration found in the `#{plugin_name(plugin)}` plugin:
|
|
133
|
+
#{messages.join("\n")}
|
|
134
|
+
WARNING
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def plugin_name(plugin)
|
|
138
|
+
plugin.about&.name || plugin.inspect
|
|
139
|
+
end
|
|
140
|
+
|
|
120
141
|
# This is how we ensure "first-in wins": plugins can override AllCops settings that are
|
|
121
142
|
# set by RuboCop's default configuration, but once a plugin sets an AllCop setting, they
|
|
122
143
|
# have exclusive first-in-wins rights to that setting.
|
data/lib/rubocop/result_cache.rb
CHANGED
|
@@ -33,8 +33,10 @@ module RuboCop
|
|
|
33
33
|
return unless File.exist?(rubocop_cache_dir)
|
|
34
34
|
|
|
35
35
|
# We know the cache entries are 3 level deep, so globing
|
|
36
|
-
# for `*/*/*` only returns files.
|
|
37
|
-
|
|
36
|
+
# for `*/*/*` only returns files. The server keeps its state files at
|
|
37
|
+
# the same depth, under `server`, so they are excluded here.
|
|
38
|
+
files = Dir[File.join(rubocop_cache_dir, '*/*/*')] -
|
|
39
|
+
Dir[File.join(rubocop_cache_dir, CacheConfig::SERVER_DIR, '*/*')]
|
|
38
40
|
return unless requires_file_removal?(files.length, config_store)
|
|
39
41
|
|
|
40
42
|
remove_oldest_files(files, rubocop_cache_dir, verbose)
|
|
@@ -228,7 +230,11 @@ module RuboCop
|
|
|
228
230
|
# don't affect caching.
|
|
229
231
|
def relevant_options_digest(options)
|
|
230
232
|
@relevant_options_digest ||= {}
|
|
231
|
-
|
|
233
|
+
# The memo key must be a snapshot, not the live Hash: callers mutate their options
|
|
234
|
+
# between runs (`--auto-gen-config` adds and removes `:only` between its phases),
|
|
235
|
+
# and a stale entry keyed by the mutated object itself could be returned for options it
|
|
236
|
+
# was not computed from.
|
|
237
|
+
@relevant_options_digest[options.dup] ||= begin
|
|
232
238
|
options = options.reject { |key, _| NON_CHANGING.include?(key) }
|
|
233
239
|
options.to_s.gsub(/[^a-z]+/i, '_')
|
|
234
240
|
end
|
data/lib/rubocop/runner.rb
CHANGED
|
@@ -136,6 +136,9 @@ module RuboCop
|
|
|
136
136
|
# particular run happens to include, or single-file runs (editors, CI
|
|
137
137
|
# sharding) would see different offenses than full runs. The project is
|
|
138
138
|
# rooted at the directory of the configuration that enabled the index.
|
|
139
|
+
#
|
|
140
|
+
# The project's RBS signatures are left out: they declare methods and constants
|
|
141
|
+
# rather than define them, and may declare only part of a namespace.
|
|
139
142
|
def project_index_files(target_files)
|
|
140
143
|
root = @config_store.for_pwd.base_dir_for_path_parameters
|
|
141
144
|
project_files = begin
|
|
@@ -143,6 +146,7 @@ module RuboCop
|
|
|
143
146
|
rescue Errno::ENOENT
|
|
144
147
|
target_files
|
|
145
148
|
end
|
|
149
|
+
project_files = project_files.reject { |file| File.extname(file) == '.rbs' }
|
|
146
150
|
|
|
147
151
|
(project_files | bundled_gem_files).sort
|
|
148
152
|
end
|
|
@@ -367,8 +371,8 @@ module RuboCop
|
|
|
367
371
|
return if team.cops.empty?
|
|
368
372
|
|
|
369
373
|
team.defer_corrections = @options[:diff]
|
|
374
|
+
team.cops.first.offenses_to_check = offenses.reject(&:corrected?)
|
|
370
375
|
|
|
371
|
-
team.cops.first.offenses_to_check = offenses
|
|
372
376
|
yield team
|
|
373
377
|
end
|
|
374
378
|
|
|
@@ -623,6 +627,7 @@ module RuboCop
|
|
|
623
627
|
def mobilize_cop_badge?(badge, config)
|
|
624
628
|
return false if badge.department == :Test
|
|
625
629
|
return false if badge.match_name?(@options[:except])
|
|
630
|
+
return false if config.missing_default_config_for?(badge)
|
|
626
631
|
|
|
627
632
|
if @options[:only]
|
|
628
633
|
badge.match_name?(@options[:only])
|
data/lib/rubocop/server/cache.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'digest'
|
|
4
|
+
require 'fileutils'
|
|
4
5
|
require 'pathname'
|
|
6
|
+
require 'securerandom'
|
|
5
7
|
require 'yaml'
|
|
6
8
|
require_relative '../cache_config'
|
|
7
9
|
require_relative '../config_finder'
|
|
@@ -79,7 +81,7 @@ module RuboCop
|
|
|
79
81
|
CacheConfig.root_dir_from_toplevel_config
|
|
80
82
|
end
|
|
81
83
|
|
|
82
|
-
File.expand_path(File.join(cache_root_dir,
|
|
84
|
+
File.expand_path(File.join(cache_root_dir, CacheConfig::SERVER_DIR))
|
|
83
85
|
end
|
|
84
86
|
|
|
85
87
|
def port_path
|
|
@@ -110,10 +112,19 @@ module RuboCop
|
|
|
110
112
|
dir.join('stderr')
|
|
111
113
|
end
|
|
112
114
|
|
|
115
|
+
def pid
|
|
116
|
+
pid = pid_path(create_dir: false).read.to_i
|
|
117
|
+
pid if pid.positive?
|
|
118
|
+
rescue Errno::ENOENT, Errno::EACCES, Errno::EPERM, Errno::EROFS, Errno::ENAMETOOLONG,
|
|
119
|
+
Errno::ENOTDIR
|
|
120
|
+
nil
|
|
121
|
+
end
|
|
122
|
+
|
|
113
123
|
def pid_running?
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
124
|
+
return false unless (pid = self.pid)
|
|
125
|
+
|
|
126
|
+
Process.kill(0, pid) == 1
|
|
127
|
+
rescue Errno::ESRCH, Errno::EPERM
|
|
117
128
|
false
|
|
118
129
|
end
|
|
119
130
|
|
|
@@ -134,7 +145,7 @@ module RuboCop
|
|
|
134
145
|
pid_path.write(Process.pid)
|
|
135
146
|
yield
|
|
136
147
|
ensure
|
|
137
|
-
|
|
148
|
+
remove_dir
|
|
138
149
|
end
|
|
139
150
|
|
|
140
151
|
def write_status_file(status)
|
|
@@ -183,6 +194,14 @@ module RuboCop
|
|
|
183
194
|
require 'yaml'
|
|
184
195
|
YAML.safe_load(yaml_code, permitted_classes: [Regexp, Symbol], aliases: true) || {}
|
|
185
196
|
end
|
|
197
|
+
|
|
198
|
+
def remove_dir
|
|
199
|
+
removed_dir_path = "#{dir_path}.#{SecureRandom.hex(8)}.removed"
|
|
200
|
+
File.rename(dir_path, removed_dir_path)
|
|
201
|
+
FileUtils.rm_rf(removed_dir_path)
|
|
202
|
+
rescue Errno::ENOENT
|
|
203
|
+
nil
|
|
204
|
+
end
|
|
186
205
|
end
|
|
187
206
|
end
|
|
188
207
|
end
|
data/lib/rubocop/todo_audit.rb
CHANGED
|
@@ -21,8 +21,8 @@ module RuboCop
|
|
|
21
21
|
entries = todo_exclude_entries
|
|
22
22
|
return [] if entries.empty?
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
entries.reject { |entry|
|
|
24
|
+
@todo_entries = entries
|
|
25
|
+
entries.reject { |entry| needed?(entry) }
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def todo_file
|
|
@@ -59,37 +59,83 @@ module RuboCop
|
|
|
59
59
|
Cop::Registry.global.contains_cop_matching?([cop_name])
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
# An entry is needed when any expanded path still reports an offense for
|
|
63
|
+
# its cop. Stop at the first hit so live glob entries skip most matches.
|
|
64
|
+
def needed?(entry)
|
|
65
|
+
expand_path(entry.path).any? { |file| offending_cops(file).include?(entry.cop_name) }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def offending_cops(file)
|
|
69
|
+
@offending_cops ||= {}
|
|
70
|
+
@offending_cops[file] ||= inspect_file(file).to_set(&:cop_name)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def expand_path(path)
|
|
74
|
+
absolute_path = absolute(path)
|
|
75
|
+
files = File.file?(absolute_path) ? [absolute_path] : []
|
|
76
|
+
return files unless PathUtil.glob?(path)
|
|
67
77
|
|
|
68
|
-
files.
|
|
69
|
-
|
|
70
|
-
[file, offenses.to_set(&:cop_name)]
|
|
78
|
+
files | target_files(path).select do |file|
|
|
79
|
+
PathUtil.match_path?(absolute_path, file)
|
|
71
80
|
end
|
|
72
81
|
end
|
|
73
82
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
83
|
+
# Scan from the longest glob-free prefix of the entry as written, so a
|
|
84
|
+
# glob in any directory segment (e.g. `**/models/*.rb`) is covered.
|
|
85
|
+
# Only the entry's own segments are inspected; metacharacters in the
|
|
86
|
+
# todo file's parent directories never move the scan root.
|
|
87
|
+
def target_files(path)
|
|
88
|
+
directory = scan_root(path)
|
|
89
|
+
@target_files ||= {}
|
|
90
|
+
@target_files[directory] ||= TargetFinder.new(@config_store, @options)
|
|
91
|
+
.target_files_in_dir(directory)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def scan_root(path)
|
|
95
|
+
segments = path.split('/', -1)
|
|
96
|
+
literal = segments.take_while { |segment| !PathUtil.glob?(segment) }
|
|
97
|
+
prefix = literal.join('/')
|
|
98
|
+
prefix = '/' if prefix.empty? && path.start_with?('/')
|
|
99
|
+
absolute(prefix.empty? ? '.' : prefix)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def inspect_file(file)
|
|
103
|
+
config = audit_config(@config_store.for_file(file))
|
|
104
|
+
team = Cop::Team.mobilize(todo_cops, config, @options.merge(autocorrect: false))
|
|
77
105
|
|
|
78
106
|
processed_source = ProcessedSource.from_file(
|
|
79
107
|
file, config.target_ruby_version, parser_engine: config.parser_engine
|
|
80
108
|
)
|
|
81
109
|
processed_source.config = config
|
|
110
|
+
# CommentConfig reads this registry to recognize cops disabled in the
|
|
111
|
+
# config. A filtered registry would treat `# rubocop:enable` of such a
|
|
112
|
+
# cop as redundant and keep a stale todo entry.
|
|
82
113
|
processed_source.registry = Cop::Registry.global
|
|
83
114
|
|
|
84
115
|
team.investigate(processed_source).offenses.reject(&:disabled?)
|
|
85
116
|
end
|
|
86
117
|
|
|
118
|
+
# Registry limited to cops named in the todo, so each file only pays for
|
|
119
|
+
# the audits that can keep an entry.
|
|
120
|
+
def todo_cops
|
|
121
|
+
@todo_cops ||= begin
|
|
122
|
+
names = @todo_entries.map(&:cop_name).uniq
|
|
123
|
+
Cop::Registry.global.filter_by_badge { |badge| badge.match_name?(names) }
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
87
127
|
# A copy of the configuration with the todo exclusions removed for the
|
|
88
128
|
# audited cops, so their offenses in the listed files become visible.
|
|
89
|
-
|
|
129
|
+
# Memoized per underlying `Config` so cop lookups stay warm across files.
|
|
130
|
+
def audit_config(config)
|
|
131
|
+
@audit_configs ||= {}.compare_by_identity
|
|
132
|
+
@audit_configs[config] ||= build_audit_config(config)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def build_audit_config(config)
|
|
90
136
|
hash = config.to_hash.dup
|
|
91
137
|
|
|
92
|
-
|
|
138
|
+
@todo_entries.group_by(&:cop_name).each do |cop_name, cop_entries|
|
|
93
139
|
cop_config = hash[cop_name]
|
|
94
140
|
next unless cop_config.is_a?(Hash) && cop_config['Exclude'].is_a?(Array)
|
|
95
141
|
|
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: 1.92.
|
|
4
|
+
version: 1.92.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bozhidar Batsov
|
|
@@ -196,6 +196,7 @@ files:
|
|
|
196
196
|
- config/obsoletion.yml
|
|
197
197
|
- exe/rubocop
|
|
198
198
|
- lib/rubocop.rb
|
|
199
|
+
- lib/rubocop/#directive_comment.rb#
|
|
199
200
|
- lib/rubocop/arguments_env.rb
|
|
200
201
|
- lib/rubocop/arguments_file.rb
|
|
201
202
|
- lib/rubocop/ast_aliases.rb
|
|
@@ -1157,7 +1158,7 @@ licenses:
|
|
|
1157
1158
|
- MIT
|
|
1158
1159
|
metadata:
|
|
1159
1160
|
homepage_uri: https://rubocop.org/
|
|
1160
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.92.
|
|
1161
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.92.3
|
|
1161
1162
|
source_code_uri: https://github.com/rubocop/rubocop/
|
|
1162
1163
|
documentation_uri: https://docs.rubocop.org/rubocop/1.92/
|
|
1163
1164
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|
|
@@ -1176,7 +1177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
1176
1177
|
- !ruby/object:Gem::Version
|
|
1177
1178
|
version: '0'
|
|
1178
1179
|
requirements: []
|
|
1179
|
-
rubygems_version:
|
|
1180
|
+
rubygems_version: 4.0.16
|
|
1180
1181
|
specification_version: 4
|
|
1181
1182
|
summary: Automatic Ruby code style checking tool.
|
|
1182
1183
|
test_files: []
|