rubocop 1.89.0 → 1.90.0
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 +74 -7
- data/exe/rubocop +1 -1
- data/lib/rubocop/cached_data.rb +7 -2
- data/lib/rubocop/cli/command/execute_runner.rb +31 -0
- data/lib/rubocop/cli.rb +2 -4
- data/lib/rubocop/comment_config/directive_range.rb +32 -0
- data/lib/rubocop/comment_config/disable_next.rb +97 -0
- data/lib/rubocop/comment_config.rb +46 -30
- data/lib/rubocop/config.rb +23 -5
- data/lib/rubocop/config_loader.rb +1 -2
- data/lib/rubocop/config_loader_resolver.rb +1 -2
- data/lib/rubocop/config_validator.rb +1 -2
- data/lib/rubocop/cop/autocorrect_logic.rb +8 -0
- data/lib/rubocop/cop/base.rb +34 -2
- data/lib/rubocop/cop/corrector.rb +3 -3
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -2
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +1 -2
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -2
- data/lib/rubocop/cop/layout/class_structure.rb +102 -26
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -2
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +63 -5
- data/lib/rubocop/cop/layout/end_alignment.rb +1 -2
- data/lib/rubocop/cop/layout/extra_spacing.rb +105 -3
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +21 -1
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -2
- data/lib/rubocop/cop/layout/line_length.rb +1 -2
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -2
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +5 -5
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +1 -2
- data/lib/rubocop/cop/layout/space_around_operators.rb +7 -0
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +2 -4
- data/lib/rubocop/cop/lint/ambiguous_range.rb +1 -2
- data/lib/rubocop/cop/lint/argument_mismatch.rb +89 -0
- data/lib/rubocop/cop/lint/constant_reassignment.rb +17 -11
- data/lib/rubocop/cop/lint/cop_directive_syntax.rb +84 -8
- data/lib/rubocop/cop/lint/deprecated_reference.rb +11 -2
- data/lib/rubocop/cop/lint/duplicate_methods.rb +112 -14
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -2
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -2
- data/lib/rubocop/cop/lint/interpolation_check.rb +1 -2
- data/lib/rubocop/cop/lint/literal_as_condition.rb +3 -6
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +3 -6
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +25 -12
- data/lib/rubocop/cop/lint/name_typo.rb +53 -6
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +15 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +98 -19
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +47 -7
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -2
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -2
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -2
- data/lib/rubocop/cop/lint/redundant_type_conversion.rb +1 -2
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -2
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -2
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +2 -4
- data/lib/rubocop/cop/lint/super_argument_mismatch.rb +179 -0
- data/lib/rubocop/cop/lint/suppressed_exception_in_number_conversion.rb +1 -2
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -2
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -2
- data/lib/rubocop/cop/lint/unused_private_method.rb +94 -17
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -2
- data/lib/rubocop/cop/lint/useless_assignment.rb +1 -2
- data/lib/rubocop/cop/lint/useless_constant_scoping.rb +36 -0
- data/lib/rubocop/cop/lint/useless_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/useless_rescue.rb +1 -2
- data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +61 -7
- data/lib/rubocop/cop/lint/void.rb +1 -2
- data/lib/rubocop/cop/lint.rb +2 -0
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -2
- data/lib/rubocop/cop/migration/department_name.rb +1 -2
- data/lib/rubocop/cop/mixin/comments_help.rb +1 -2
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -2
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +1 -2
- data/lib/rubocop/cop/mixin/hash_subset.rb +1 -2
- data/lib/rubocop/cop/mixin/indexed_method_arity.rb +94 -0
- data/lib/rubocop/cop/mixin/line_length_help.rb +7 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +51 -6
- data/lib/rubocop/cop/mixin/range_help.rb +1 -2
- data/lib/rubocop/cop/mixin/statement_modifier.rb +13 -7
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
- data/lib/rubocop/cop/mixin.rb +4 -0
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +16 -0
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -4
- data/lib/rubocop/cop/naming/method_name.rb +5 -2
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -2
- data/lib/rubocop/cop/offense.rb +27 -4
- data/lib/rubocop/cop/registry.rb +34 -10
- data/lib/rubocop/cop/style/accessor_grouping.rb +1 -2
- data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -6
- data/lib/rubocop/cop/style/array_first_last.rb +1 -2
- data/lib/rubocop/cop/style/bitwise_predicate.rb +1 -2
- data/lib/rubocop/cop/style/block_delimiters.rb +3 -6
- data/lib/rubocop/cop/style/case_like_if.rb +2 -4
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -2
- data/lib/rubocop/cop/style/combinable_loops.rb +1 -2
- data/lib/rubocop/cop/style/concat_array_literals.rb +1 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -2
- data/lib/rubocop/cop/style/constant_visibility.rb +1 -2
- data/lib/rubocop/cop/style/copyright.rb +1 -2
- data/lib/rubocop/cop/style/directive_scope.rb +171 -0
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +36 -10
- data/lib/rubocop/cop/style/empty_case_condition.rb +1 -2
- data/lib/rubocop/cop/style/format_string_token.rb +1 -2
- data/lib/rubocop/cop/style/guard_clause.rb +1 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +1 -2
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -2
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +2 -4
- data/lib/rubocop/cop/style/if_inside_else.rb +1 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -2
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +1 -2
- data/lib/rubocop/cop/style/map_to_hash.rb +1 -2
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -2
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -2
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -2
- data/lib/rubocop/cop/style/negative_array_index.rb +2 -4
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -2
- data/lib/rubocop/cop/style/operator_method_call.rb +1 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -2
- data/lib/rubocop/cop/style/redundant_assignment.rb +1 -2
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -4
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +1 -2
- data/lib/rubocop/cop/style/redundant_each.rb +1 -2
- data/lib/rubocop/cop/style/redundant_format.rb +2 -4
- data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +1 -2
- data/lib/rubocop/cop/style/redundant_return.rb +1 -2
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -2
- data/lib/rubocop/cop/style/redundant_string_escape.rb +1 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +1 -2
- data/lib/rubocop/cop/style/sample.rb +11 -6
- data/lib/rubocop/cop/style/select_by_regexp.rb +1 -2
- data/lib/rubocop/cop/style/semicolon.rb +2 -4
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +1 -2
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +1 -2
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +2 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +18 -5
- data/lib/rubocop/cop/style/super_arguments.rb +1 -2
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -2
- data/lib/rubocop/cop/style/time_now.rb +41 -0
- data/lib/rubocop/cop/style/yoda_condition.rb +1 -2
- data/lib/rubocop/cop/style.rb +2 -0
- data/lib/rubocop/cop/team.rb +11 -3
- data/lib/rubocop/cop/util.rb +2 -4
- data/lib/rubocop/cop/variable_force/variable.rb +1 -2
- data/lib/rubocop/cops_documentation_generator.rb +3 -6
- data/lib/rubocop/directive_comment.rb +37 -3
- data/lib/rubocop/formatter/emacs_style_formatter.rb +3 -1
- data/lib/rubocop/formatter/html_formatter.rb +2 -4
- data/lib/rubocop/formatter/json_formatter.rb +11 -6
- data/lib/rubocop/formatter/junit_formatter.rb +26 -9
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -2
- data/lib/rubocop/formatter/simple_text_formatter.rb +4 -3
- data/lib/rubocop/formatter/tap_formatter.rb +3 -1
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -2
- data/lib/rubocop/lockfile.rb +18 -0
- data/lib/rubocop/lsp/diagnostic.rb +4 -8
- data/lib/rubocop/lsp/routes.rb +48 -19
- data/lib/rubocop/mcp/server.rb +1 -2
- data/lib/rubocop/options.rb +10 -6
- data/lib/rubocop/path_util.rb +1 -2
- data/lib/rubocop/plugin/configuration_integrator.rb +6 -3
- data/lib/rubocop/rake_task.rb +1 -2
- data/lib/rubocop/rspec/expect_offense.rb +2 -4
- data/lib/rubocop/rspec/shared_contexts.rb +4 -2
- data/lib/rubocop/runner.rb +26 -23
- data/lib/rubocop/server/cache.rb +1 -2
- data/lib/rubocop/server/cli.rb +2 -4
- data/lib/rubocop/server.rb +14 -0
- data/lib/rubocop/target_finder.rb +4 -1
- data/lib/rubocop/todo_audit.rb +111 -0
- data/lib/rubocop/version.rb +3 -5
- data/lib/rubocop.rb +3 -0
- data/lib/ruby_lsp/rubocop/addon.rb +1 -2
- metadata +13 -5
|
@@ -91,7 +91,7 @@ module RuboCop
|
|
|
91
91
|
[Style::Next, Style::SoleNestedConditional]
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
94
|
+
# rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
95
95
|
def on_if(node)
|
|
96
96
|
return if endless_method?(node.body) || node.each_ancestor(:dstr).any?
|
|
97
97
|
|
|
@@ -109,7 +109,6 @@ module RuboCop
|
|
|
109
109
|
ignore_node(node)
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
113
112
|
|
|
114
113
|
private
|
|
115
114
|
|
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
|
28
28
|
|
|
29
29
|
MSG = 'Avoid modifier `%<keyword>s` after another conditional.'
|
|
30
30
|
|
|
31
|
-
# rubocop:disable Metrics/AbcSize
|
|
31
|
+
# rubocop:disable-next Metrics/AbcSize
|
|
32
32
|
def on_if(node)
|
|
33
33
|
return unless node.modifier_form? && node.body.if_type?
|
|
34
34
|
|
|
@@ -37,7 +37,6 @@ module RuboCop
|
|
|
37
37
|
corrector.remove(node.if_branch.source_range.end.join(node.condition.source_range.end))
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
|
-
# rubocop:enable Metrics/AbcSize
|
|
41
40
|
end
|
|
42
41
|
end
|
|
43
42
|
end
|
|
@@ -67,7 +67,7 @@ module RuboCop
|
|
|
67
67
|
|
|
68
68
|
private
|
|
69
69
|
|
|
70
|
-
# rubocop:disable Metrics/AbcSize
|
|
70
|
+
# rubocop:disable-next Metrics/AbcSize
|
|
71
71
|
def autocorrect(corrector, to_h, map)
|
|
72
72
|
removal_range = range_between(to_h.loc.dot.begin_pos, to_h.loc.selector.end_pos)
|
|
73
73
|
|
|
@@ -83,7 +83,6 @@ module RuboCop
|
|
|
83
83
|
corrector.replace(argument, argument.source[1..-2])
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
|
-
# rubocop:enable Metrics/AbcSize
|
|
87
86
|
end
|
|
88
87
|
end
|
|
89
88
|
end
|
|
@@ -5,7 +5,7 @@ module RuboCop
|
|
|
5
5
|
module Style
|
|
6
6
|
class MethodCallWithArgsParentheses
|
|
7
7
|
# Style omit_parentheses
|
|
8
|
-
# rubocop:disable Metrics/ModuleLength, Metrics/CyclomaticComplexity
|
|
8
|
+
# rubocop:disable-next Metrics/ModuleLength, Metrics/CyclomaticComplexity
|
|
9
9
|
module OmitParentheses
|
|
10
10
|
include RangeHelp
|
|
11
11
|
include ReparsedEquivalence
|
|
@@ -150,7 +150,7 @@ module RuboCop
|
|
|
150
150
|
node.parent&.class_type? && node.parent.single_line?
|
|
151
151
|
end
|
|
152
152
|
|
|
153
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
|
153
|
+
# rubocop:disable-next Metrics/PerceivedComplexity
|
|
154
154
|
def call_with_ambiguous_arguments?(node)
|
|
155
155
|
call_with_braced_block?(node) ||
|
|
156
156
|
call_in_argument_with_block?(node) ||
|
|
@@ -163,7 +163,6 @@ module RuboCop
|
|
|
163
163
|
ambiguous_literal?(n) || logical_operator?(n)
|
|
164
164
|
end
|
|
165
165
|
end
|
|
166
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
|
167
166
|
|
|
168
167
|
def call_with_braced_block?(node)
|
|
169
168
|
node.type?(:call, :super) && node.block_node&.braces?
|
|
@@ -269,7 +268,6 @@ module RuboCop
|
|
|
269
268
|
last_argument.hash_type? && last_argument.children.any?(&:forwarded_kwrestarg_type?)
|
|
270
269
|
end
|
|
271
270
|
end
|
|
272
|
-
# rubocop:enable Metrics/ModuleLength, Metrics/CyclomaticComplexity
|
|
273
271
|
end
|
|
274
272
|
end
|
|
275
273
|
end
|
|
@@ -33,7 +33,7 @@ module RuboCop
|
|
|
33
33
|
|
|
34
34
|
MSG = 'Do not use parentheses for method calls with no arguments.'
|
|
35
35
|
|
|
36
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
|
36
|
+
# rubocop:disable-next Metrics/CyclomaticComplexity
|
|
37
37
|
def on_send(node)
|
|
38
38
|
return unless !node.arguments? && node.parenthesized?
|
|
39
39
|
return if ineligible_node?(node)
|
|
@@ -44,7 +44,6 @@ module RuboCop
|
|
|
44
44
|
|
|
45
45
|
register_offense(node)
|
|
46
46
|
end
|
|
47
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
|
48
47
|
alias on_csend on_send
|
|
49
48
|
|
|
50
49
|
private
|
|
@@ -38,7 +38,7 @@ module RuboCop
|
|
|
38
38
|
|
|
39
39
|
private
|
|
40
40
|
|
|
41
|
-
# rubocop:disable Metrics/AbcSize
|
|
41
|
+
# rubocop:disable-next Metrics/AbcSize
|
|
42
42
|
def autocorrect(corrector, node, begin_of_arguments)
|
|
43
43
|
arguments = node.arguments
|
|
44
44
|
joined_arguments = arguments.map(&:source).join(', ')
|
|
@@ -62,7 +62,6 @@ module RuboCop
|
|
|
62
62
|
corrector.remove(arguments_range)
|
|
63
63
|
corrector.insert_after(begin_of_arguments, joined_arguments)
|
|
64
64
|
end
|
|
65
|
-
# rubocop:enable Metrics/AbcSize
|
|
66
65
|
|
|
67
66
|
def last_line_source_of_arguments(arguments)
|
|
68
67
|
processed_source[arguments.last_line - 1].strip
|
|
@@ -46,7 +46,7 @@ module RuboCop
|
|
|
46
46
|
@corrected_nodes = nil
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
# rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
|
|
49
|
+
# rubocop:disable-next Metrics/AbcSize,Metrics/CyclomaticComplexity
|
|
50
50
|
def on_if(node)
|
|
51
51
|
return unless if_else?(node)
|
|
52
52
|
return unless (condition = unwrap_begin_nodes(node.condition))
|
|
@@ -64,7 +64,6 @@ module RuboCop
|
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
|
-
# rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity
|
|
68
67
|
|
|
69
68
|
private
|
|
70
69
|
|
|
@@ -91,7 +91,7 @@ module RuboCop
|
|
|
91
91
|
end
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
|
94
|
+
# rubocop:disable-next Metrics/CyclomaticComplexity
|
|
95
95
|
def range_with_length_subtraction?(range_node, array_receiver)
|
|
96
96
|
return false unless range_node&.range_type?
|
|
97
97
|
|
|
@@ -108,7 +108,6 @@ module RuboCop
|
|
|
108
108
|
|
|
109
109
|
receivers_match_strict?(length_receiver, array_receiver)
|
|
110
110
|
end
|
|
111
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
|
112
111
|
|
|
113
112
|
def handle_range_pattern(receiver, range_node, index_arg)
|
|
114
113
|
range_end = range_node.end
|
|
@@ -124,7 +123,7 @@ module RuboCop
|
|
|
124
123
|
end
|
|
125
124
|
end
|
|
126
125
|
|
|
127
|
-
# rubocop:disable Metrics/ParameterLists
|
|
126
|
+
# rubocop:disable-next Metrics/ParameterLists
|
|
128
127
|
def build_range_offense_data(receiver, range_node, range_end, inner_end, negative_index,
|
|
129
128
|
index_arg)
|
|
130
129
|
range_op = range_node.erange_type? ? '...' : '..'
|
|
@@ -140,7 +139,6 @@ module RuboCop
|
|
|
140
139
|
|
|
141
140
|
[message, replacement]
|
|
142
141
|
end
|
|
143
|
-
# rubocop:enable Metrics/ParameterLists
|
|
144
142
|
|
|
145
143
|
def format_range_message_parts(range_start, negative_index, index_arg)
|
|
146
144
|
has_parentheses = index_arg.begin_type?
|
|
@@ -42,7 +42,7 @@ module RuboCop
|
|
|
42
42
|
# @!method nil_check?(node)
|
|
43
43
|
def_node_matcher :nil_check?, '(send _ :nil?)'
|
|
44
44
|
|
|
45
|
-
# rubocop:disable Metrics/AbcSize
|
|
45
|
+
# rubocop:disable-next Metrics/AbcSize
|
|
46
46
|
def on_send(node)
|
|
47
47
|
return unless node.receiver
|
|
48
48
|
|
|
@@ -61,7 +61,6 @@ module RuboCop
|
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
|
-
# rubocop:enable Metrics/AbcSize
|
|
65
64
|
|
|
66
65
|
private
|
|
67
66
|
|
|
@@ -26,7 +26,7 @@ module RuboCop
|
|
|
26
26
|
splat kwsplat forwarded_args forwarded_restarg forwarded_kwrestarg block_pass
|
|
27
27
|
].freeze
|
|
28
28
|
|
|
29
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
29
|
+
# rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
30
30
|
def on_send(node)
|
|
31
31
|
return unless (dot = node.loc.dot)
|
|
32
32
|
return if unary_method_no_operator?(node)
|
|
@@ -44,7 +44,6 @@ module RuboCop
|
|
|
44
44
|
corrector.insert_after(selector, ' ') if insert_space_after?(node)
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
48
47
|
|
|
49
48
|
private
|
|
50
49
|
|
|
@@ -184,9 +184,8 @@ module RuboCop
|
|
|
184
184
|
def accesses?(rhs, lhs)
|
|
185
185
|
if lhs.method?(:[]=)
|
|
186
186
|
# FIXME: Workaround `rubocop:disable` comment for JRuby.
|
|
187
|
-
# rubocop:disable Performance/RedundantEqualityComparisonBlock
|
|
187
|
+
# rubocop:disable-next Performance/RedundantEqualityComparisonBlock
|
|
188
188
|
matching_calls(rhs, lhs.receiver, :[]).any? { |args| args == lhs.arguments }
|
|
189
|
-
# rubocop:enable Performance/RedundantEqualityComparisonBlock
|
|
190
189
|
else
|
|
191
190
|
access_method = lhs.method_name.to_s.chop.to_sym
|
|
192
191
|
matching_calls(rhs, lhs.receiver, access_method).any?
|
|
@@ -57,7 +57,7 @@ module RuboCop
|
|
|
57
57
|
|
|
58
58
|
private
|
|
59
59
|
|
|
60
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
|
60
|
+
# rubocop:disable-next Metrics/CyclomaticComplexity
|
|
61
61
|
def check_branch(node)
|
|
62
62
|
return unless node
|
|
63
63
|
|
|
@@ -72,7 +72,6 @@ module RuboCop
|
|
|
72
72
|
check_begin_node(node)
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
|
76
75
|
|
|
77
76
|
def check_case_node(node)
|
|
78
77
|
node.when_branches.each { |when_node| check_branch(when_node.body) }
|
|
@@ -180,7 +180,7 @@ module RuboCop
|
|
|
180
180
|
!use_hash_key_access?(if_branch)
|
|
181
181
|
end
|
|
182
182
|
|
|
183
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
183
|
+
# rubocop:disable-next Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
184
184
|
def if_branch_is_true_type_and_else_is_not?(node)
|
|
185
185
|
return false unless node.ternary? || node.if?
|
|
186
186
|
|
|
@@ -190,7 +190,6 @@ module RuboCop
|
|
|
190
190
|
|
|
191
191
|
node.if_branch&.true_type? && node.else_branch && !node.else_branch.true_type?
|
|
192
192
|
end
|
|
193
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
194
193
|
|
|
195
194
|
def branches_have_assignment?(node)
|
|
196
195
|
_condition, if_branch, else_branch = *node # rubocop:disable InternalAffairs/NodeDestructuring
|
|
@@ -240,7 +239,7 @@ module RuboCop
|
|
|
240
239
|
"#{method.source}(#{arguments.source})"
|
|
241
240
|
end
|
|
242
241
|
|
|
243
|
-
# rubocop:disable Metrics/AbcSize
|
|
242
|
+
# rubocop:disable-next Metrics/AbcSize
|
|
244
243
|
def if_source(if_branch, arithmetic_operation)
|
|
245
244
|
if branches_have_method?(if_branch.parent) && if_branch.parenthesized?
|
|
246
245
|
if_branch.source.delete_suffix(')')
|
|
@@ -257,7 +256,6 @@ module RuboCop
|
|
|
257
256
|
if_branch.source
|
|
258
257
|
end
|
|
259
258
|
end
|
|
260
|
-
# rubocop:enable Metrics/AbcSize
|
|
261
259
|
|
|
262
260
|
def else_source(else_branch, arithmetic_operation) # rubocop:disable Metrics/AbcSize
|
|
263
261
|
if arithmetic_operation
|
|
@@ -25,7 +25,7 @@ module RuboCop
|
|
|
25
25
|
MSG = 'Remove the redundant double splat and braces, use keyword arguments directly.'
|
|
26
26
|
MERGE_METHODS = %i[merge merge!].freeze
|
|
27
27
|
|
|
28
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
28
|
+
# rubocop:disable-next Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
29
29
|
def on_hash(node)
|
|
30
30
|
return if node.pairs.empty? || node.pairs.any?(&:hash_rocket?)
|
|
31
31
|
return unless (parent = node.parent)
|
|
@@ -38,7 +38,6 @@ module RuboCop
|
|
|
38
38
|
autocorrect(corrector, node, kwsplat)
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
42
41
|
|
|
43
42
|
private
|
|
44
43
|
|
|
@@ -60,7 +60,7 @@ module RuboCop
|
|
|
60
60
|
|
|
61
61
|
private
|
|
62
62
|
|
|
63
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
63
|
+
# rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
64
64
|
def redundant_each_method(node)
|
|
65
65
|
return if node.last_argument&.block_pass_type?
|
|
66
66
|
|
|
@@ -81,7 +81,6 @@ module RuboCop
|
|
|
81
81
|
|
|
82
82
|
prev_method if detected || prev_method.method?(:reverse_each)
|
|
83
83
|
end
|
|
84
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
85
84
|
|
|
86
85
|
def range(node)
|
|
87
86
|
return node.selector unless node.method?(:each)
|
|
@@ -155,7 +155,7 @@ module RuboCop
|
|
|
155
155
|
end
|
|
156
156
|
end
|
|
157
157
|
|
|
158
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
158
|
+
# rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
159
159
|
def all_fields_literal?(string, arguments)
|
|
160
160
|
count = 0
|
|
161
161
|
sequences = RuboCop::Cop::Utils::FormatString.new(string).format_sequences
|
|
@@ -175,7 +175,6 @@ module RuboCop
|
|
|
175
175
|
|
|
176
176
|
sequences.size == count
|
|
177
177
|
end
|
|
178
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
179
178
|
|
|
180
179
|
# If the sequence has a variable (`*`) width, it cannot be autocorrected
|
|
181
180
|
# if the width is not given as a numeric literal argument
|
|
@@ -186,7 +185,7 @@ module RuboCop
|
|
|
186
185
|
argument.nil? || !numeric?(argument)
|
|
187
186
|
end
|
|
188
187
|
|
|
189
|
-
# rubocop:disable Metrics/AbcSize
|
|
188
|
+
# rubocop:disable-next Metrics/AbcSize
|
|
190
189
|
def find_argument(sequence, arguments, hash)
|
|
191
190
|
if hash && (sequence.annotated? || sequence.template?)
|
|
192
191
|
find_hash_value_node(hash, sequence.name.to_sym).first
|
|
@@ -200,7 +199,6 @@ module RuboCop
|
|
|
200
199
|
arguments.shift
|
|
201
200
|
end
|
|
202
201
|
end
|
|
203
|
-
# rubocop:enable Metrics/AbcSize
|
|
204
202
|
|
|
205
203
|
def matching_argument?(sequence, argument)
|
|
206
204
|
# Template specifiers don't give a type, any acceptable literal type is ok.
|
|
@@ -152,7 +152,7 @@ module RuboCop
|
|
|
152
152
|
check_send(begin_node, node) if call_node?(node)
|
|
153
153
|
end
|
|
154
154
|
|
|
155
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
155
|
+
# rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
156
156
|
def find_offense_message(begin_node, node)
|
|
157
157
|
return 'a keyword' if keyword_with_redundant_parentheses?(node)
|
|
158
158
|
return 'a literal' if node.literal? && disallowed_literal?(begin_node, node)
|
|
@@ -189,7 +189,6 @@ module RuboCop
|
|
|
189
189
|
'a comparison expression'
|
|
190
190
|
end
|
|
191
191
|
end
|
|
192
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
193
192
|
|
|
194
193
|
# @!method interpolation?(node)
|
|
195
194
|
def_node_matcher :interpolation?, '[^begin ^^dstr]'
|
|
@@ -305,7 +304,7 @@ module RuboCop
|
|
|
305
304
|
parent.begin_type? && parent.children.one?
|
|
306
305
|
end
|
|
307
306
|
|
|
308
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
|
307
|
+
# rubocop:disable-next Metrics/CyclomaticComplexity
|
|
309
308
|
def body_range?(begin_node, node)
|
|
310
309
|
return false if begin_node.chained?
|
|
311
310
|
return false unless node.range_type?
|
|
@@ -315,7 +314,6 @@ module RuboCop
|
|
|
315
314
|
(node.begin.nil? && begin_node == parent.children.first) ||
|
|
316
315
|
(node.end.nil? && begin_node == parent.children.last)
|
|
317
316
|
end
|
|
318
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
|
319
317
|
|
|
320
318
|
def disallowed_one_line_pattern_matching?(begin_node, node)
|
|
321
319
|
if (parent = begin_node.parent)
|
|
@@ -66,7 +66,7 @@ module RuboCop
|
|
|
66
66
|
DETERMINISTIC_REGEX.match?(regexp_node.source)
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
# rubocop:disable Metrics/MethodLength
|
|
69
|
+
# rubocop:disable-next Metrics/MethodLength
|
|
70
70
|
def preferred_argument(regexp_node)
|
|
71
71
|
new_argument = replacement(regexp_node)
|
|
72
72
|
|
|
@@ -92,7 +92,6 @@ module RuboCop
|
|
|
92
92
|
|
|
93
93
|
"#{quote}#{new_argument}#{quote}"
|
|
94
94
|
end
|
|
95
|
-
# rubocop:enable Metrics/MethodLength
|
|
96
95
|
|
|
97
96
|
def replacement(regexp_node)
|
|
98
97
|
regexp_content = regexp_node.content
|
|
@@ -108,7 +108,7 @@ module RuboCop
|
|
|
108
108
|
corrector.insert_after(node.children.last, '}')
|
|
109
109
|
end
|
|
110
110
|
|
|
111
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
|
111
|
+
# rubocop:disable-next Metrics/CyclomaticComplexity
|
|
112
112
|
def check_branch(node)
|
|
113
113
|
return unless node
|
|
114
114
|
|
|
@@ -124,7 +124,6 @@ module RuboCop
|
|
|
124
124
|
check_begin_node(node)
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
|
128
127
|
|
|
129
128
|
def check_return_node(node)
|
|
130
129
|
return if cop_config['AllowMultipleReturnValues'] && node.children.size > 1
|
|
@@ -55,7 +55,7 @@ module RuboCop
|
|
|
55
55
|
...))
|
|
56
56
|
PATTERN
|
|
57
57
|
|
|
58
|
-
# rubocop:disable Metrics/AbcSize
|
|
58
|
+
# rubocop:disable-next Metrics/AbcSize
|
|
59
59
|
def on_lvasgn(node)
|
|
60
60
|
return unless (rhs = node.rhs)
|
|
61
61
|
return unless rhs.type?(:any_block, :call) && method_returning_self?(rhs.method_name)
|
|
@@ -69,7 +69,6 @@ module RuboCop
|
|
|
69
69
|
corrector.replace(node, rhs.source)
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
|
-
# rubocop:enable Metrics/AbcSize
|
|
73
72
|
alias on_ivasgn on_lvasgn
|
|
74
73
|
alias on_cvasgn on_lvasgn
|
|
75
74
|
alias on_gvasgn on_lvasgn
|
|
@@ -75,7 +75,7 @@ module RuboCop
|
|
|
75
75
|
node.loc.to_hash.key?(:begin) && !node.loc.begin.nil?
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
|
78
|
+
# rubocop:disable-next Metrics/CyclomaticComplexity
|
|
79
79
|
def allowed_escape?(node, range)
|
|
80
80
|
escaped = range.source[(1..-1)]
|
|
81
81
|
|
|
@@ -95,7 +95,6 @@ module RuboCop
|
|
|
95
95
|
|
|
96
96
|
false
|
|
97
97
|
end
|
|
98
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
|
99
98
|
|
|
100
99
|
def interpolation_not_enabled?(node)
|
|
101
100
|
single_quoted?(node) ||
|
|
@@ -67,7 +67,7 @@ module RuboCop
|
|
|
67
67
|
node.parent && parentheses?(node.parent)
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
# rubocop:disable Metrics/AbcSize
|
|
70
|
+
# rubocop:disable-next Metrics/AbcSize
|
|
71
71
|
def correct_rescue_block(corrector, node, parenthesized)
|
|
72
72
|
operation = node.body
|
|
73
73
|
|
|
@@ -83,7 +83,6 @@ module RuboCop
|
|
|
83
83
|
#{node_offset}end
|
|
84
84
|
RESCUE_CLAUSE
|
|
85
85
|
end
|
|
86
|
-
# rubocop:enable Metrics/AbcSize
|
|
87
86
|
|
|
88
87
|
def indentation_and_offset(node, parenthesized)
|
|
89
88
|
node_indentation = indentation(node)
|
|
@@ -152,7 +152,7 @@ module RuboCop
|
|
|
152
152
|
# @!method strip_begin(node)
|
|
153
153
|
def_node_matcher :strip_begin, '{ (begin $!begin) $!(begin) }'
|
|
154
154
|
|
|
155
|
-
# rubocop:disable Metrics/AbcSize
|
|
155
|
+
# rubocop:disable-next Metrics/AbcSize
|
|
156
156
|
def on_if(node)
|
|
157
157
|
return if allowed_if_condition?(node)
|
|
158
158
|
|
|
@@ -170,7 +170,6 @@ module RuboCop
|
|
|
170
170
|
corrector.insert_before(method_call.loc.dot, '&') unless method_call.safe_navigation?
|
|
171
171
|
end
|
|
172
172
|
end
|
|
173
|
-
# rubocop:enable Metrics/AbcSize
|
|
174
173
|
|
|
175
174
|
def on_and(node) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
|
176
175
|
collect_and_clauses(node).each do |(lhs, lhs_operator_range), (rhs, _rhs_operator_range)|
|
|
@@ -7,6 +7,10 @@ module RuboCop
|
|
|
7
7
|
# `shuffle.last`, and `shuffle[]` and change them to use
|
|
8
8
|
# `sample` instead.
|
|
9
9
|
#
|
|
10
|
+
# NOTE: An offense involving a `random:` argument is registered but not autocorrected:
|
|
11
|
+
# `shuffle` and `sample` consume the given generator differently, so for a seeded generator
|
|
12
|
+
# the correction would select different elements.
|
|
13
|
+
#
|
|
10
14
|
# @example
|
|
11
15
|
# # bad
|
|
12
16
|
# [1, 2, 3].shuffle.first
|
|
@@ -45,10 +49,12 @@ module RuboCop
|
|
|
45
49
|
range = source_range(shuffle_node, node)
|
|
46
50
|
message = message(shuffle_arg, method, method_args, range)
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
corrector
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
if shuffle_arg.empty?
|
|
53
|
+
add_offense(range, message: message) do |corrector|
|
|
54
|
+
corrector.replace(range, correction(shuffle_arg, method, method_args))
|
|
55
|
+
end
|
|
56
|
+
else
|
|
57
|
+
add_offense(range, message: message)
|
|
52
58
|
end
|
|
53
59
|
end
|
|
54
60
|
end
|
|
@@ -92,7 +98,7 @@ module RuboCop
|
|
|
92
98
|
second.int_type? ? second.to_a.first : :unknown
|
|
93
99
|
end
|
|
94
100
|
|
|
95
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
101
|
+
# rubocop:disable-next Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
96
102
|
def range_size(range_node)
|
|
97
103
|
vals = range_node.to_a
|
|
98
104
|
return :unknown unless vals.all? { |val| val.nil? || val.int_type? }
|
|
@@ -107,7 +113,6 @@ module RuboCop
|
|
|
107
113
|
(low..high).size
|
|
108
114
|
end
|
|
109
115
|
end
|
|
110
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
111
116
|
|
|
112
117
|
def source_range(shuffle_node, node)
|
|
113
118
|
shuffle_node.loc.selector.join(node.source_range.end)
|
|
@@ -97,7 +97,7 @@ module RuboCop
|
|
|
97
97
|
}
|
|
98
98
|
PATTERN
|
|
99
99
|
|
|
100
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
100
|
+
# rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
101
101
|
def on_send(node)
|
|
102
102
|
return if target_ruby_version < 2.6 && node.method?(:filter)
|
|
103
103
|
return unless (block_node = node.block_node)
|
|
@@ -113,7 +113,6 @@ module RuboCop
|
|
|
113
113
|
|
|
114
114
|
register_offense(node, block_node, regexp, replacement)
|
|
115
115
|
end
|
|
116
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
117
116
|
alias on_csend on_send
|
|
118
117
|
|
|
119
118
|
private
|
|
@@ -83,7 +83,7 @@ module RuboCop
|
|
|
83
83
|
processed_source.tokens.group_by(&:line)
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
86
|
+
# rubocop:disable-next Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
87
87
|
def semicolon_position(tokens)
|
|
88
88
|
if tokens.last.semicolon?
|
|
89
89
|
-1
|
|
@@ -100,7 +100,6 @@ module RuboCop
|
|
|
100
100
|
-4
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
104
103
|
|
|
105
104
|
def exist_semicolon_before_right_curly_brace?(tokens)
|
|
106
105
|
tokens[-2]&.right_curly_brace? && tokens[-3]&.semicolon?
|
|
@@ -122,7 +121,7 @@ module RuboCop
|
|
|
122
121
|
tokens[1]&.type == :tSTRING_DBEG && tokens[2]&.semicolon?
|
|
123
122
|
end
|
|
124
123
|
|
|
125
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
124
|
+
# rubocop:disable-next Metrics/AbcSize, Metrics/MethodLength
|
|
126
125
|
def register_semicolon(line, column, after_expression, token_before_semicolon = nil)
|
|
127
126
|
range = source_range(processed_source.buffer, line, column)
|
|
128
127
|
|
|
@@ -146,7 +145,6 @@ module RuboCop
|
|
|
146
145
|
end
|
|
147
146
|
end
|
|
148
147
|
end
|
|
149
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
150
148
|
|
|
151
149
|
def replace_semicolon_with_line_break(corrector, range)
|
|
152
150
|
# Replacing the semicolon with a newline would move the rest of the
|
|
@@ -36,7 +36,7 @@ module RuboCop
|
|
|
36
36
|
|
|
37
37
|
MSG = 'Prefer multiline `do`...`end` block.'
|
|
38
38
|
|
|
39
|
-
# rubocop:disable Metrics/AbcSize
|
|
39
|
+
# rubocop:disable-next Metrics/AbcSize
|
|
40
40
|
def on_block(node)
|
|
41
41
|
return if node.multiline? || node.braces?
|
|
42
42
|
return if single_line_blocks_preferred? && suitable_as_single_line?(node)
|
|
@@ -55,7 +55,6 @@ module RuboCop
|
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
|
-
# rubocop:enable Metrics/AbcSize
|
|
59
58
|
alias on_numblock on_block
|
|
60
59
|
alias on_itblock on_block
|
|
61
60
|
|
|
@@ -148,7 +148,7 @@ module RuboCop
|
|
|
148
148
|
corrector.remove(range_with_surrounding_space(range, newlines: false))
|
|
149
149
|
end
|
|
150
150
|
|
|
151
|
-
# rubocop:disable Metrics/AbcSize
|
|
151
|
+
# rubocop:disable-next Metrics/AbcSize
|
|
152
152
|
def correct_for_basic_condition_style(corrector, node, if_branch)
|
|
153
153
|
range = range_between(
|
|
154
154
|
node.condition.source_range.end_pos, if_branch.condition.source_range.begin_pos
|
|
@@ -164,7 +164,6 @@ module RuboCop
|
|
|
164
164
|
end
|
|
165
165
|
corrector.remove(end_range)
|
|
166
166
|
end
|
|
167
|
-
# rubocop:enable Metrics/AbcSize
|
|
168
167
|
|
|
169
168
|
def autocorrect_outer_condition_modify_form(corrector, node, if_branch)
|
|
170
169
|
correct_node(corrector, if_branch)
|
|
@@ -25,6 +25,8 @@ module RuboCop
|
|
|
25
25
|
|
|
26
26
|
MSG_REQUIRE = 'Wrap stabby lambda arguments with parentheses.'
|
|
27
27
|
MSG_NO_REQUIRE = 'Do not wrap stabby lambda arguments with parentheses.'
|
|
28
|
+
RESTRICT_ON_SEND = %i[lambda].freeze
|
|
29
|
+
|
|
28
30
|
def on_send(node)
|
|
29
31
|
return unless stabby_lambda_with_args?(node)
|
|
30
32
|
return unless redundant_parentheses?(node) || missing_parentheses?(node)
|