rubocop 1.70.0 → 1.71.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 -1
- data/config/default.yml +17 -0
- data/lib/rubocop/cli/command/show_cops.rb +24 -2
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/location_expression.rb +2 -1
- data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +3 -2
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +63 -0
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +131 -0
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +229 -0
- data/lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb +126 -0
- data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +90 -0
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +3 -1
- data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +5 -4
- data/lib/rubocop/cop/internal_affairs.rb +3 -0
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +9 -9
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +7 -11
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -1
- data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/redundant_line_break.rb +6 -5
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_colon.rb +2 -2
- data/lib/rubocop/cop/layout/space_after_comma.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -0
- data/lib/rubocop/cop/layout/space_before_comma.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_semicolon.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
- data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +119 -0
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -3
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +1 -1
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +3 -3
- data/lib/rubocop/cop/lint/constant_reassignment.rb +2 -6
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_set_element.rb +1 -1
- data/lib/rubocop/cop/lint/empty_expression.rb +0 -2
- data/lib/rubocop/cop/lint/float_comparison.rb +5 -2
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +13 -3
- data/lib/rubocop/cop/lint/missing_super.rb +2 -2
- data/lib/rubocop/cop/lint/mixed_case_range.rb +1 -1
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -3
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +1 -1
- data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +13 -18
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +2 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -5
- data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +2 -2
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +8 -1
- data/lib/rubocop/cop/lint/shared_mutable_default.rb +3 -3
- data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/unexpected_block_arity.rb +1 -1
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -4
- data/lib/rubocop/cop/lint/useless_assignment.rb +1 -1
- data/lib/rubocop/cop/lint/useless_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/useless_numeric_operation.rb +2 -1
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +2 -2
- data/lib/rubocop/cop/lint/void.rb +2 -7
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
- data/lib/rubocop/cop/metrics/collection_literal_length.rb +7 -0
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/module_length.rb +1 -1
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +5 -5
- data/lib/rubocop/cop/mixin/comments_help.rb +1 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +4 -4
- data/lib/rubocop/cop/mixin/hash_subset.rb +188 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +1 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +22 -8
- data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -2
- data/lib/rubocop/cop/mixin/string_help.rb +1 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +3 -3
- data/lib/rubocop/cop/naming/block_forwarding.rb +18 -14
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +3 -3
- data/lib/rubocop/cop/security/compound_hash.rb +1 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +2 -4
- data/lib/rubocop/cop/style/arguments_forwarding.rb +38 -19
- data/lib/rubocop/cop/style/array_first_last.rb +18 -2
- data/lib/rubocop/cop/style/block_delimiters.rb +7 -20
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/collection_methods.rb +1 -1
- data/lib/rubocop/cop/style/combinable_defined.rb +1 -1
- data/lib/rubocop/cop/style/combinable_loops.rb +2 -2
- data/lib/rubocop/cop/style/concat_array_literals.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +6 -4
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +3 -3
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
- data/lib/rubocop/cop/style/each_with_object.rb +2 -3
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
- data/lib/rubocop/cop/style/exact_regexp_match.rb +1 -1
- data/lib/rubocop/cop/style/explicit_block_argument.rb +15 -2
- data/lib/rubocop/cop/style/fetch_env_var.rb +1 -1
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/hash_each_methods.rb +3 -6
- data/lib/rubocop/cop/style/hash_except.rb +20 -131
- data/lib/rubocop/cop/style/hash_slice.rb +80 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +22 -3
- data/lib/rubocop/cop/style/if_unless_modifier.rb +3 -3
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
- data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -2
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +6 -6
- data/lib/rubocop/cop/style/it_assignment.rb +1 -1
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -1
- data/lib/rubocop/cop/style/map_into_array.rb +1 -1
- data/lib/rubocop/cop/style/map_to_hash.rb +1 -1
- data/lib/rubocop/cop/style/map_to_set.rb +3 -2
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +10 -13
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -1
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -4
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +2 -2
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -1
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
- data/lib/rubocop/cop/style/open_struct_use.rb +5 -5
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -5
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -2
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -2
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -2
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +6 -10
- data/lib/rubocop/cop/style/redundant_each.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +2 -2
- data/lib/rubocop/cop/style/redundant_freeze.rb +2 -2
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +27 -10
- data/lib/rubocop/cop/style/redundant_parentheses.rb +9 -6
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +12 -27
- data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
- data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -2
- data/lib/rubocop/cop/style/return_nil.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +1 -1
- data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +2 -2
- data/lib/rubocop/cop/style/string_concatenation.rb +1 -1
- data/lib/rubocop/cop/style/string_literals.rb +1 -1
- data/lib/rubocop/cop/style/string_methods.rb +1 -1
- data/lib/rubocop/cop/style/super_arguments.rb +4 -4
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +4 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
- data/lib/rubocop/cop/style/yoda_expression.rb +1 -1
- data/lib/rubocop/cop/util.rb +2 -2
- data/lib/rubocop/cop/variable_force/variable.rb +14 -2
- data/lib/rubocop/cop/variable_force/variable_table.rb +3 -3
- data/lib/rubocop/cops_documentation_generator.rb +13 -13
- data/lib/rubocop/directive_comment.rb +9 -8
- data/lib/rubocop/options.rb +2 -1
- data/lib/rubocop/result_cache.rb +13 -13
- data/lib/rubocop/rspec/expect_offense.rb +6 -2
- data/lib/rubocop/rspec/support.rb +1 -2
- data/lib/rubocop/target_finder.rb +1 -0
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +3 -0
- metadata +15 -11
- data/lib/rubocop/rspec/host_environment_simulation_helper.rb +0 -28
@@ -6,6 +6,8 @@ module RuboCop
|
|
6
6
|
# A Variable represents existence of a local variable.
|
7
7
|
# This holds a variable declaration node and some states of the variable.
|
8
8
|
class Variable
|
9
|
+
extend NodePattern::Macros
|
10
|
+
|
9
11
|
VARIABLE_DECLARATION_TYPES = (VARIABLE_ASSIGNMENT_TYPES + ARGUMENT_DECLARATION_TYPES).freeze
|
10
12
|
|
11
13
|
attr_reader :name, :declaration_node, :scope, :assignments, :references, :captured_by_block
|
@@ -31,11 +33,21 @@ module RuboCop
|
|
31
33
|
def assign(node)
|
32
34
|
assignment = Assignment.new(node, self)
|
33
35
|
|
34
|
-
|
36
|
+
mark_last_as_reassigned!(assignment)
|
35
37
|
|
36
38
|
@assignments << assignment
|
37
39
|
end
|
38
40
|
|
41
|
+
def mark_last_as_reassigned!(assignment)
|
42
|
+
return if captured_by_block?
|
43
|
+
return if candidate_condition?(assignment.node.parent)
|
44
|
+
|
45
|
+
@assignments.last&.reassigned!
|
46
|
+
end
|
47
|
+
|
48
|
+
# @!method candidate_condition?(node)
|
49
|
+
def_node_matcher :candidate_condition?, '[{if case case_match when}]'
|
50
|
+
|
39
51
|
def referenced?
|
40
52
|
!@references.empty?
|
41
53
|
end
|
@@ -72,7 +84,7 @@ module RuboCop
|
|
72
84
|
parent = parent.parent if parent&.begin_type?
|
73
85
|
return false if parent.nil?
|
74
86
|
|
75
|
-
|
87
|
+
parent.type?(:if, :while, :until) && parent.modifier_form?
|
76
88
|
end
|
77
89
|
|
78
90
|
def capture_with_block!
|
@@ -100,7 +100,7 @@ module RuboCop
|
|
100
100
|
|
101
101
|
# Only block scope allows referencing outer scope variables.
|
102
102
|
node = scope.node
|
103
|
-
return nil unless node.
|
103
|
+
return nil unless node.any_block_type?
|
104
104
|
end
|
105
105
|
|
106
106
|
nil
|
@@ -113,14 +113,14 @@ module RuboCop
|
|
113
113
|
def accessible_variables
|
114
114
|
scope_stack.reverse_each.with_object([]) do |scope, variables|
|
115
115
|
variables.concat(scope.variables.values)
|
116
|
-
break variables unless scope.node.
|
116
|
+
break variables unless scope.node.any_block_type?
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
private
|
121
121
|
|
122
122
|
def mark_variable_as_captured_by_block_if_so(variable)
|
123
|
-
return unless current_scope.node.
|
123
|
+
return unless current_scope.node.any_block_type?
|
124
124
|
return if variable.scope == current_scope
|
125
125
|
|
126
126
|
variable.capture_with_block!
|
@@ -18,7 +18,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
18
18
|
description: ->(data) { "#{data.description}\n" },
|
19
19
|
safety: ->(data) { safety_object(data.safety_objects, data.cop) },
|
20
20
|
examples: ->(data) { examples(data.example_objects, data.cop) },
|
21
|
-
configuration: ->(data) { configurations(data.cop.department, data.
|
21
|
+
configuration: ->(data) { configurations(data.cop.department, data.cop, data.config) },
|
22
22
|
references: ->(data) { references(data.cop, data.see_objects) }
|
23
23
|
}.freeze
|
24
24
|
|
@@ -180,17 +180,17 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
180
180
|
content
|
181
181
|
end
|
182
182
|
|
183
|
-
def configurations(department,
|
184
|
-
return '' if pars.empty?
|
185
|
-
|
183
|
+
def configurations(department, cop, cop_config)
|
186
184
|
header = ['Name', 'Default value', 'Configurable values']
|
187
|
-
configs =
|
185
|
+
configs = cop_config
|
188
186
|
.each_key
|
189
187
|
.reject { |key| key.start_with?('Supported') }
|
190
188
|
.reject { |key| key.start_with?('AllowMultipleStyles') }
|
189
|
+
return '' if configs.empty?
|
190
|
+
|
191
191
|
content = configs.map do |name|
|
192
|
-
configurable = configurable_values(
|
193
|
-
default = format_table_value(
|
192
|
+
configurable = configurable_values(cop_config, name)
|
193
|
+
default = format_table_value(cop_config[name])
|
194
194
|
|
195
195
|
[configuration_name(department, name), default, configurable]
|
196
196
|
end
|
@@ -206,17 +206,17 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
206
206
|
end
|
207
207
|
|
208
208
|
# rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
|
209
|
-
def configurable_values(
|
209
|
+
def configurable_values(cop_config, name)
|
210
210
|
case name
|
211
211
|
when /^Enforced/
|
212
212
|
supported_style_name = RuboCop::Cop::Util.to_supported_styles(name)
|
213
|
-
format_table_value(
|
213
|
+
format_table_value(cop_config[supported_style_name])
|
214
214
|
when 'IndentationWidth'
|
215
215
|
'Integer'
|
216
216
|
when 'Database'
|
217
|
-
format_table_value(
|
217
|
+
format_table_value(cop_config['SupportedDatabases'])
|
218
218
|
else
|
219
|
-
case
|
219
|
+
case cop_config[name]
|
220
220
|
when String
|
221
221
|
'String'
|
222
222
|
when Integer
|
@@ -319,7 +319,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
319
319
|
AutoCorrect Description Enabled StyleGuide Reference Safe SafeAutoCorrect VersionAdded
|
320
320
|
VersionChanged
|
321
321
|
]
|
322
|
-
|
322
|
+
parameters = cop_config.reject { |k| non_display_keys.include? k }
|
323
323
|
description = 'No documentation'
|
324
324
|
example_objects = safety_objects = see_objects = []
|
325
325
|
cop_code(cop) do |code_object|
|
@@ -329,7 +329,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
329
329
|
see_objects = code_object.tags('see')
|
330
330
|
end
|
331
331
|
data = CopData.new(cop: cop, description: description, example_objects: example_objects,
|
332
|
-
safety_objects: safety_objects, see_objects: see_objects, config:
|
332
|
+
safety_objects: safety_objects, see_objects: see_objects, config: parameters)
|
333
333
|
cops_body(data)
|
334
334
|
end
|
335
335
|
|
@@ -88,10 +88,15 @@ module RuboCop
|
|
88
88
|
@cop_names ||= all_cops? ? all_cop_names : parsed_cop_names
|
89
89
|
end
|
90
90
|
|
91
|
+
# Returns an array of cops for this directive comment, without resolving departments
|
92
|
+
def raw_cop_names
|
93
|
+
@raw_cop_names ||= (cops || '').split(/,\s*/)
|
94
|
+
end
|
95
|
+
|
91
96
|
# Returns array of specified in this directive department names
|
92
97
|
# when all department disabled
|
93
98
|
def department_names
|
94
|
-
|
99
|
+
raw_cop_names.select { |cop| department?(cop) }
|
95
100
|
end
|
96
101
|
|
97
102
|
# Checks if directive departments include cop
|
@@ -101,11 +106,11 @@ module RuboCop
|
|
101
106
|
|
102
107
|
# Checks if cop department has already used in directive comment
|
103
108
|
def overridden_by_department?(cop)
|
104
|
-
in_directive_department?(cop) &&
|
109
|
+
in_directive_department?(cop) && raw_cop_names.include?(cop)
|
105
110
|
end
|
106
111
|
|
107
112
|
def directive_count
|
108
|
-
|
113
|
+
raw_cop_names.count
|
109
114
|
end
|
110
115
|
|
111
116
|
# Returns line number for directive
|
@@ -115,12 +120,8 @@ module RuboCop
|
|
115
120
|
|
116
121
|
private
|
117
122
|
|
118
|
-
def splitted_cops_string
|
119
|
-
(cops || '').split(/,\s*/)
|
120
|
-
end
|
121
|
-
|
122
123
|
def parsed_cop_names
|
123
|
-
cops =
|
124
|
+
cops = raw_cop_names.map do |name|
|
124
125
|
department?(name) ? cop_names_for_department(name) : name
|
125
126
|
end.flatten
|
126
127
|
cops - [LINT_SYNTAX_COP]
|
data/lib/rubocop/options.rb
CHANGED
@@ -579,7 +579,8 @@ module RuboCop
|
|
579
579
|
'when combined with --display-only-correctable.'],
|
580
580
|
show_cops: ['Shows the given cops, or all cops by',
|
581
581
|
'default, and their configurations for the',
|
582
|
-
'current directory.'
|
582
|
+
'current directory.',
|
583
|
+
'You can use `*` as a wildcard.'],
|
583
584
|
show_docs_url: ['Display url to documentation for the given',
|
584
585
|
'cops, or base url by default.'],
|
585
586
|
fail_fast: ['Inspect files in order of modification',
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -25,16 +25,16 @@ module RuboCop
|
|
25
25
|
# cleaning should be done relatively seldom, since there is a slight risk
|
26
26
|
# that some other RuboCop process was just about to read the file, when
|
27
27
|
# there's parallel execution and the cache is shared.
|
28
|
-
def self.cleanup(config_store, verbose,
|
28
|
+
def self.cleanup(config_store, verbose, cache_root_override = nil)
|
29
29
|
return if inhibit_cleanup # OPTIMIZE: For faster testing
|
30
30
|
|
31
|
-
|
32
|
-
return unless File.exist?(
|
31
|
+
rubocop_cache_dir = cache_root(config_store, cache_root_override)
|
32
|
+
return unless File.exist?(rubocop_cache_dir)
|
33
33
|
|
34
|
-
files, dirs = Find.find(
|
34
|
+
files, dirs = Find.find(rubocop_cache_dir).partition { |path| File.file?(path) }
|
35
35
|
return unless requires_file_removal?(files.length, config_store)
|
36
36
|
|
37
|
-
remove_oldest_files(files, dirs,
|
37
|
+
remove_oldest_files(files, dirs, rubocop_cache_dir, verbose)
|
38
38
|
end
|
39
39
|
|
40
40
|
class << self
|
@@ -49,11 +49,11 @@ module RuboCop
|
|
49
49
|
file_count > 1 && file_count > config_store.for_pwd.for_all_cops['MaxFilesInCache']
|
50
50
|
end
|
51
51
|
|
52
|
-
def remove_oldest_files(files, dirs,
|
52
|
+
def remove_oldest_files(files, dirs, rubocop_cache_dir, verbose)
|
53
53
|
# Add 1 to half the number of files, so that we remove the file if
|
54
54
|
# there's only 1 left.
|
55
55
|
remove_count = (files.length / 2) + 1
|
56
|
-
puts "Removing the #{remove_count} oldest files from #{
|
56
|
+
puts "Removing the #{remove_count} oldest files from #{rubocop_cache_dir}" if verbose
|
57
57
|
sorted = files.sort_by { |path| File.mtime(path) }
|
58
58
|
remove_files(sorted, dirs, remove_count)
|
59
59
|
rescue Errno::ENOENT
|
@@ -72,9 +72,9 @@ module RuboCop
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
def self.cache_root(config_store)
|
75
|
+
def self.cache_root(config_store, cache_root_override = nil)
|
76
76
|
CacheConfig.root_dir do
|
77
|
-
config_store.for_pwd.for_all_cops['CacheRootDirectory']
|
77
|
+
cache_root_override || config_store.for_pwd.for_all_cops['CacheRootDirectory']
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -84,12 +84,12 @@ module RuboCop
|
|
84
84
|
|
85
85
|
attr_reader :path
|
86
86
|
|
87
|
-
def initialize(file, team, options, config_store,
|
88
|
-
|
89
|
-
|
87
|
+
def initialize(file, team, options, config_store, cache_root_override = nil)
|
88
|
+
cache_root_override ||= options[:cache_root] if options[:cache_root]
|
89
|
+
rubocop_cache_dir = ResultCache.cache_root(config_store, cache_root_override)
|
90
90
|
@allow_symlinks_in_cache_location =
|
91
91
|
ResultCache.allow_symlinks_in_cache_location?(config_store)
|
92
|
-
@path = File.join(
|
92
|
+
@path = File.join(rubocop_cache_dir,
|
93
93
|
rubocop_checksum,
|
94
94
|
context_checksum(team, options),
|
95
95
|
file_checksum(file, config_store))
|
@@ -190,7 +190,10 @@ module RuboCop
|
|
190
190
|
def expect_no_offenses(source, file = nil)
|
191
191
|
offenses = inspect_source(source, file)
|
192
192
|
|
193
|
-
|
193
|
+
# Since source given `expect_no_offenses` does not have annotations, we do not need to parse
|
194
|
+
# for them, and can just build an `AnnotatedSource` object from the source lines.
|
195
|
+
# This also prevents treating source lines that begin with a caret as an annotation.
|
196
|
+
expected_annotations = AnnotatedSource.new(source.each_line.to_a, [])
|
194
197
|
actual_annotations = expected_annotations.with_offense_annotations(offenses)
|
195
198
|
expect(actual_annotations.to_s).to eq(source)
|
196
199
|
end
|
@@ -221,7 +224,8 @@ module RuboCop
|
|
221
224
|
|
222
225
|
# Parsed representation of code annotated with the `^^^ Message` style
|
223
226
|
class AnnotatedSource
|
224
|
-
|
227
|
+
# Ignore escaped carets, don't treat as annotations
|
228
|
+
ANNOTATION_PATTERN = /\A\s*((?<!\\)\^+|\^{}) ?/.freeze
|
225
229
|
ABBREV = "[...]\n"
|
226
230
|
|
227
231
|
# @param annotated_source [String] string passed to the matchers
|
@@ -4,13 +4,12 @@
|
|
4
4
|
|
5
5
|
require_relative 'cop_helper'
|
6
6
|
require_relative 'expect_offense'
|
7
|
-
require_relative 'host_environment_simulation_helper'
|
8
7
|
require_relative 'parallel_formatter'
|
9
8
|
require_relative 'shared_contexts'
|
10
9
|
|
11
10
|
RSpec.configure do |config|
|
12
11
|
config.include CopHelper
|
13
|
-
config.include
|
12
|
+
config.include RuboCop::RSpec::ExpectOffense
|
14
13
|
config.include_context 'config', :config
|
15
14
|
config.include_context 'isolated environment', :isolated_environment
|
16
15
|
config.include_context 'isolated bundler', :isolated_bundler
|
@@ -127,6 +127,7 @@ module RuboCop
|
|
127
127
|
if mode == :only_recognized_file_types || force_exclusion?
|
128
128
|
files.select! { |file| included_file?(file) }
|
129
129
|
end
|
130
|
+
files.reject! { |file| FileTest.directory?(file) }
|
130
131
|
|
131
132
|
force_exclusion? ? without_excluded(files) : files
|
132
133
|
end
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
@@ -100,6 +100,7 @@ require_relative 'rubocop/cop/mixin/frozen_string_literal'
|
|
100
100
|
require_relative 'rubocop/cop/mixin/gem_declaration'
|
101
101
|
require_relative 'rubocop/cop/mixin/gemspec_help'
|
102
102
|
require_relative 'rubocop/cop/mixin/hash_alignment_styles'
|
103
|
+
require_relative 'rubocop/cop/mixin/hash_subset'
|
103
104
|
require_relative 'rubocop/cop/mixin/hash_transform_method'
|
104
105
|
require_relative 'rubocop/cop/mixin/integer_node'
|
105
106
|
require_relative 'rubocop/cop/mixin/interpolation'
|
@@ -293,6 +294,7 @@ require_relative 'rubocop/cop/lint/ambiguous_operator'
|
|
293
294
|
require_relative 'rubocop/cop/lint/ambiguous_operator_precedence'
|
294
295
|
require_relative 'rubocop/cop/lint/ambiguous_range'
|
295
296
|
require_relative 'rubocop/cop/lint/ambiguous_regexp_literal'
|
297
|
+
require_relative 'rubocop/cop/lint/array_literal_in_regexp'
|
296
298
|
require_relative 'rubocop/cop/lint/assignment_in_condition'
|
297
299
|
require_relative 'rubocop/cop/lint/big_decimal_new'
|
298
300
|
require_relative 'rubocop/cop/lint/binary_operator_with_identical_operands'
|
@@ -559,6 +561,7 @@ require_relative 'rubocop/cop/style/hash_conversion'
|
|
559
561
|
require_relative 'rubocop/cop/style/hash_each_methods'
|
560
562
|
require_relative 'rubocop/cop/style/hash_except'
|
561
563
|
require_relative 'rubocop/cop/style/hash_like_case'
|
564
|
+
require_relative 'rubocop/cop/style/hash_slice'
|
562
565
|
require_relative 'rubocop/cop/style/hash_syntax'
|
563
566
|
require_relative 'rubocop/cop/style/hash_transform_keys'
|
564
567
|
require_relative 'rubocop/cop/style/hash_transform_values'
|
metadata
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.71.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
8
8
|
- Jonas Arvidsson
|
9
9
|
- Yuji Nakayama
|
10
|
-
autorequire:
|
11
10
|
bindir: exe
|
12
11
|
cert_chain: []
|
13
|
-
date: 2025-
|
12
|
+
date: 2025-02-04 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: json
|
@@ -114,7 +113,7 @@ dependencies:
|
|
114
113
|
requirements:
|
115
114
|
- - ">="
|
116
115
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.
|
116
|
+
version: 1.38.0
|
118
117
|
- - "<"
|
119
118
|
- !ruby/object:Gem::Version
|
120
119
|
version: '2.0'
|
@@ -124,7 +123,7 @@ dependencies:
|
|
124
123
|
requirements:
|
125
124
|
- - ">="
|
126
125
|
- !ruby/object:Gem::Version
|
127
|
-
version: 1.
|
126
|
+
version: 1.38.0
|
128
127
|
- - "<"
|
129
128
|
- !ruby/object:Gem::Version
|
130
129
|
version: '2.0'
|
@@ -280,9 +279,14 @@ files:
|
|
280
279
|
- lib/rubocop/cop/internal_affairs/node_destructuring.rb
|
281
280
|
- lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb
|
282
281
|
- lib/rubocop/cop/internal_affairs/node_matcher_directive.rb
|
282
|
+
- lib/rubocop/cop/internal_affairs/node_pattern_groups.rb
|
283
|
+
- lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb
|
284
|
+
- lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb
|
285
|
+
- lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb
|
283
286
|
- lib/rubocop/cop/internal_affairs/node_type_predicate.rb
|
284
287
|
- lib/rubocop/cop/internal_affairs/numblock_handler.rb
|
285
288
|
- lib/rubocop/cop/internal_affairs/offense_location_keyword.rb
|
289
|
+
- lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb
|
286
290
|
- lib/rubocop/cop/internal_affairs/operator_keyword.rb
|
287
291
|
- lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb
|
288
292
|
- lib/rubocop/cop/internal_affairs/redundant_context_config_parameter.rb
|
@@ -405,6 +409,7 @@ files:
|
|
405
409
|
- lib/rubocop/cop/lint/ambiguous_operator_precedence.rb
|
406
410
|
- lib/rubocop/cop/lint/ambiguous_range.rb
|
407
411
|
- lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
|
412
|
+
- lib/rubocop/cop/lint/array_literal_in_regexp.rb
|
408
413
|
- lib/rubocop/cop/lint/assignment_in_condition.rb
|
409
414
|
- lib/rubocop/cop/lint/big_decimal_new.rb
|
410
415
|
- lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb
|
@@ -595,6 +600,7 @@ files:
|
|
595
600
|
- lib/rubocop/cop/mixin/gemspec_help.rb
|
596
601
|
- lib/rubocop/cop/mixin/hash_alignment_styles.rb
|
597
602
|
- lib/rubocop/cop/mixin/hash_shorthand_syntax.rb
|
603
|
+
- lib/rubocop/cop/mixin/hash_subset.rb
|
598
604
|
- lib/rubocop/cop/mixin/hash_transform_method.rb
|
599
605
|
- lib/rubocop/cop/mixin/heredoc.rb
|
600
606
|
- lib/rubocop/cop/mixin/integer_node.rb
|
@@ -757,6 +763,7 @@ files:
|
|
757
763
|
- lib/rubocop/cop/style/hash_each_methods.rb
|
758
764
|
- lib/rubocop/cop/style/hash_except.rb
|
759
765
|
- lib/rubocop/cop/style/hash_like_case.rb
|
766
|
+
- lib/rubocop/cop/style/hash_slice.rb
|
760
767
|
- lib/rubocop/cop/style/hash_syntax.rb
|
761
768
|
- lib/rubocop/cop/style/hash_transform_keys.rb
|
762
769
|
- lib/rubocop/cop/style/hash_transform_values.rb
|
@@ -1006,7 +1013,6 @@ files:
|
|
1006
1013
|
- lib/rubocop/result_cache.rb
|
1007
1014
|
- lib/rubocop/rspec/cop_helper.rb
|
1008
1015
|
- lib/rubocop/rspec/expect_offense.rb
|
1009
|
-
- lib/rubocop/rspec/host_environment_simulation_helper.rb
|
1010
1016
|
- lib/rubocop/rspec/parallel_formatter.rb
|
1011
1017
|
- lib/rubocop/rspec/shared_contexts.rb
|
1012
1018
|
- lib/rubocop/rspec/support.rb
|
@@ -1043,12 +1049,11 @@ licenses:
|
|
1043
1049
|
- MIT
|
1044
1050
|
metadata:
|
1045
1051
|
homepage_uri: https://rubocop.org/
|
1046
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.
|
1052
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.71.2
|
1047
1053
|
source_code_uri: https://github.com/rubocop/rubocop/
|
1048
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
1054
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.71/
|
1049
1055
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|
1050
1056
|
rubygems_mfa_required: 'true'
|
1051
|
-
post_install_message:
|
1052
1057
|
rdoc_options: []
|
1053
1058
|
require_paths:
|
1054
1059
|
- lib
|
@@ -1063,8 +1068,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1063
1068
|
- !ruby/object:Gem::Version
|
1064
1069
|
version: '0'
|
1065
1070
|
requirements: []
|
1066
|
-
rubygems_version: 3.
|
1067
|
-
signing_key:
|
1071
|
+
rubygems_version: 3.6.2
|
1068
1072
|
specification_version: 4
|
1069
1073
|
summary: Automatic Ruby code style checking tool.
|
1070
1074
|
test_files: []
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# RuboCop can be run in contexts where unexpected other libraries are included,
|
4
|
-
# which may interfere with its normal behavior. In order to test those
|
5
|
-
# situations, it may be necessary to require another library for the duration
|
6
|
-
# of one spec
|
7
|
-
module HostEnvironmentSimulatorHelper
|
8
|
-
def in_its_own_process_with(*files)
|
9
|
-
if ::Process.respond_to?(:fork)
|
10
|
-
pid = ::Process.fork do
|
11
|
-
# Need to write coverage result under different name
|
12
|
-
if defined?(SimpleCov)
|
13
|
-
SimpleCov.command_name "rspec-fork-#{Process.pid}"
|
14
|
-
SimpleCov.pid = Process.pid
|
15
|
-
end
|
16
|
-
|
17
|
-
files.each { |file| require file }
|
18
|
-
yield
|
19
|
-
end
|
20
|
-
::Process.wait(pid)
|
21
|
-
|
22
|
-
# assert that the block did not fail
|
23
|
-
expect($CHILD_STATUS).to be_success
|
24
|
-
else
|
25
|
-
warn 'Process.fork is not available.'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|