rubocop 1.77.0 → 1.80.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/README.md +1 -3
- data/config/default.yml +36 -20
- data/exe/rubocop +1 -8
- data/lib/rubocop/cli.rb +17 -1
- data/lib/rubocop/config_loader.rb +1 -38
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +6 -3
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -2
- data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_type_group.rb +3 -2
- data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +101 -0
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +8 -29
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +2 -0
- data/lib/rubocop/cop/layout/space_around_keyword.rb +6 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +8 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +25 -4
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
- data/lib/rubocop/cop/lint/literal_as_condition.rb +15 -1
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -2
- data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +101 -2
- data/lib/rubocop/cop/lint/redundant_type_conversion.rb +4 -4
- data/lib/rubocop/cop/lint/require_range_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +1 -1
- data/lib/rubocop/cop/lint/self_assignment.rb +5 -4
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
- data/lib/rubocop/cop/lint/useless_numeric_operation.rb +1 -0
- data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +121 -0
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
- data/lib/rubocop/cop/naming/method_name.rb +127 -13
- data/lib/rubocop/cop/naming/predicate_method.rb +30 -4
- data/lib/rubocop/cop/security/eval.rb +2 -1
- data/lib/rubocop/cop/security/open.rb +1 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -1
- data/lib/rubocop/cop/style/accessor_grouping.rb +13 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +11 -17
- data/lib/rubocop/cop/style/array_intersect.rb +98 -34
- data/lib/rubocop/cop/style/bitwise_predicate.rb +8 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
- data/lib/rubocop/cop/style/dig_chain.rb +1 -1
- data/lib/rubocop/cop/style/exponential_notation.rb +1 -0
- data/lib/rubocop/cop/style/hash_conversion.rb +8 -9
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
- data/lib/rubocop/cop/style/it_assignment.rb +69 -12
- data/lib/rubocop/cop/style/it_block_parameter.rb +3 -1
- data/lib/rubocop/cop/style/map_to_hash.rb +1 -3
- data/lib/rubocop/cop/style/map_to_set.rb +1 -3
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +16 -0
- data/lib/rubocop/cop/style/parallel_assignment.rb +32 -20
- data/lib/rubocop/cop/style/redundant_begin.rb +34 -0
- data/lib/rubocop/cop/style/redundant_condition.rb +1 -1
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -9
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +28 -11
- data/lib/rubocop/cop/style/safe_navigation.rb +20 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +7 -4
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +30 -1
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/string_concatenation.rb +17 -13
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/variable_force/variable.rb +1 -1
- data/lib/rubocop/cop/variable_force.rb +25 -8
- data/lib/rubocop/cops_documentation_generator.rb +1 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +18 -5
- data/lib/rubocop/formatter/markdown_formatter.rb +1 -0
- data/lib/rubocop/formatter/pacman_formatter.rb +1 -0
- data/lib/rubocop/lsp/routes.rb +35 -6
- data/lib/rubocop/pending_cops_reporter.rb +56 -0
- data/lib/rubocop/result_cache.rb +14 -12
- data/lib/rubocop/runner.rb +6 -4
- data/lib/rubocop/server/cache.rb +4 -2
- data/lib/rubocop/server/client_command/base.rb +10 -0
- data/lib/rubocop/server/client_command/exec.rb +2 -1
- data/lib/rubocop/server/client_command/start.rb +11 -1
- data/lib/rubocop/target_finder.rb +9 -9
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +3 -0
- metadata +9 -6
@@ -175,6 +175,8 @@ module RuboCop
|
|
175
175
|
|
176
176
|
if parenthesize_method?(condition)
|
177
177
|
parenthesized_method_arguments(condition)
|
178
|
+
elsif condition.and_type?
|
179
|
+
parenthesized_and(condition)
|
178
180
|
else
|
179
181
|
"(#{condition.source})"
|
180
182
|
end
|
@@ -186,12 +188,19 @@ module RuboCop
|
|
186
188
|
end
|
187
189
|
|
188
190
|
def add_parentheses?(node)
|
189
|
-
return true if node.assignment? ||
|
191
|
+
return true if node.assignment? || node.or_type?
|
192
|
+
return true if assignment_in_and?(node)
|
190
193
|
return false unless node.call_type?
|
191
194
|
|
192
195
|
(node.arguments.any? && !node.parenthesized?) || node.prefix_not?
|
193
196
|
end
|
194
197
|
|
198
|
+
def assignment_in_and?(node)
|
199
|
+
return false unless node.and_type?
|
200
|
+
|
201
|
+
node.each_descendant.any?(&:assignment?)
|
202
|
+
end
|
203
|
+
|
195
204
|
def parenthesized_method_arguments(node)
|
196
205
|
method_call = node.source_range.begin.join(node.loc.selector.end).source
|
197
206
|
arguments = node.first_argument.source_range.begin.join(node.source_range.end).source
|
@@ -199,6 +208,26 @@ module RuboCop
|
|
199
208
|
"#{method_call}(#{arguments})"
|
200
209
|
end
|
201
210
|
|
211
|
+
def parenthesized_and(node)
|
212
|
+
# We only need to add parentheses around the last clause if it's an assignment,
|
213
|
+
# because other clauses will be unchanged by merging conditionals.
|
214
|
+
lhs = node.lhs.source
|
215
|
+
rhs = parenthesized_and_clause(node.rhs)
|
216
|
+
operator = range_with_surrounding_space(node.loc.operator, whitespace: true).source
|
217
|
+
|
218
|
+
"#{lhs}#{operator}#{rhs}"
|
219
|
+
end
|
220
|
+
|
221
|
+
def parenthesized_and_clause(node)
|
222
|
+
if node.and_type?
|
223
|
+
parenthesized_and(node)
|
224
|
+
elsif node.assignment?
|
225
|
+
"(#{node.source})"
|
226
|
+
else
|
227
|
+
node.source
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
202
231
|
def allow_modifier?
|
203
232
|
cop_config['AllowModifier']
|
204
233
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
#
|
6
|
+
# Checks for parentheses around stabby lambda arguments.
|
7
7
|
# There are two different styles. Defaults to `require_parentheses`.
|
8
8
|
#
|
9
9
|
# @example EnforcedStyle: require_parentheses (default)
|
@@ -100,7 +100,7 @@ module RuboCop
|
|
100
100
|
node.receiver.str_type? &&
|
101
101
|
node.first_argument.str_type? &&
|
102
102
|
node.multiline? &&
|
103
|
-
node.source
|
103
|
+
node.source.match?(/\+\s*\n/)
|
104
104
|
end
|
105
105
|
|
106
106
|
def find_topmost_plus_node(node)
|
@@ -141,22 +141,26 @@ module RuboCop
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def replacement(parts)
|
144
|
-
interpolated_parts = parts.map
|
145
|
-
case part.type
|
146
|
-
when :str
|
147
|
-
adjust_str(part)
|
148
|
-
when :dstr
|
149
|
-
part.children.all?(&:str_type?) ? adjust_str(part) : part.value
|
150
|
-
else
|
151
|
-
"\#{#{part.source}}"
|
152
|
-
end
|
153
|
-
end
|
144
|
+
interpolated_parts = parts.map { |part| adjust_str(part) }
|
154
145
|
|
155
146
|
"\"#{handle_quotes(interpolated_parts).join}\""
|
156
147
|
end
|
157
148
|
|
158
|
-
def adjust_str(
|
159
|
-
|
149
|
+
def adjust_str(part)
|
150
|
+
case part.type
|
151
|
+
when :str
|
152
|
+
if single_quoted?(part)
|
153
|
+
part.value.gsub(/(\\|"|#\{|#@|#\$)/, '\\\\\&')
|
154
|
+
else
|
155
|
+
part.value.inspect[1..-2]
|
156
|
+
end
|
157
|
+
when :dstr, :begin
|
158
|
+
part.children.map do |child|
|
159
|
+
adjust_str(child)
|
160
|
+
end.join
|
161
|
+
else
|
162
|
+
"\#{#{part.source}}"
|
163
|
+
end
|
160
164
|
end
|
161
165
|
|
162
166
|
def handle_quotes(parts)
|
@@ -81,7 +81,7 @@ module RuboCop
|
|
81
81
|
|
82
82
|
content = *sym
|
83
83
|
content = content.map { |c| c.is_a?(AST::Node) ? c.source : c }.join
|
84
|
-
content_without_delimiter_pairs = content.gsub(/(\[[^\s\[\]]*\])|(\([^\s
|
84
|
+
content_without_delimiter_pairs = content.gsub(/(\[[^\s\[\]]*\])|(\([^\s()]*\))/, '')
|
85
85
|
|
86
86
|
content.include?(' ') || DELIMITERS.any? do |delimiter|
|
87
87
|
content_without_delimiter_pairs.include?(delimiter)
|
@@ -71,6 +71,8 @@ module RuboCop
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
BRANCH_NODES = %i[if case case_match rescue].freeze
|
75
|
+
|
74
76
|
def variable_table
|
75
77
|
@variable_table ||= VariableTable.new(self)
|
76
78
|
end
|
@@ -236,11 +238,16 @@ module RuboCop
|
|
236
238
|
end
|
237
239
|
|
238
240
|
def process_loop(node)
|
239
|
-
if
|
241
|
+
if node.post_condition_loop?
|
240
242
|
# See the comment at the end of file for this behavior.
|
241
243
|
condition_node, body_node = *node
|
242
244
|
process_node(body_node)
|
243
245
|
process_node(condition_node)
|
246
|
+
elsif node.for_type?
|
247
|
+
# In `for item in items` the rightmost expression is evaluated first.
|
248
|
+
process_node(node.collection)
|
249
|
+
process_node(node.variable)
|
250
|
+
process_node(node.body) if node.body
|
244
251
|
else
|
245
252
|
process_children(node)
|
246
253
|
end
|
@@ -296,7 +303,7 @@ module RuboCop
|
|
296
303
|
variable_table.accessible_variables.each { |variable| variable.reference!(node) }
|
297
304
|
end
|
298
305
|
|
299
|
-
# Mark
|
306
|
+
# Mark last assignments which are referenced in the same loop
|
300
307
|
# as referenced by ignoring AST order since they would be referenced
|
301
308
|
# in next iteration.
|
302
309
|
def mark_assignments_as_referenced_in_loop(node)
|
@@ -308,13 +315,12 @@ module RuboCop
|
|
308
315
|
# would be skipped here.
|
309
316
|
next unless variable
|
310
317
|
|
311
|
-
variable.assignments.
|
312
|
-
|
313
|
-
assignment_node.equal?(assignment.node)
|
314
|
-
end
|
315
|
-
|
316
|
-
assignment.reference!(node)
|
318
|
+
loop_assignments = variable.assignments.select do |assignment|
|
319
|
+
assignment_nodes_in_loop.include?(assignment.node)
|
317
320
|
end
|
321
|
+
next unless loop_assignments.any?
|
322
|
+
|
323
|
+
reference_assignments(loop_assignments, node)
|
318
324
|
end
|
319
325
|
end
|
320
326
|
|
@@ -354,6 +360,17 @@ module RuboCop
|
|
354
360
|
end
|
355
361
|
end
|
356
362
|
|
363
|
+
def reference_assignments(loop_assignments, loop_node)
|
364
|
+
# If inside a branching statement, mark all as referenced.
|
365
|
+
# Otherwise, mark only the last assignment as referenced.
|
366
|
+
# Note that `rescue` must be considered as branching because of
|
367
|
+
# the `retry` keyword.
|
368
|
+
loop_assignments.each do |assignment|
|
369
|
+
assignment.reference!(loop_node) if assignment.node.each_ancestor(*BRANCH_NODES).any?
|
370
|
+
end
|
371
|
+
loop_assignments.last&.reference!(loop_node)
|
372
|
+
end
|
373
|
+
|
357
374
|
def scanned_node?(node)
|
358
375
|
scanned_nodes.include?(node)
|
359
376
|
end
|
@@ -7,6 +7,7 @@ require 'yard'
|
|
7
7
|
# @api private
|
8
8
|
class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
9
9
|
include ::RuboCop::Cop::Documentation
|
10
|
+
|
10
11
|
CopData = Struct.new(
|
11
12
|
:cop, :description, :example_objects, :safety_objects, :see_objects, :config, keyword_init: true
|
12
13
|
)
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
module Formatter
|
5
5
|
# This formatter displays a YAML configuration file where all cops that
|
6
6
|
# detected any offenses are configured to not detect the offense.
|
7
|
-
class DisabledConfigFormatter < BaseFormatter
|
7
|
+
class DisabledConfigFormatter < BaseFormatter # rubocop:disable Metrics/ClassLength
|
8
8
|
include PathUtil
|
9
9
|
|
10
10
|
HEADING = <<~COMMENTS
|
@@ -17,6 +17,22 @@ module RuboCop
|
|
17
17
|
# versions of RuboCop, may require this file to be generated again.
|
18
18
|
COMMENTS
|
19
19
|
|
20
|
+
EXCLUDED_CONFIG_KEYS = %w[
|
21
|
+
AutoCorrect
|
22
|
+
Description
|
23
|
+
Enabled
|
24
|
+
Exclude
|
25
|
+
Include
|
26
|
+
Reference
|
27
|
+
References
|
28
|
+
Safe
|
29
|
+
SafeAutoCorrect
|
30
|
+
StyleGuide
|
31
|
+
VersionAdded
|
32
|
+
VersionChanged
|
33
|
+
VersionRemoved
|
34
|
+
].freeze
|
35
|
+
|
20
36
|
@config_to_allow_offenses = {}
|
21
37
|
@detected_styles = {}
|
22
38
|
|
@@ -163,10 +179,7 @@ module RuboCop
|
|
163
179
|
end
|
164
180
|
|
165
181
|
def cop_config_params(default_cfg, cfg)
|
166
|
-
default_cfg.keys -
|
167
|
-
%w[Description StyleGuide Reference References Enabled Exclude Safe
|
168
|
-
SafeAutoCorrect VersionAdded VersionChanged VersionRemoved] -
|
169
|
-
cfg.keys
|
182
|
+
default_cfg.keys - EXCLUDED_CONFIG_KEYS - cfg.keys
|
170
183
|
end
|
171
184
|
|
172
185
|
def output_cop_param_comments(output_buffer, params, default_cfg)
|
data/lib/rubocop/lsp/routes.rb
CHANGED
@@ -51,7 +51,7 @@ module RuboCop
|
|
51
51
|
capabilities: LanguageServer::Protocol::Interface::ServerCapabilities.new(
|
52
52
|
document_formatting_provider: true,
|
53
53
|
text_document_sync: LanguageServer::Protocol::Interface::TextDocumentSyncOptions.new(
|
54
|
-
change: LanguageServer::Protocol::Constant::TextDocumentSyncKind::
|
54
|
+
change: LanguageServer::Protocol::Constant::TextDocumentSyncKind::INCREMENTAL,
|
55
55
|
open_close: true
|
56
56
|
)
|
57
57
|
)
|
@@ -76,7 +76,12 @@ module RuboCop
|
|
76
76
|
|
77
77
|
handle 'textDocument/didChange' do |request|
|
78
78
|
params = request[:params]
|
79
|
-
|
79
|
+
file_uri = params[:textDocument][:uri]
|
80
|
+
text = @text_cache[file_uri]
|
81
|
+
params[:contentChanges].each do |content|
|
82
|
+
text = change_text(text, content[:text], content[:range])
|
83
|
+
end
|
84
|
+
result = diagnostic(file_uri, text)
|
80
85
|
@server.write(result)
|
81
86
|
end
|
82
87
|
|
@@ -194,7 +199,7 @@ module RuboCop
|
|
194
199
|
return []
|
195
200
|
end
|
196
201
|
|
197
|
-
new_text = @server.format(
|
202
|
+
new_text = @server.format(convert_file_uri_to_path(file_uri), text, command: command)
|
198
203
|
|
199
204
|
return [] if new_text == text
|
200
205
|
|
@@ -214,13 +219,37 @@ module RuboCop
|
|
214
219
|
method: 'textDocument/publishDiagnostics',
|
215
220
|
params: {
|
216
221
|
uri: file_uri,
|
217
|
-
diagnostics: @server.offenses(
|
222
|
+
diagnostics: @server.offenses(convert_file_uri_to_path(file_uri), text)
|
218
223
|
}
|
219
224
|
}
|
220
225
|
end
|
221
226
|
|
222
|
-
def
|
223
|
-
|
227
|
+
def change_text(orig_text, text, range)
|
228
|
+
return text unless range
|
229
|
+
|
230
|
+
start_pos = text_pos(orig_text, range[:start])
|
231
|
+
end_pos = text_pos(orig_text, range[:end])
|
232
|
+
text_bin = orig_text.b
|
233
|
+
text_bin[start_pos...end_pos] = text.b
|
234
|
+
text_bin.force_encoding(orig_text.encoding)
|
235
|
+
end
|
236
|
+
|
237
|
+
def text_pos(text, range)
|
238
|
+
line = range[:line]
|
239
|
+
char = range[:character]
|
240
|
+
pos = 0
|
241
|
+
text.each_line.with_index do |l, i|
|
242
|
+
if i == line
|
243
|
+
pos += l.encode('utf-16be').b[0, char * 2].encode('utf-8', 'utf-16be').bytesize
|
244
|
+
return pos
|
245
|
+
end
|
246
|
+
pos += l.bytesize
|
247
|
+
end
|
248
|
+
pos
|
249
|
+
end
|
250
|
+
|
251
|
+
def convert_file_uri_to_path(uri)
|
252
|
+
URI.decode_www_form_component(uri.delete_prefix('file://'))
|
224
253
|
end
|
225
254
|
end
|
226
255
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
# Reports information about pending cops that are not explicitly configured.
|
5
|
+
#
|
6
|
+
# This class is responsible for displaying warnings when new cops have been added to RuboCop
|
7
|
+
# but have not yet been enabled or disabled in the user's configuration.
|
8
|
+
# It provides a centralized way to determine whether such warnings should be shown,
|
9
|
+
# based on global flags or configuration settings.
|
10
|
+
class PendingCopsReporter
|
11
|
+
class << self
|
12
|
+
PENDING_BANNER = <<~BANNER
|
13
|
+
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
|
14
|
+
|
15
|
+
Please also note that you can opt-in to new cops by default by adding this to your config:
|
16
|
+
AllCops:
|
17
|
+
NewCops: enable
|
18
|
+
BANNER
|
19
|
+
|
20
|
+
attr_accessor :disable_pending_cops, :enable_pending_cops
|
21
|
+
|
22
|
+
def warn_if_needed(config)
|
23
|
+
return if possible_new_cops?(config)
|
24
|
+
|
25
|
+
pending_cops = pending_cops_only_qualified(config.pending_cops)
|
26
|
+
warn_on_pending_cops(pending_cops) unless pending_cops.empty?
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def pending_cops_only_qualified(pending_cops)
|
32
|
+
pending_cops.select { |cop| Cop::Registry.qualified_cop?(cop.name) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def possible_new_cops?(config)
|
36
|
+
disable_pending_cops || enable_pending_cops ||
|
37
|
+
config.disabled_new_cops? || config.enabled_new_cops?
|
38
|
+
end
|
39
|
+
|
40
|
+
def warn_on_pending_cops(pending_cops)
|
41
|
+
warn Rainbow(PENDING_BANNER).yellow
|
42
|
+
|
43
|
+
pending_cops.each { |cop| warn_pending_cop cop }
|
44
|
+
|
45
|
+
warn Rainbow('For more information: https://docs.rubocop.org/rubocop/versioning.html').yellow
|
46
|
+
end
|
47
|
+
|
48
|
+
def warn_pending_cop(cop)
|
49
|
+
version = cop.metadata['VersionAdded'] || 'N/A'
|
50
|
+
|
51
|
+
warn Rainbow("#{cop.name}: # new in #{version}").yellow
|
52
|
+
warn Rainbow(' Enabled: true').yellow
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -9,7 +9,7 @@ module RuboCop
|
|
9
9
|
# Provides functionality for caching RuboCop runs.
|
10
10
|
# @api private
|
11
11
|
class ResultCache
|
12
|
-
NON_CHANGING = %i[color format formatters out debug fail_level
|
12
|
+
NON_CHANGING = %i[color format formatters out debug display_time fail_level
|
13
13
|
fix_layout autocorrect safe_autocorrect autocorrect_all
|
14
14
|
cache fail_fast stdin parallel].freeze
|
15
15
|
|
@@ -198,20 +198,22 @@ module RuboCop
|
|
198
198
|
end
|
199
199
|
|
200
200
|
def rubocop_extra_features
|
201
|
-
|
202
|
-
|
201
|
+
@rubocop_extra_features ||= begin
|
202
|
+
lib_root = File.join(File.dirname(__FILE__), '..')
|
203
|
+
exe_root = File.join(lib_root, '..', 'exe')
|
203
204
|
|
204
|
-
|
205
|
-
|
206
|
-
|
205
|
+
# Make sure to use an absolute path to prevent errors on Windows
|
206
|
+
# when traversing the relative paths with symlinks.
|
207
|
+
exe_root = File.absolute_path(exe_root)
|
207
208
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
209
|
+
# These are all the files we have `require`d plus everything in the
|
210
|
+
# exe directory. A change to any of them could affect the cop output
|
211
|
+
# so we include them in the cache hash.
|
212
|
+
source_files = $LOADED_FEATURES + Find.find(exe_root).to_a
|
213
|
+
source_files -= ResultCache.rubocop_required_features # Rely on gem versions
|
213
214
|
|
214
|
-
|
215
|
+
source_files
|
216
|
+
end
|
215
217
|
end
|
216
218
|
|
217
219
|
# Return a hash of the options given at invocation, minus the ones that have
|
data/lib/rubocop/runner.rb
CHANGED
@@ -273,7 +273,8 @@ module RuboCop
|
|
273
273
|
end
|
274
274
|
|
275
275
|
def do_inspection_loop(file)
|
276
|
-
|
276
|
+
# We can reuse the prism result since the source did not change yet.
|
277
|
+
processed_source = get_processed_source(file, @prism_result)
|
277
278
|
# This variable is 2d array used to track corrected offenses after each
|
278
279
|
# inspection iteration. This is used to output meaningful infinite loop
|
279
280
|
# error message.
|
@@ -295,7 +296,8 @@ module RuboCop
|
|
295
296
|
# loop if we find any.
|
296
297
|
break unless updated_source_file
|
297
298
|
|
298
|
-
|
299
|
+
# Autocorrect has happened, don't use the prism result since it is stale.
|
300
|
+
processed_source = get_processed_source(file, nil)
|
299
301
|
end
|
300
302
|
|
301
303
|
# Return summary of corrected offenses after all iterations
|
@@ -482,7 +484,7 @@ module RuboCop
|
|
482
484
|
end
|
483
485
|
|
484
486
|
# rubocop:disable Metrics/MethodLength
|
485
|
-
def get_processed_source(file)
|
487
|
+
def get_processed_source(file, prism_result)
|
486
488
|
config = @config_store.for_file(file)
|
487
489
|
ruby_version = config.target_ruby_version
|
488
490
|
parser_engine = config.parser_engine
|
@@ -493,7 +495,7 @@ module RuboCop
|
|
493
495
|
ruby_version,
|
494
496
|
file,
|
495
497
|
parser_engine: parser_engine,
|
496
|
-
prism_result:
|
498
|
+
prism_result: prism_result
|
497
499
|
)
|
498
500
|
else
|
499
501
|
begin
|
data/lib/rubocop/server/cache.rb
CHANGED
@@ -46,12 +46,14 @@ module RuboCop
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# rubocop:disable Metrics/AbcSize
|
49
|
-
def restart_key
|
49
|
+
def restart_key(args_config_file_path: nil)
|
50
50
|
lockfile_path = LOCKFILE_NAMES.map do |lockfile_name|
|
51
51
|
Pathname(project_dir).join(lockfile_name)
|
52
52
|
end.find(&:exist?)
|
53
53
|
version_data = lockfile_path&.read || RuboCop::Version::STRING
|
54
|
-
config_data = Pathname(
|
54
|
+
config_data = Pathname(
|
55
|
+
args_config_file_path || ConfigFinder.find_config_path(Dir.pwd)
|
56
|
+
).read
|
55
57
|
yaml = load_erb_templated_yaml(config_data)
|
56
58
|
|
57
59
|
inherit_from_data = inherit_from_data(yaml)
|
@@ -38,6 +38,16 @@ module RuboCop
|
|
38
38
|
warn 'RuboCop server is not running.' unless running
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
class << self
|
43
|
+
def args_config_file_path
|
44
|
+
first_args_config_key_index = ARGV.index { |value| ['-c', '--config'].include?(value) }
|
45
|
+
|
46
|
+
return if first_args_config_key_index.nil?
|
47
|
+
|
48
|
+
ARGV[first_args_config_key_index + 1]
|
49
|
+
end
|
50
|
+
end
|
41
51
|
end
|
42
52
|
end
|
43
53
|
end
|
@@ -34,7 +34,7 @@ module RuboCop
|
|
34
34
|
exit 0
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
write_version_file
|
38
38
|
|
39
39
|
host = ENV.fetch('RUBOCOP_SERVER_HOST', '127.0.0.1')
|
40
40
|
port = ENV.fetch('RUBOCOP_SERVER_PORT', 0)
|
@@ -42,6 +42,16 @@ module RuboCop
|
|
42
42
|
Server::Core.new.start(host, port, detach: @detach)
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def write_version_file
|
49
|
+
Cache.write_version_file(
|
50
|
+
Cache.restart_key(
|
51
|
+
args_config_file_path: self.class.args_config_file_path
|
52
|
+
)
|
53
|
+
)
|
54
|
+
end
|
45
55
|
end
|
46
56
|
end
|
47
57
|
end
|
@@ -42,14 +42,12 @@ module RuboCop
|
|
42
42
|
# Support Windows: Backslashes from command-line -> forward slashes
|
43
43
|
base_dir = base_dir.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
44
44
|
all_files = find_files(base_dir, File::FNM_DOTMATCH)
|
45
|
-
# use file.include? for performance optimization
|
46
|
-
hidden_files = all_files.select { |file| file.include?(HIDDEN_PATH_SUBSTRING) }.sort
|
47
45
|
base_dir_config = @config_store.for(base_dir)
|
48
46
|
|
49
|
-
target_files = if
|
47
|
+
target_files = if hidden_path?(base_dir)
|
50
48
|
all_files.select { |file| ruby_file?(file) }
|
51
49
|
else
|
52
|
-
all_files.select { |file| to_inspect?(file,
|
50
|
+
all_files.select { |file| to_inspect?(file, base_dir_config) }
|
53
51
|
end
|
54
52
|
|
55
53
|
target_files.sort_by!(&order)
|
@@ -74,18 +72,20 @@ module RuboCop
|
|
74
72
|
|
75
73
|
private
|
76
74
|
|
77
|
-
def to_inspect?(file,
|
75
|
+
def to_inspect?(file, base_dir_config)
|
78
76
|
return false if base_dir_config.file_to_exclude?(file)
|
79
|
-
return true if !
|
80
|
-
file <=> hidden_file
|
81
|
-
end && ruby_file?(file)
|
77
|
+
return true if !hidden_path?(file) && ruby_file?(file)
|
82
78
|
|
83
79
|
base_dir_config.file_to_include?(file)
|
84
80
|
end
|
85
81
|
|
82
|
+
def hidden_path?(path)
|
83
|
+
path.include?(HIDDEN_PATH_SUBSTRING)
|
84
|
+
end
|
85
|
+
|
86
86
|
def wanted_dir_patterns(base_dir, exclude_pattern, flags)
|
87
87
|
# Escape glob characters in base_dir to avoid unwanted behavior.
|
88
|
-
base_dir = base_dir.gsub(/[
|
88
|
+
base_dir = base_dir.gsub(/[\\{}\[\]*?]/) do |reserved_glob_character|
|
89
89
|
"\\#{reserved_glob_character}"
|
90
90
|
end
|
91
91
|
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
@@ -211,6 +211,7 @@ require_relative 'rubocop/cop/layout/empty_line_after_guard_clause'
|
|
211
211
|
require_relative 'rubocop/cop/layout/empty_line_after_magic_comment'
|
212
212
|
require_relative 'rubocop/cop/layout/empty_line_after_multiline_condition'
|
213
213
|
require_relative 'rubocop/cop/layout/empty_line_between_defs'
|
214
|
+
require_relative 'rubocop/cop/layout/empty_lines_after_module_inclusion'
|
214
215
|
require_relative 'rubocop/cop/layout/empty_lines_around_access_modifier'
|
215
216
|
require_relative 'rubocop/cop/layout/empty_lines_around_arguments'
|
216
217
|
require_relative 'rubocop/cop/layout/empty_lines_around_attribute_accessor'
|
@@ -290,6 +291,7 @@ require_relative 'rubocop/cop/layout/space_inside_string_interpolation'
|
|
290
291
|
require_relative 'rubocop/cop/layout/trailing_empty_lines'
|
291
292
|
require_relative 'rubocop/cop/layout/trailing_whitespace'
|
292
293
|
|
294
|
+
require_relative 'rubocop/cop/lint/utils/nil_receiver_checker'
|
293
295
|
require_relative 'rubocop/cop/lint/ambiguous_assignment'
|
294
296
|
require_relative 'rubocop/cop/lint/ambiguous_block_association'
|
295
297
|
require_relative 'rubocop/cop/lint/ambiguous_operator'
|
@@ -812,6 +814,7 @@ require_relative 'rubocop/options'
|
|
812
814
|
require_relative 'rubocop/remote_config'
|
813
815
|
require_relative 'rubocop/target_ruby'
|
814
816
|
require_relative 'rubocop/yaml_duplication_checker'
|
817
|
+
require_relative 'rubocop/pending_cops_reporter'
|
815
818
|
|
816
819
|
# rubocop:enable Style/RequireOrder
|
817
820
|
|