rubocop 1.92.2 → 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 -0
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +9 -19
- 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 +14 -6
- 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 +5 -5
- data/lib/rubocop/cop/layout/extra_spacing.rb +5 -6
- 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/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/single_line_block_chain.rb +11 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +15 -4
- 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 +7 -1
- 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/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 +45 -3
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +18 -0
- 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/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 +1 -1
- 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_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/trailing_comma.rb +3 -1
- 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 +8 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +6 -1
- data/lib/rubocop/cop/style/class_and_module_children.rb +8 -12
- 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 +30 -10
- data/lib/rubocop/cop/style/explicit_block_argument.rb +19 -4
- 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_conversion.rb +3 -1
- data/lib/rubocop/cop/style/hash_fetch_chain.rb +1 -1
- data/lib/rubocop/cop/style/hash_lookup_method.rb +11 -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 +11 -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/operator_method_call.rb +23 -24
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -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/redundant_array_constructor.rb +4 -1
- data/lib/rubocop/cop/style/redundant_begin.rb +96 -16
- data/lib/rubocop/cop/style/redundant_each.rb +8 -1
- 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_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 +5 -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 +16 -7
- 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/result_cache.rb +9 -3
- data/lib/rubocop/runner.rb +5 -0
- 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
|
@@ -98,9 +98,7 @@ module RuboCop
|
|
|
98
98
|
|
|
99
99
|
syms = node.children.map do |c|
|
|
100
100
|
if c.dsym_type?
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
":#{trim_string_interpolation_escape_character(string_literal)}"
|
|
101
|
+
":#{build_interpolated_string_literal(c)}"
|
|
104
102
|
else
|
|
105
103
|
to_symbol_literal(c.value.to_s)
|
|
106
104
|
end
|
|
@@ -141,9 +141,7 @@ module RuboCop
|
|
|
141
141
|
|
|
142
142
|
words = node.children.map do |word|
|
|
143
143
|
if word.dstr_type?
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
trim_string_interpolation_escape_character(string_literal)
|
|
144
|
+
build_interpolated_string_literal(word)
|
|
147
145
|
else
|
|
148
146
|
to_string_literal(word.children[0])
|
|
149
147
|
end
|
data/lib/rubocop/cop/util.rb
CHANGED
|
@@ -32,6 +32,15 @@ module RuboCop
|
|
|
32
32
|
VARIABLE_ASSIGNMENT_TYPE, REGEXP_NAMED_CAPTURE_TYPE, PATTERN_MATCH_VARIABLE_TYPE
|
|
33
33
|
].freeze
|
|
34
34
|
|
|
35
|
+
# Ruby assigns a named capture to a local variable only when its name is a valid
|
|
36
|
+
# local variable name, so `(?<Foo>...)` and `(?<if>...)` declare no variable.
|
|
37
|
+
LOCAL_VARIABLE_NAME = /\A(?![[:upper:]\p{Lt}])[a-z_\P{ASCII}][a-zA-Z0-9_\P{ASCII}]*\z/.freeze
|
|
38
|
+
RESERVED_WORDS = %w[
|
|
39
|
+
__ENCODING__ __FILE__ __LINE__ BEGIN END alias and begin break case class def do else
|
|
40
|
+
elsif end ensure false for if in module next nil not or redo rescue retry return self
|
|
41
|
+
super then true undef unless until when while yield
|
|
42
|
+
].to_set.freeze
|
|
43
|
+
|
|
35
44
|
ARGUMENT_DECLARATION_TYPES = [
|
|
36
45
|
:arg, :optarg, :restarg,
|
|
37
46
|
:kwarg, :kwoptarg, :kwrestarg,
|
|
@@ -192,7 +201,11 @@ module RuboCop
|
|
|
192
201
|
def regexp_captured_names(node)
|
|
193
202
|
regexp = node.to_regexp
|
|
194
203
|
|
|
195
|
-
regexp.
|
|
204
|
+
regexp.names.select { |name| local_variable_name?(name) }
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def local_variable_name?(name)
|
|
208
|
+
LOCAL_VARIABLE_NAME.match?(name) && !RESERVED_WORDS.include?(name)
|
|
196
209
|
end
|
|
197
210
|
|
|
198
211
|
def process_variable_operator_assignment(node)
|
|
@@ -297,7 +297,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
|
297
297
|
|
|
298
298
|
def references(cop, see_objects) # rubocop:disable Metrics/AbcSize
|
|
299
299
|
cop_config = config.for_cop(cop)
|
|
300
|
-
urls = RuboCop::Cop::MessageAnnotator.new(config, cop.
|
|
300
|
+
urls = RuboCop::Cop::MessageAnnotator.new(config, cop.cop_name, cop_config, {}).urls
|
|
301
301
|
return '' if urls.empty? && see_objects.empty?
|
|
302
302
|
|
|
303
303
|
content = cop_subsection('References', cop)
|
|
@@ -78,7 +78,8 @@ module RuboCop
|
|
|
78
78
|
# in which case all cops are returned for compatibility.
|
|
79
79
|
return Cop::Registry.all if @config_store.nil?
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
config = @config_store.for_file(file)
|
|
82
|
+
registry_for(config).enabled(config)
|
|
82
83
|
end
|
|
83
84
|
|
|
84
85
|
def relevant_for_output?(options, target_offenses)
|
|
@@ -100,14 +101,20 @@ module RuboCop
|
|
|
100
101
|
|
|
101
102
|
# Filtering by badge keeps lazy-loaded cops unloaded; `Registry#enabled` then loads only
|
|
102
103
|
# the enabled cops, the same set the runner mobilizes.
|
|
103
|
-
def
|
|
104
|
-
@
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
options[:only].nil? || badge.match_name?(options[:only])
|
|
104
|
+
def registry_for(config)
|
|
105
|
+
@registry_by_config ||= {}.compare_by_identity
|
|
106
|
+
@registry_by_config[config] ||= Cop::Registry.global.filter_by_badge(options) do |badge|
|
|
107
|
+
mobilized_cop_badge?(badge, config)
|
|
108
108
|
end
|
|
109
109
|
end
|
|
110
110
|
|
|
111
|
+
def mobilized_cop_badge?(badge, config)
|
|
112
|
+
return false if badge.department == :Test || badge.match_name?(options[:except])
|
|
113
|
+
return false if config.missing_default_config_for?(badge)
|
|
114
|
+
|
|
115
|
+
options[:only].nil? || badge.match_name?(options[:only])
|
|
116
|
+
end
|
|
117
|
+
|
|
111
118
|
def classname_attribute_value(file)
|
|
112
119
|
@classname_attribute_value_cache ||= Hash.new do |hash, key|
|
|
113
120
|
hash[key] = key.delete_suffix('.rb').gsub("#{PathUtil.pwd}/", '').tr('/', '.')
|
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
|
|
@@ -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: []
|