rubocop 1.86.1 → 1.86.2
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/config/default.yml +8 -1
- data/lib/rubocop/cli/command/auto_generate_config.rb +27 -1
- data/lib/rubocop/cli/command/list_enabled_cops_for.rb +40 -0
- data/lib/rubocop/cli/command/show_docs_url.rb +3 -7
- data/lib/rubocop/cli/command/suggest_extensions.rb +1 -1
- data/lib/rubocop/cli.rb +4 -7
- data/lib/rubocop/comment_config.rb +12 -15
- data/lib/rubocop/cop/autocorrect_logic.rb +2 -1
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +1 -5
- data/lib/rubocop/cop/correctors.rb +28 -0
- data/lib/rubocop/cop/exclude_limit.rb +31 -5
- data/lib/rubocop/cop/gemspec/require_mfa.rb +3 -3
- data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +26 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +3 -13
- data/lib/rubocop/cop/lint/require_relative_self_path.rb +2 -0
- data/lib/rubocop/cop/lint/useless_assignment.rb +3 -8
- data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +18 -7
- data/lib/rubocop/cop/mixin/configurable_max.rb +6 -5
- data/lib/rubocop/cop/mixin.rb +85 -0
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/offense.rb +8 -0
- data/lib/rubocop/cop/registry.rb +19 -24
- data/lib/rubocop/cop/style/copyright.rb +21 -10
- data/lib/rubocop/cop/style/date_time.rb +2 -2
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +6 -1
- data/lib/rubocop/cop/style/hash_lookup_method.rb +12 -7
- data/lib/rubocop/cop/style/if_inside_else.rb +15 -2
- data/lib/rubocop/cop/style/module_member_existence_check.rb +6 -3
- data/lib/rubocop/cop/style/reduce_to_hash.rb +16 -0
- data/lib/rubocop/cop/style/redundant_self.rb +2 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +29 -0
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +4 -2
- data/lib/rubocop/cop/style/symbol_proc.rb +3 -3
- data/lib/rubocop/cop/style/while_until_modifier.rb +16 -0
- data/lib/rubocop/cop/team.rb +86 -35
- data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -1
- data/lib/rubocop/lsp/runtime.rb +1 -2
- data/lib/rubocop/options.rb +8 -4
- data/lib/rubocop/rspec/shared_contexts.rb +21 -0
- data/lib/rubocop/runner.rb +77 -55
- data/lib/rubocop/target_finder.rb +13 -6
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +7 -96
- metadata +5 -2
data/lib/rubocop/cop/team.rb
CHANGED
|
@@ -11,6 +11,9 @@ module RuboCop
|
|
|
11
11
|
# (unless autocorrections happened).
|
|
12
12
|
# rubocop:disable Metrics/ClassLength
|
|
13
13
|
class Team
|
|
14
|
+
InvestigationResult = Struct.new(:report, :corrector)
|
|
15
|
+
private_constant :InvestigationResult
|
|
16
|
+
|
|
14
17
|
# @return [Team]
|
|
15
18
|
def self.new(cop_or_classes, config, options = {})
|
|
16
19
|
# Support v0 api:
|
|
@@ -89,31 +92,25 @@ module RuboCop
|
|
|
89
92
|
|
|
90
93
|
# @return [Commissioner::InvestigationReport]
|
|
91
94
|
def investigate(processed_source, offset: 0, original: processed_source)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
# To speed things up, run autocorrecting cops by themselves, and only
|
|
97
|
-
# run the other cops when no corrections are left
|
|
98
|
-
on_duty = roundup_relevant_cops(processed_source)
|
|
95
|
+
result = investigate_with_corrector(processed_source, offset: offset, original: original)
|
|
96
|
+
autocorrect(processed_source, result.corrector)
|
|
97
|
+
result.report
|
|
98
|
+
end
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
# @return [Array<Offense>]
|
|
101
|
+
def investigate_fragments(fragments, original:)
|
|
102
|
+
@updated_source_file = false
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
report = report.merge(investigate_partial(other_cops, processed_source,
|
|
109
|
-
offset: offset, original: original))
|
|
110
|
-
end
|
|
104
|
+
offenses, errors, warnings, corrector =
|
|
105
|
+
fragments.each_with_object([[], [], [], nil]) do |fragment, data|
|
|
106
|
+
investigate_fragment(fragment, original, data)
|
|
107
|
+
end
|
|
111
108
|
|
|
112
|
-
|
|
109
|
+
autocorrect(original, corrector)
|
|
110
|
+
@errors = errors
|
|
111
|
+
@warnings = warnings
|
|
113
112
|
|
|
114
|
-
|
|
115
|
-
ensure
|
|
116
|
-
@ready = false
|
|
113
|
+
offenses
|
|
117
114
|
end
|
|
118
115
|
|
|
119
116
|
# @deprecated
|
|
@@ -136,14 +133,13 @@ module RuboCop
|
|
|
136
133
|
|
|
137
134
|
private
|
|
138
135
|
|
|
139
|
-
def autocorrect(processed_source,
|
|
136
|
+
def autocorrect(processed_source, corrector)
|
|
140
137
|
@updated_source_file = false
|
|
141
138
|
return unless autocorrect?
|
|
142
|
-
return
|
|
139
|
+
return unless corrector
|
|
140
|
+
return if corrector.empty?
|
|
143
141
|
|
|
144
|
-
new_source =
|
|
145
|
-
|
|
146
|
-
return unless new_source
|
|
142
|
+
new_source = corrector.rewrite
|
|
147
143
|
|
|
148
144
|
if @options[:stdin]
|
|
149
145
|
# holds source read in from stdin, when --stdin option is used
|
|
@@ -174,6 +170,54 @@ module RuboCop
|
|
|
174
170
|
commissioner.investigate(processed_source, offset: offset, original: original)
|
|
175
171
|
end
|
|
176
172
|
|
|
173
|
+
def investigate_with_corrector(processed_source, offset:, original:)
|
|
174
|
+
be_ready
|
|
175
|
+
|
|
176
|
+
# The autocorrection process may have to be repeated multiple times
|
|
177
|
+
# until there are no corrections left to perform
|
|
178
|
+
# To speed things up, run autocorrecting cops by themselves, and only
|
|
179
|
+
# run the other cops when no corrections are left
|
|
180
|
+
on_duty = roundup_relevant_cops(processed_source)
|
|
181
|
+
|
|
182
|
+
autocorrect_cops, other_cops = on_duty.partition(&:autocorrect?)
|
|
183
|
+
report = investigate_partial(autocorrect_cops, processed_source,
|
|
184
|
+
offset: offset, original: original)
|
|
185
|
+
|
|
186
|
+
corrector = collated_corrector(report, offset: offset, original: original)
|
|
187
|
+
|
|
188
|
+
unless corrector
|
|
189
|
+
# If we corrected some errors, another round of inspection will be
|
|
190
|
+
# done, and any other offenses will be caught then, so only need
|
|
191
|
+
# to check other_cops if no correction was done
|
|
192
|
+
report = report.merge(investigate_partial(other_cops, processed_source,
|
|
193
|
+
offset: offset, original: original))
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
process_errors(processed_source.path, report.errors)
|
|
197
|
+
|
|
198
|
+
InvestigationResult.new(report, corrector)
|
|
199
|
+
ensure
|
|
200
|
+
@ready = false
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def investigate_fragment(fragment, original, data)
|
|
204
|
+
offenses, errors, warnings, corrector = data
|
|
205
|
+
result = investigate_with_corrector(
|
|
206
|
+
fragment[:processed_source],
|
|
207
|
+
offset: fragment[:offset],
|
|
208
|
+
original: original
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
offenses.concat(result.report.offenses)
|
|
212
|
+
if result.corrector
|
|
213
|
+
corrector ||= Corrector.new(original)
|
|
214
|
+
merge_corrector!(corrector, result.corrector, offset: 0)
|
|
215
|
+
data[3] = corrector
|
|
216
|
+
end
|
|
217
|
+
errors.concat(@errors)
|
|
218
|
+
warnings.concat(@warnings)
|
|
219
|
+
end
|
|
220
|
+
|
|
177
221
|
# @return [Array<cop>]
|
|
178
222
|
def roundup_relevant_cops(processed_source)
|
|
179
223
|
cops.select do |cop|
|
|
@@ -200,28 +244,35 @@ module RuboCop
|
|
|
200
244
|
cop.class.support_target_rails_version?(cop.target_rails_version)
|
|
201
245
|
end
|
|
202
246
|
|
|
203
|
-
def
|
|
247
|
+
def collated_corrector(report, offset:, original:)
|
|
248
|
+
return unless autocorrect?
|
|
249
|
+
return if report.processed_source.parser_error
|
|
250
|
+
|
|
204
251
|
corrector = collate_corrections(report, offset: offset, original: original)
|
|
205
252
|
|
|
206
|
-
corrector
|
|
253
|
+
corrector unless corrector.empty?
|
|
207
254
|
end
|
|
208
255
|
|
|
209
256
|
def collate_corrections(report, offset:, original:)
|
|
210
257
|
corrector = Corrector.new(original)
|
|
211
258
|
|
|
212
259
|
each_corrector(report) do |to_merge|
|
|
213
|
-
|
|
214
|
-
if corrector.source_buffer == to_merge.source_buffer
|
|
215
|
-
corrector.merge!(to_merge)
|
|
216
|
-
else
|
|
217
|
-
corrector.import!(to_merge, offset: offset)
|
|
218
|
-
end
|
|
219
|
-
end
|
|
260
|
+
merge_corrector!(corrector, to_merge, offset: offset)
|
|
220
261
|
end
|
|
221
262
|
|
|
222
263
|
corrector
|
|
223
264
|
end
|
|
224
265
|
|
|
266
|
+
def merge_corrector!(corrector, to_merge, offset:)
|
|
267
|
+
suppress_clobbering do
|
|
268
|
+
if corrector.source_buffer == to_merge.source_buffer
|
|
269
|
+
corrector.merge!(to_merge)
|
|
270
|
+
else
|
|
271
|
+
corrector.import!(to_merge, offset: offset)
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
|
|
225
276
|
def each_corrector(report)
|
|
226
277
|
skips = Set.new
|
|
227
278
|
report.cop_reports.each do |cop_report|
|
|
@@ -131,6 +131,9 @@ module RuboCop
|
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
def set_max(cfg, cop_name)
|
|
134
|
+
exclude_limits = RuboCop::ExcludeLimit.read_limits(cop_name)
|
|
135
|
+
cfg[:exclude_limit] = exclude_limits unless exclude_limits.empty?
|
|
136
|
+
|
|
134
137
|
return unless cfg[:exclude_limit]
|
|
135
138
|
|
|
136
139
|
cfg.merge!(cfg[:exclude_limit]) if should_set_max?(cop_name)
|
|
@@ -192,7 +195,7 @@ module RuboCop
|
|
|
192
195
|
next unless value.is_a?(Array)
|
|
193
196
|
next if value.empty?
|
|
194
197
|
|
|
195
|
-
value.map
|
|
198
|
+
value = value.map { |v| v.nil? ? '~' : v } # Change nil back to ~ as in the YAML file.
|
|
196
199
|
output_buffer.puts "# #{param}: #{value.uniq.join(', ')}"
|
|
197
200
|
end
|
|
198
201
|
end
|
data/lib/rubocop/lsp/runtime.rb
CHANGED
|
@@ -23,7 +23,6 @@ module RuboCop
|
|
|
23
23
|
RuboCop::LSP.enable
|
|
24
24
|
|
|
25
25
|
@runner = RuboCop::Lsp::StdinRunner.new(config_store)
|
|
26
|
-
@cop_registry = RuboCop::Cop::Registry.global.to_h
|
|
27
26
|
|
|
28
27
|
@safe_autocorrect = true
|
|
29
28
|
@lint_mode = false
|
|
@@ -63,7 +62,7 @@ module RuboCop
|
|
|
63
62
|
document_encoding,
|
|
64
63
|
offense,
|
|
65
64
|
path,
|
|
66
|
-
|
|
65
|
+
RuboCop::Cop::Registry.global.find_by_cop_name(offense.cop_name),
|
|
67
66
|
processed_source
|
|
68
67
|
).to_lsp_diagnostic(config)
|
|
69
68
|
end
|
data/lib/rubocop/options.rb
CHANGED
|
@@ -16,7 +16,9 @@ module RuboCop
|
|
|
16
16
|
'root of the project. RuboCop will use this path to determine which ' \
|
|
17
17
|
'cops are enabled (via eg. Include/Exclude), and so that certain cops ' \
|
|
18
18
|
'like Naming/FileName can be checked.'
|
|
19
|
-
EXITING_OPTIONS = %i[
|
|
19
|
+
EXITING_OPTIONS = %i[
|
|
20
|
+
version verbose_version show_cops list_enabled_cops_for show_docs_url lsp mcp
|
|
21
|
+
].freeze
|
|
20
22
|
DEFAULT_MAXIMUM_EXCLUSION_ITEMS = 15
|
|
21
23
|
|
|
22
24
|
def initialize
|
|
@@ -236,6 +238,7 @@ module RuboCop
|
|
|
236
238
|
def add_additional_modes(opts)
|
|
237
239
|
section(opts, 'Additional Modes') do
|
|
238
240
|
option(opts, '-L', '--list-target-files')
|
|
241
|
+
option(opts, '--list-enabled-cops-for PATH')
|
|
239
242
|
option(opts, '--show-cops [COP1,COP2,...]') do |list|
|
|
240
243
|
@options[:show_cops] = list.nil? ? [] : list.split(',')
|
|
241
244
|
end
|
|
@@ -474,8 +477,7 @@ module RuboCop
|
|
|
474
477
|
end
|
|
475
478
|
|
|
476
479
|
def invalid_arguments_for_parallel
|
|
477
|
-
[('
|
|
478
|
-
('-F/--fail-fast' if @options.key?(:fail_fast)),
|
|
480
|
+
[('-F/--fail-fast' if @options.key?(:fail_fast)),
|
|
479
481
|
('--profile' if @options[:profile]),
|
|
480
482
|
('--memory' if @options[:memory]),
|
|
481
483
|
('--cache false' if @options > { cache: 'false' })].compact
|
|
@@ -599,7 +601,7 @@ module RuboCop
|
|
|
599
601
|
display_only_correctable: ['Only output correctable offense messages.'],
|
|
600
602
|
display_only_safe_correctable: ['Only output safe-correctable offense messages',
|
|
601
603
|
'when combined with --display-only-correctable.'],
|
|
602
|
-
show_cops: ['
|
|
604
|
+
show_cops: ['Show the given cops, or all cops by',
|
|
603
605
|
'default, and their configurations for the',
|
|
604
606
|
'current directory.',
|
|
605
607
|
'You can use `*` as a wildcard.'],
|
|
@@ -628,6 +630,8 @@ module RuboCop
|
|
|
628
630
|
'autocorrected source. This is especially useful',
|
|
629
631
|
'when combined with --autocorrect and --stdin.'],
|
|
630
632
|
list_target_files: 'List all files RuboCop will inspect.',
|
|
633
|
+
list_enabled_cops_for: ['List which cops will inspect a given file or',
|
|
634
|
+
'directory.'],
|
|
631
635
|
autocorrect: 'Autocorrect offenses (only when it\'s safe).',
|
|
632
636
|
auto_correct: '(same, deprecated)',
|
|
633
637
|
safe_auto_correct: '(same, deprecated)',
|
|
@@ -212,6 +212,27 @@ RSpec.shared_context 'lsp' do
|
|
|
212
212
|
end
|
|
213
213
|
end
|
|
214
214
|
|
|
215
|
+
RSpec.shared_context 'with exclude limit tracking' do
|
|
216
|
+
around do |example|
|
|
217
|
+
Dir.mktmpdir('rubocop-exclude-limit') do |dir|
|
|
218
|
+
RuboCop::ExcludeLimit.tmp_dir = Pathname.new(dir)
|
|
219
|
+
example.run
|
|
220
|
+
ensure
|
|
221
|
+
RuboCop::ExcludeLimit.tmp_dir = nil
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# Reads exclude_limit values from the tmp files written by ExcludeLimit.
|
|
226
|
+
# Returns a hash like { 'Max' => 81 } or nil if no values were written.
|
|
227
|
+
def read_exclude_limit(cop, parameter_name = nil)
|
|
228
|
+
if parameter_name
|
|
229
|
+
read_exclude_limit(cop)[parameter_name]
|
|
230
|
+
else
|
|
231
|
+
RuboCop::ExcludeLimit.read_limits(cop.class.badge.to_s)
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
215
236
|
RSpec.shared_context 'ruby 2.0' do
|
|
216
237
|
# Prism supports parsing Ruby 3.3+.
|
|
217
238
|
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 2.0 }
|
data/lib/rubocop/runner.rb
CHANGED
|
@@ -62,6 +62,8 @@ module RuboCop
|
|
|
62
62
|
@errors = []
|
|
63
63
|
@warnings = []
|
|
64
64
|
@aborting = false
|
|
65
|
+
@inspected_files = []
|
|
66
|
+
@report_queue = {}
|
|
65
67
|
end
|
|
66
68
|
|
|
67
69
|
def run(paths)
|
|
@@ -73,7 +75,6 @@ module RuboCop
|
|
|
73
75
|
if @options[:list_target_files]
|
|
74
76
|
list_files(target_files)
|
|
75
77
|
else
|
|
76
|
-
warm_cache(target_files) if @options[:parallel]
|
|
77
78
|
inspect_files(target_files)
|
|
78
79
|
end
|
|
79
80
|
rescue Interrupt
|
|
@@ -90,21 +91,6 @@ module RuboCop
|
|
|
90
91
|
|
|
91
92
|
private
|
|
92
93
|
|
|
93
|
-
# Warms up the RuboCop cache by forking a suitable number of RuboCop
|
|
94
|
-
# instances that each inspects its allotted group of files.
|
|
95
|
-
def warm_cache(target_files)
|
|
96
|
-
saved_options = @options.dup
|
|
97
|
-
if target_files.length <= 1
|
|
98
|
-
puts 'Skipping parallel inspection: only a single file needs inspection' if @options[:debug]
|
|
99
|
-
return
|
|
100
|
-
end
|
|
101
|
-
puts 'Running parallel inspection' if @options[:debug]
|
|
102
|
-
%i[autocorrect safe_autocorrect].each { |opt| @options[opt] = false }
|
|
103
|
-
Parallel.each(target_files) { |target_file| file_offenses(target_file) }
|
|
104
|
-
ensure
|
|
105
|
-
@options = saved_options
|
|
106
|
-
end
|
|
107
|
-
|
|
108
94
|
def find_target_files(paths)
|
|
109
95
|
target_finder = TargetFinder.new(@config_store, @options)
|
|
110
96
|
mode = if @options[:only_recognized_file_types]
|
|
@@ -116,12 +102,15 @@ module RuboCop
|
|
|
116
102
|
target_files.each(&:freeze).freeze
|
|
117
103
|
end
|
|
118
104
|
|
|
119
|
-
def inspect_files(files)
|
|
120
|
-
inspected_files = []
|
|
121
|
-
|
|
105
|
+
def inspect_files(files) # rubocop:disable Metrics/AbcSize
|
|
122
106
|
formatter_set.started(files)
|
|
107
|
+
file_iterator(files) do |file|
|
|
108
|
+
offenses = process_file(file)
|
|
109
|
+
succeeded = offenses.none? { |o| considered_failure?(o) && offense_displayed?(o) }
|
|
110
|
+
raise Parallel::Break if @options[:fail_fast] && !succeeded
|
|
123
111
|
|
|
124
|
-
|
|
112
|
+
[offenses, succeeded]
|
|
113
|
+
end
|
|
125
114
|
ensure
|
|
126
115
|
# OPTIMIZE: Calling `ResultCache.cleanup` takes time. This optimization
|
|
127
116
|
# mainly targets editors that integrates RuboCop. When RuboCop is run
|
|
@@ -129,23 +118,74 @@ module RuboCop
|
|
|
129
118
|
if files.size > 1 && cached_run?
|
|
130
119
|
ResultCache.cleanup(@config_store, @options[:debug], @options[:cache_root])
|
|
131
120
|
end
|
|
132
|
-
|
|
133
|
-
formatter_set.finished(inspected_files.freeze)
|
|
121
|
+
formatter_set.finished(@inspected_files.freeze)
|
|
134
122
|
formatter_set.close_output_files
|
|
135
123
|
end
|
|
136
124
|
|
|
137
|
-
def
|
|
138
|
-
|
|
139
|
-
offenses = process_file(file)
|
|
140
|
-
yield file
|
|
125
|
+
def file_iterator(files, &block)
|
|
126
|
+
all_passed = true
|
|
141
127
|
|
|
142
|
-
|
|
143
|
-
|
|
128
|
+
on_start = ->(file, _index) { file_started(file) }
|
|
129
|
+
on_finish = lambda do |file, index, (offenses, passed)|
|
|
130
|
+
all_passed &&= passed
|
|
131
|
+
finished_report(file, index, offenses)
|
|
132
|
+
end
|
|
144
133
|
|
|
145
|
-
|
|
146
|
-
|
|
134
|
+
if run_in_parallel?(files)
|
|
135
|
+
parallel_file_iterator(files, on_start, on_finish, &block)
|
|
136
|
+
else
|
|
137
|
+
serial_file_iterator(files, on_start, on_finish, &block)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
process_remaining_report_queue
|
|
147
141
|
|
|
148
|
-
|
|
142
|
+
all_passed
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def finished_report(file, index, offenses)
|
|
146
|
+
@report_queue[index] = [file, offenses]
|
|
147
|
+
@next_index_to_report ||= 0
|
|
148
|
+
while @report_queue.key?(@next_index_to_report)
|
|
149
|
+
process_report_queue_entry(@next_index_to_report)
|
|
150
|
+
@next_index_to_report += 1
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def process_report_queue_entry(index)
|
|
155
|
+
file, offenses = @report_queue.delete(index)
|
|
156
|
+
file_finished(file, offenses)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def process_remaining_report_queue
|
|
160
|
+
@report_queue.keys.sort.each do |index|
|
|
161
|
+
process_report_queue_entry(index)
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def run_in_parallel?(files)
|
|
166
|
+
return false if @options[:auto_gen_config]
|
|
167
|
+
return false unless @options[:parallel]
|
|
168
|
+
|
|
169
|
+
if files.size <= 1
|
|
170
|
+
puts 'Skipping parallel inspection: only a single file needs inspection' if @options[:debug]
|
|
171
|
+
return false
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
puts 'Running parallel inspection' if @options[:debug]
|
|
175
|
+
true
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def parallel_file_iterator(files, on_start, on_finish, &block)
|
|
179
|
+
Parallel.each(files, start: on_start, finish: on_finish, &block)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def serial_file_iterator(files, on_start, on_finish, &block)
|
|
183
|
+
files.each_with_index do |file, index|
|
|
184
|
+
on_start.call(file, index)
|
|
185
|
+
result = yield file
|
|
186
|
+
on_finish.call(file, index, result)
|
|
187
|
+
rescue Parallel::Break
|
|
188
|
+
break
|
|
149
189
|
end
|
|
150
190
|
end
|
|
151
191
|
|
|
@@ -154,16 +194,13 @@ module RuboCop
|
|
|
154
194
|
end
|
|
155
195
|
|
|
156
196
|
def process_file(file)
|
|
157
|
-
|
|
158
|
-
offenses = file_offenses(file)
|
|
197
|
+
file_offenses(file)
|
|
159
198
|
rescue InfiniteCorrectionLoop => e
|
|
160
199
|
raise e if @options[:raise_cop_error]
|
|
161
200
|
|
|
162
201
|
errors << e
|
|
163
202
|
warn Rainbow(e.message).red
|
|
164
|
-
|
|
165
|
-
ensure
|
|
166
|
-
file_finished(file, offenses || [])
|
|
203
|
+
e.offenses.compact.sort.freeze
|
|
167
204
|
end
|
|
168
205
|
|
|
169
206
|
def file_offenses(file)
|
|
@@ -250,6 +287,7 @@ module RuboCop
|
|
|
250
287
|
end
|
|
251
288
|
|
|
252
289
|
def file_finished(file, offenses)
|
|
290
|
+
@inspected_files << file
|
|
253
291
|
offenses = offenses_to_report(offenses)
|
|
254
292
|
formatter_set.file_finished(file, offenses)
|
|
255
293
|
end
|
|
@@ -258,10 +296,6 @@ module RuboCop
|
|
|
258
296
|
@cached_run ||=
|
|
259
297
|
(@options[:cache] == 'true' ||
|
|
260
298
|
(@options[:cache] != 'false' && @config_store.for_pwd.for_all_cops['UseCache'])) &&
|
|
261
|
-
# When running --auto-gen-config, there's some processing done in the
|
|
262
|
-
# cops related to calculating the Max parameters for Metrics cops. We
|
|
263
|
-
# need to do that processing and cannot use caching.
|
|
264
|
-
!@options[:auto_gen_config] &&
|
|
265
299
|
# We can't cache results from code which is piped in to stdin
|
|
266
300
|
!@options[:stdin]
|
|
267
301
|
end
|
|
@@ -350,21 +384,9 @@ module RuboCop
|
|
|
350
384
|
|
|
351
385
|
def inspect_file(processed_source, team = mobilize_team(processed_source))
|
|
352
386
|
extracted_ruby_sources = extract_ruby_sources(processed_source)
|
|
353
|
-
offenses =
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
report = team.investigate(
|
|
357
|
-
extracted_ruby_source[:processed_source],
|
|
358
|
-
offset: extracted_ruby_source[:offset],
|
|
359
|
-
original: processed_source
|
|
360
|
-
)
|
|
361
|
-
@errors.concat(team.errors)
|
|
362
|
-
@warnings.concat(team.warnings)
|
|
363
|
-
offenses.concat(report.offenses)
|
|
364
|
-
|
|
365
|
-
break if team.updated_source_file?
|
|
366
|
-
end
|
|
367
|
-
|
|
387
|
+
offenses = team.investigate_fragments(extracted_ruby_sources, original: processed_source)
|
|
388
|
+
@errors.concat(team.errors)
|
|
389
|
+
@warnings.concat(team.warnings)
|
|
368
390
|
[offenses, team.updated_source_file?]
|
|
369
391
|
end
|
|
370
392
|
|
|
@@ -44,10 +44,10 @@ module RuboCop
|
|
|
44
44
|
all_files = find_files(base_dir, File::FNM_DOTMATCH)
|
|
45
45
|
base_dir_config = @config_store.for(base_dir)
|
|
46
46
|
|
|
47
|
-
target_files = if
|
|
47
|
+
target_files = if hidden_dir?(base_dir)
|
|
48
48
|
all_files.select { |file| ruby_file?(file) }
|
|
49
49
|
else
|
|
50
|
-
all_files.select { |file| to_inspect?(file, base_dir_config) }
|
|
50
|
+
all_files.select { |file| to_inspect?(file, base_dir, base_dir_config) }
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
target_files.sort_by!(&order)
|
|
@@ -72,15 +72,22 @@ module RuboCop
|
|
|
72
72
|
|
|
73
73
|
private
|
|
74
74
|
|
|
75
|
-
def to_inspect?(file, base_dir_config)
|
|
75
|
+
def to_inspect?(file, base_dir, base_dir_config)
|
|
76
76
|
return false if base_dir_config.file_to_exclude?(file)
|
|
77
|
-
return true if !
|
|
77
|
+
return true if !hidden_file_in_dir?(file, base_dir) && ruby_file?(file)
|
|
78
78
|
|
|
79
79
|
base_dir_config.file_to_include?(file)
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
-
def
|
|
83
|
-
|
|
82
|
+
def hidden_dir?(dir)
|
|
83
|
+
basename = File.basename(dir)
|
|
84
|
+
basename.start_with?('.') && basename != '.' && basename != '..'
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def hidden_file_in_dir?(file, base_dir)
|
|
88
|
+
base_dir = "#{base_dir}#{File::SEPARATOR}" unless base_dir.end_with?(File::SEPARATOR)
|
|
89
|
+
relative = file.delete_prefix(base_dir)
|
|
90
|
+
relative.start_with?('.') || relative.include?(HIDDEN_PATH_SUBSTRING)
|
|
84
91
|
end
|
|
85
92
|
|
|
86
93
|
def wanted_dir_patterns(base_dir, exclude_pattern, flags)
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
|
@@ -52,6 +52,7 @@ require_relative 'rubocop/cop/cop'
|
|
|
52
52
|
require_relative 'rubocop/cop/commissioner'
|
|
53
53
|
require_relative 'rubocop/cop/documentation'
|
|
54
54
|
require_relative 'rubocop/cop/corrector'
|
|
55
|
+
require_relative 'rubocop/cop/correctors'
|
|
55
56
|
require_relative 'rubocop/cop/force'
|
|
56
57
|
require_relative 'rubocop/cop/severity'
|
|
57
58
|
require_relative 'rubocop/cop/generator'
|
|
@@ -68,109 +69,18 @@ require_relative 'rubocop/cop/variable_force/reference'
|
|
|
68
69
|
require_relative 'rubocop/cop/variable_force/scope'
|
|
69
70
|
require_relative 'rubocop/cop/variable_force/variable_table'
|
|
70
71
|
|
|
71
|
-
require_relative 'rubocop/cop/mixin
|
|
72
|
-
|
|
73
|
-
require_relative 'rubocop/cop/mixin/
|
|
74
|
-
|
|
75
|
-
require_relative 'rubocop/cop/mixin/
|
|
76
|
-
require_relative 'rubocop/cop/mixin/allowed_pattern'
|
|
77
|
-
require_relative 'rubocop/cop/mixin/allowed_receivers'
|
|
78
|
-
require_relative 'rubocop/cop/mixin/forbidden_identifiers'
|
|
79
|
-
require_relative 'rubocop/cop/mixin/forbidden_pattern'
|
|
80
|
-
require_relative 'rubocop/cop/mixin/auto_corrector' # rubocop:todo Naming/InclusiveLanguage
|
|
81
|
-
require_relative 'rubocop/cop/mixin/check_assignment'
|
|
82
|
-
require_relative 'rubocop/cop/mixin/check_line_breakable'
|
|
83
|
-
require_relative 'rubocop/cop/mixin/check_single_line_suitability'
|
|
84
|
-
require_relative 'rubocop/cop/mixin/configurable_max'
|
|
85
|
-
require_relative 'rubocop/cop/mixin/code_length' # relies on configurable_max
|
|
86
|
-
require_relative 'rubocop/cop/mixin/configurable_enforced_style'
|
|
87
|
-
require_relative 'rubocop/cop/mixin/configurable_formatting'
|
|
88
|
-
require_relative 'rubocop/cop/mixin/configurable_naming'
|
|
89
|
-
require_relative 'rubocop/cop/mixin/configurable_numbering'
|
|
90
|
-
require_relative 'rubocop/cop/mixin/dig_help'
|
|
91
|
-
require_relative 'rubocop/cop/mixin/documentation_comment'
|
|
92
|
-
require_relative 'rubocop/cop/mixin/duplication'
|
|
93
|
-
require_relative 'rubocop/cop/mixin/range_help'
|
|
94
|
-
require_relative 'rubocop/cop/mixin/annotation_comment' # relies on range
|
|
95
|
-
require_relative 'rubocop/cop/mixin/empty_lines_around_body' # relies on range
|
|
96
|
-
require_relative 'rubocop/cop/mixin/empty_parameter'
|
|
97
|
-
require_relative 'rubocop/cop/mixin/end_keyword_alignment'
|
|
98
|
-
require_relative 'rubocop/cop/mixin/endless_method_rewriter'
|
|
99
|
-
require_relative 'rubocop/cop/mixin/enforce_superclass'
|
|
100
|
-
require_relative 'rubocop/cop/mixin/first_element_line_break'
|
|
101
|
-
require_relative 'rubocop/cop/mixin/frozen_string_literal'
|
|
102
|
-
require_relative 'rubocop/cop/mixin/gem_declaration'
|
|
103
|
-
require_relative 'rubocop/cop/mixin/gemspec_help'
|
|
104
|
-
require_relative 'rubocop/cop/mixin/hash_alignment_styles'
|
|
105
|
-
require_relative 'rubocop/cop/mixin/hash_subset'
|
|
106
|
-
require_relative 'rubocop/cop/mixin/hash_transform_method'
|
|
107
|
-
require_relative 'rubocop/cop/mixin/integer_node'
|
|
108
|
-
require_relative 'rubocop/cop/mixin/interpolation'
|
|
109
|
-
require_relative 'rubocop/cop/mixin/line_length_help'
|
|
110
|
-
require_relative 'rubocop/cop/mixin/match_range'
|
|
72
|
+
require_relative 'rubocop/cop/mixin'
|
|
73
|
+
# TODO: move to Layout module once cop lazy loading is implemented
|
|
74
|
+
require_relative 'rubocop/cop/mixin/empty_lines_around_body'
|
|
75
|
+
# TODO: move to Lint module once cop lazy loading is implemented
|
|
76
|
+
require_relative 'rubocop/cop/mixin/unused_argument'
|
|
111
77
|
require_relative 'rubocop/cop/metrics/utils/repeated_csend_discount'
|
|
112
78
|
require_relative 'rubocop/cop/metrics/utils/repeated_attribute_discount'
|
|
113
|
-
require_relative 'rubocop/cop/mixin/hash_shorthand_syntax'
|
|
114
|
-
require_relative 'rubocop/cop/mixin/method_complexity'
|
|
115
|
-
require_relative 'rubocop/cop/mixin/method_preference'
|
|
116
|
-
require_relative 'rubocop/cop/mixin/min_body_length'
|
|
117
|
-
require_relative 'rubocop/cop/mixin/min_branches_count'
|
|
118
|
-
require_relative 'rubocop/cop/mixin/multiline_element_indentation'
|
|
119
|
-
require_relative 'rubocop/cop/mixin/multiline_element_line_breaks'
|
|
120
|
-
require_relative 'rubocop/cop/mixin/multiline_expression_indentation'
|
|
121
|
-
require_relative 'rubocop/cop/mixin/multiline_literal_brace_layout'
|
|
122
|
-
require_relative 'rubocop/cop/mixin/negative_conditional'
|
|
123
|
-
require_relative 'rubocop/cop/mixin/heredoc'
|
|
124
|
-
require_relative 'rubocop/cop/mixin/nil_methods'
|
|
125
|
-
require_relative 'rubocop/cop/mixin/on_normal_if_unless'
|
|
126
|
-
require_relative 'rubocop/cop/mixin/ordered_gem_node'
|
|
127
|
-
require_relative 'rubocop/cop/mixin/parentheses'
|
|
128
|
-
require_relative 'rubocop/cop/mixin/percent_array'
|
|
129
|
-
require_relative 'rubocop/cop/mixin/percent_literal'
|
|
130
|
-
require_relative 'rubocop/cop/mixin/preceding_following_alignment'
|
|
131
|
-
require_relative 'rubocop/cop/mixin/preferred_delimiters'
|
|
132
|
-
require_relative 'rubocop/cop/mixin/rational_literal'
|
|
133
|
-
require_relative 'rubocop/cop/mixin/require_library'
|
|
134
|
-
require_relative 'rubocop/cop/mixin/rescue_node'
|
|
135
|
-
require_relative 'rubocop/cop/mixin/safe_assignment'
|
|
136
|
-
require_relative 'rubocop/cop/mixin/space_after_punctuation'
|
|
137
|
-
require_relative 'rubocop/cop/mixin/space_before_punctuation'
|
|
138
|
-
require_relative 'rubocop/cop/mixin/surrounding_space'
|
|
139
|
-
require_relative 'rubocop/cop/mixin/statement_modifier'
|
|
140
|
-
require_relative 'rubocop/cop/mixin/string_help'
|
|
141
|
-
require_relative 'rubocop/cop/mixin/string_literals_help'
|
|
142
|
-
require_relative 'rubocop/cop/mixin/symbol_help'
|
|
143
|
-
require_relative 'rubocop/cop/mixin/target_ruby_version'
|
|
144
|
-
require_relative 'rubocop/cop/mixin/trailing_body'
|
|
145
|
-
require_relative 'rubocop/cop/mixin/trailing_comma'
|
|
146
|
-
require_relative 'rubocop/cop/mixin/uncommunicative_name'
|
|
147
|
-
require_relative 'rubocop/cop/mixin/unused_argument'
|
|
148
|
-
require_relative 'rubocop/cop/mixin/visibility_help'
|
|
149
|
-
require_relative 'rubocop/cop/mixin/comments_help' # relies on visibility_help
|
|
150
|
-
require_relative 'rubocop/cop/mixin/def_node' # relies on visibility_help
|
|
151
79
|
|
|
152
80
|
require_relative 'rubocop/cop/utils/format_string'
|
|
153
81
|
|
|
154
82
|
require_relative 'rubocop/cop/migration/department_name'
|
|
155
83
|
|
|
156
|
-
require_relative 'rubocop/cop/correctors/alignment_corrector'
|
|
157
|
-
require_relative 'rubocop/cop/correctors/condition_corrector'
|
|
158
|
-
require_relative 'rubocop/cop/correctors/each_to_for_corrector'
|
|
159
|
-
require_relative 'rubocop/cop/correctors/empty_line_corrector'
|
|
160
|
-
require_relative 'rubocop/cop/correctors/for_to_each_corrector'
|
|
161
|
-
require_relative 'rubocop/cop/correctors/if_then_corrector'
|
|
162
|
-
require_relative 'rubocop/cop/correctors/lambda_literal_to_method_corrector'
|
|
163
|
-
require_relative 'rubocop/cop/correctors/line_break_corrector'
|
|
164
|
-
require_relative 'rubocop/cop/correctors/multiline_literal_brace_corrector'
|
|
165
|
-
require_relative 'rubocop/cop/correctors/ordered_gem_corrector'
|
|
166
|
-
require_relative 'rubocop/cop/correctors/parentheses_corrector'
|
|
167
|
-
require_relative 'rubocop/cop/correctors/percent_literal_corrector'
|
|
168
|
-
require_relative 'rubocop/cop/correctors/punctuation_corrector'
|
|
169
|
-
require_relative 'rubocop/cop/correctors/require_library_corrector'
|
|
170
|
-
require_relative 'rubocop/cop/correctors/space_corrector'
|
|
171
|
-
require_relative 'rubocop/cop/correctors/string_literal_corrector'
|
|
172
|
-
require_relative 'rubocop/cop/correctors/unused_arg_corrector'
|
|
173
|
-
|
|
174
84
|
require_relative 'rubocop/cop/bundler/duplicated_gem'
|
|
175
85
|
require_relative 'rubocop/cop/bundler/duplicated_group'
|
|
176
86
|
require_relative 'rubocop/cop/bundler/gem_comment'
|
|
@@ -824,6 +734,7 @@ require_relative 'rubocop/cli/command/auto_generate_config'
|
|
|
824
734
|
require_relative 'rubocop/cli/command/execute_runner'
|
|
825
735
|
require_relative 'rubocop/cli/command/init_dotfile'
|
|
826
736
|
require_relative 'rubocop/cli/command/lsp'
|
|
737
|
+
require_relative 'rubocop/cli/command/list_enabled_cops_for'
|
|
827
738
|
require_relative 'rubocop/cli/command/mcp'
|
|
828
739
|
require_relative 'rubocop/cli/command/show_cops'
|
|
829
740
|
require_relative 'rubocop/cli/command/show_docs_url'
|