rubocop 1.71.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/lib/rubocop/cop/autocorrect_logic.rb +1 -1
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
- 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/redundant_source_range.rb +1 -0
- data/lib/rubocop/cop/internal_affairs.rb +2 -0
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +2 -2
- 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/end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.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_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_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/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/empty_expression.rb +0 -2
- 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 +1 -1
- data/lib/rubocop/cop/lint/missing_super.rb +2 -2
- 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 +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -5
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
- 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_method_definition.rb +1 -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/module_length.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/hash_shorthand_syntax.rb +4 -4
- data/lib/rubocop/cop/mixin/hash_subset.rb +19 -1
- 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/string_help.rb +1 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- 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/style/access_modifier_declarations.rb +2 -4
- data/lib/rubocop/cop/style/arguments_forwarding.rb +38 -19
- data/lib/rubocop/cop/style/block_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/class_and_module_children.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 +3 -3
- 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_with_object.rb +2 -3
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
- data/lib/rubocop/cop/style/explicit_block_argument.rb +15 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +2 -5
- data/lib/rubocop/cop/style/hash_except.rb +15 -0
- data/lib/rubocop/cop/style/hash_slice.rb +15 -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 +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +10 -13
- 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 +1 -1
- 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 +1 -1
- 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/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 +1 -1
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +6 -6
- 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_methods.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +1 -1
- 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/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/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/rspec/support.rb +1 -2
- data/lib/rubocop/version.rb +1 -1
- metadata +9 -6
- data/lib/rubocop/rspec/host_environment_simulation_helper.rb +0 -28
@@ -22,8 +22,6 @@ module RuboCop
|
|
22
22
|
# def b
|
23
23
|
# end
|
24
24
|
#
|
25
|
-
# @example
|
26
|
-
#
|
27
25
|
# # good
|
28
26
|
# def a
|
29
27
|
# end
|
@@ -42,8 +40,6 @@ module RuboCop
|
|
42
40
|
# def b
|
43
41
|
# end
|
44
42
|
#
|
45
|
-
# @example
|
46
|
-
#
|
47
43
|
# # good
|
48
44
|
# class A
|
49
45
|
# end
|
@@ -65,8 +61,6 @@ module RuboCop
|
|
65
61
|
# def b
|
66
62
|
# end
|
67
63
|
#
|
68
|
-
# @example
|
69
|
-
#
|
70
64
|
# # good
|
71
65
|
# module A
|
72
66
|
# end
|
@@ -162,7 +156,7 @@ module RuboCop
|
|
162
156
|
private
|
163
157
|
|
164
158
|
def def_location(correction_node)
|
165
|
-
if correction_node.
|
159
|
+
if correction_node.any_block_type?
|
166
160
|
correction_node.source_range.join(correction_node.children.first.source_range)
|
167
161
|
else
|
168
162
|
correction_node.loc.keyword.join(correction_node.loc.name)
|
@@ -181,12 +175,12 @@ module RuboCop
|
|
181
175
|
end
|
182
176
|
|
183
177
|
def macro_candidate?(node)
|
184
|
-
node.
|
178
|
+
node.any_block_type? && node.children.first.macro? &&
|
185
179
|
empty_line_between_macros.include?(node.children.first.method_name)
|
186
180
|
end
|
187
181
|
|
188
182
|
def method_candidate?(node)
|
189
|
-
cop_config['EmptyLineBetweenMethodDefs'] &&
|
183
|
+
cop_config['EmptyLineBetweenMethodDefs'] && node.type?(:def, :defs)
|
190
184
|
end
|
191
185
|
|
192
186
|
def class_candidate?(node)
|
@@ -246,7 +240,7 @@ module RuboCop
|
|
246
240
|
end
|
247
241
|
|
248
242
|
def def_start(node)
|
249
|
-
if node.
|
243
|
+
if node.any_block_type? && node.children.first.send_type?
|
250
244
|
node.source_range.line
|
251
245
|
else
|
252
246
|
node.loc.keyword.line
|
@@ -258,7 +252,7 @@ module RuboCop
|
|
258
252
|
end
|
259
253
|
|
260
254
|
def end_loc(node)
|
261
|
-
if
|
255
|
+
if node.type?(:def, :defs) && node.endless?
|
262
256
|
node.source_range.end
|
263
257
|
else
|
264
258
|
node.loc.end
|
@@ -283,6 +277,8 @@ module RuboCop
|
|
283
277
|
case node.type
|
284
278
|
when :def, :defs
|
285
279
|
:method
|
280
|
+
when :numblock
|
281
|
+
:block
|
286
282
|
else
|
287
283
|
node.type
|
288
284
|
end
|
@@ -182,7 +182,7 @@ module RuboCop
|
|
182
182
|
end
|
183
183
|
|
184
184
|
def alignment_node_for_variable_style(node)
|
185
|
-
if
|
185
|
+
if node.type?(:case, :case_match) && node.argument? &&
|
186
186
|
same_line?(node, node.parent)
|
187
187
|
return node.parent
|
188
188
|
end
|
@@ -225,7 +225,7 @@ module RuboCop
|
|
225
225
|
|
226
226
|
def base_range(send_node, arg_node)
|
227
227
|
parent = send_node.parent
|
228
|
-
start_node = if parent
|
228
|
+
start_node = if parent&.type?(:splat, :kwsplat)
|
229
229
|
send_node.parent
|
230
230
|
else
|
231
231
|
send_node
|
@@ -5,10 +5,10 @@ module RuboCop
|
|
5
5
|
module Layout
|
6
6
|
# Checks the indentation of the first parameter in a method
|
7
7
|
# definition. Parameters after the first one are checked by
|
8
|
-
# Layout/ParameterAlignment
|
8
|
+
# `Layout/ParameterAlignment`, not by this cop.
|
9
9
|
#
|
10
10
|
# For indenting the first argument of method _calls_, check out
|
11
|
-
# Layout/FirstArgumentIndentation
|
11
|
+
# `Layout/FirstArgumentIndentation`, which supports options related to
|
12
12
|
# nesting that are irrelevant for method _definitions_.
|
13
13
|
#
|
14
14
|
# @example
|
@@ -102,7 +102,7 @@ module RuboCop
|
|
102
102
|
|
103
103
|
def strings_concatenated_with_backslash?(dstr_node)
|
104
104
|
dstr_node.multiline? &&
|
105
|
-
dstr_node.children.all? { |c| c.
|
105
|
+
dstr_node.children.all? { |c| c.type?(:str, :dstr) } &&
|
106
106
|
dstr_node.children.none?(&:multiline?)
|
107
107
|
end
|
108
108
|
|
@@ -100,7 +100,7 @@ module RuboCop
|
|
100
100
|
|
101
101
|
def extra_indentation(given_style, parent)
|
102
102
|
if given_style == :indented_relative_to_receiver
|
103
|
-
if parent
|
103
|
+
if parent&.type?(:splat, :kwsplat)
|
104
104
|
configured_indentation_width - parent.loc.operator.length
|
105
105
|
else
|
106
106
|
configured_indentation_width
|
@@ -224,7 +224,7 @@ module RuboCop
|
|
224
224
|
end
|
225
225
|
|
226
226
|
def find_multiline_block_chain_node(node)
|
227
|
-
return unless (block_node = node.each_descendant(:
|
227
|
+
return unless (block_node = node.each_descendant(:any_block).first)
|
228
228
|
return unless block_node.multiline? && block_node.parent.call_type?
|
229
229
|
|
230
230
|
if node.receiver.call_type?
|
@@ -103,13 +103,13 @@ module RuboCop
|
|
103
103
|
|
104
104
|
def configured_to_not_be_inspected?(node)
|
105
105
|
return true if other_cop_takes_precedence?(node)
|
106
|
+
return false if cop_config['InspectBlocks']
|
106
107
|
|
107
|
-
|
108
|
-
any_descendant?(node, :block, &:multiline?))
|
108
|
+
node.any_block_type? || any_descendant?(node, :any_block, &:multiline?)
|
109
109
|
end
|
110
110
|
|
111
111
|
def other_cop_takes_precedence?(node)
|
112
|
-
single_line_block_chain_enabled? && any_descendant?(node, :
|
112
|
+
single_line_block_chain_enabled? && any_descendant?(node, :any_block) do |block_node|
|
113
113
|
block_node.parent.send_type? && block_node.parent.loc.dot && !block_node.multiline?
|
114
114
|
end
|
115
115
|
end
|
@@ -119,8 +119,9 @@ module RuboCop
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def convertible_block?(node)
|
122
|
-
parent = node.parent
|
123
|
-
|
122
|
+
return false unless (parent = node.parent)
|
123
|
+
|
124
|
+
parent.any_block_type? && node == parent.send_node &&
|
124
125
|
(node.parenthesized? || !node.arguments?)
|
125
126
|
end
|
126
127
|
end
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
MSG = '`%<kw_loc>s` at %<kw_loc_line>d, %<kw_loc_column>d is not ' \
|
30
30
|
'aligned with `%<beginning>s` at ' \
|
31
31
|
'%<begin_loc_line>d, %<begin_loc_column>d.'
|
32
|
-
ANCESTOR_TYPES = %i[kwbegin def defs class module
|
32
|
+
ANCESTOR_TYPES = %i[kwbegin def defs class module any_block].freeze
|
33
33
|
ANCESTOR_TYPES_WITH_ACCESS_MODIFIERS = %i[def defs].freeze
|
34
34
|
ALTERNATIVE_ACCESS_MODIFIERS = %i[public_class_method private_class_method].freeze
|
35
35
|
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
|
40
40
|
def offending_range(node)
|
41
41
|
receiver = node.receiver
|
42
|
-
return unless receiver&.
|
42
|
+
return unless receiver&.any_block_type?
|
43
43
|
|
44
44
|
receiver_location = receiver.loc
|
45
45
|
closing_block_delimiter_line_num = receiver_location.end.line
|
@@ -3,9 +3,9 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Layout
|
6
|
-
# Checks for colon (
|
6
|
+
# Checks for colon (`:`) not followed by some kind of space.
|
7
7
|
# N.B. this cop does not handle spaces after a ternary operator, which are
|
8
|
-
# instead handled by Layout/SpaceAroundOperators
|
8
|
+
# instead handled by `Layout/SpaceAroundOperators`.
|
9
9
|
#
|
10
10
|
# @example
|
11
11
|
# # bad
|
@@ -77,7 +77,7 @@ module RuboCop
|
|
77
77
|
private
|
78
78
|
|
79
79
|
def ambiguous_block_association?(send_node)
|
80
|
-
send_node.last_argument.
|
80
|
+
send_node.last_argument.any_block_type? && !send_node.last_argument.send_node.arguments?
|
81
81
|
end
|
82
82
|
|
83
83
|
def allowed_method_pattern?(node)
|
@@ -53,8 +53,6 @@ module RuboCop
|
|
53
53
|
ASGN_TYPES = [:begin, *AST::Node::EQUALS_ASSIGNMENTS, :send, :csend].freeze
|
54
54
|
|
55
55
|
def on_if(node)
|
56
|
-
return if node.condition.block_type?
|
57
|
-
|
58
56
|
traverse_node(node.condition) do |asgn_node|
|
59
57
|
next :skip_children if skip_children?(asgn_node)
|
60
58
|
next if allowed_construct?(asgn_node)
|
@@ -95,7 +93,7 @@ module RuboCop
|
|
95
93
|
|
96
94
|
def traverse_node(node, &block)
|
97
95
|
# if the node is a block, any assignments are irrelevant
|
98
|
-
return if node.
|
96
|
+
return if node.any_block_type?
|
99
97
|
|
100
98
|
result = yield node if ASGN_TYPES.include?(node.type)
|
101
99
|
|
@@ -14,7 +14,7 @@ module RuboCop
|
|
14
14
|
# Although these can be rewritten in a different way, it should not be necessary to
|
15
15
|
# do so. Operations such as `-` or `/` where the result will always be the same
|
16
16
|
# (`x - x` will always be 0; `x / x` will always be 1) are offenses, but these
|
17
|
-
# are covered by Lint/NumericOperationWithConstantResult instead.
|
17
|
+
# are covered by `Lint/NumericOperationWithConstantResult` instead.
|
18
18
|
#
|
19
19
|
# @safety
|
20
20
|
# This cop is unsafe as it does not consider side effects when calling methods
|
@@ -68,12 +68,12 @@ module RuboCop
|
|
68
68
|
|
69
69
|
# @!method constant_assigned_in_block?(node)
|
70
70
|
def_node_matcher :constant_assigned_in_block?, <<~PATTERN
|
71
|
-
({^
|
71
|
+
({^any_block [^begin ^^any_block]} nil? ...)
|
72
72
|
PATTERN
|
73
73
|
|
74
74
|
# @!method module_defined_in_block?(node)
|
75
75
|
def_node_matcher :module_defined_in_block?, <<~PATTERN
|
76
|
-
({^
|
76
|
+
({^any_block [^begin ^^any_block]} ...)
|
77
77
|
PATTERN
|
78
78
|
|
79
79
|
def on_casgn(node)
|
@@ -92,7 +92,7 @@ module RuboCop
|
|
92
92
|
private
|
93
93
|
|
94
94
|
def method_name(node)
|
95
|
-
node.ancestors.find(&:
|
95
|
+
node.ancestors.find(&:any_block_type?).method_name
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
@@ -96,22 +96,18 @@ module RuboCop
|
|
96
96
|
private
|
97
97
|
|
98
98
|
def fixed_constant_path?(node)
|
99
|
-
node.each_path.all? { |path| path.
|
99
|
+
node.each_path.all? { |path| path.type?(:cbase, :const, :self) }
|
100
100
|
end
|
101
101
|
|
102
102
|
def simple_assignment?(node)
|
103
103
|
node.ancestors.all? do |ancestor|
|
104
|
-
return true if
|
104
|
+
return true if ancestor.type?(:module, :class)
|
105
105
|
|
106
106
|
ancestor.begin_type? || ancestor.literal? || ancestor.casgn_type? ||
|
107
107
|
freeze_method?(ancestor)
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
def namespace_definition?(node)
|
112
|
-
node.module_type? || node.class_type?
|
113
|
-
end
|
114
|
-
|
115
111
|
def freeze_method?(node)
|
116
112
|
node.send_type? && node.method?(:freeze)
|
117
113
|
end
|
@@ -116,7 +116,7 @@ module RuboCop
|
|
116
116
|
|
117
117
|
def assumed_usage_context?(node)
|
118
118
|
# Basically, debugger methods are not used as a method argument without arguments.
|
119
|
-
return false unless node.arguments.empty? && node.each_ancestor(:
|
119
|
+
return false unless node.arguments.empty? && node.each_ancestor(:call).any?
|
120
120
|
return true if assumed_argument?(node)
|
121
121
|
|
122
122
|
node.each_ancestor.none? do |ancestor|
|
@@ -106,7 +106,7 @@ module RuboCop
|
|
106
106
|
private
|
107
107
|
|
108
108
|
def pattern_identity(pattern)
|
109
|
-
pattern_source = if pattern.
|
109
|
+
pattern_source = if pattern.type?(:hash_pattern, :match_alt)
|
110
110
|
pattern.children.map(&:source).sort.to_s
|
111
111
|
else
|
112
112
|
pattern.source
|
@@ -73,7 +73,7 @@ module RuboCop
|
|
73
73
|
|
74
74
|
first_arg = node.first_argument
|
75
75
|
return false if num_of_expected_fields.zero? &&
|
76
|
-
|
76
|
+
first_arg.type?(:dstr, :array)
|
77
77
|
|
78
78
|
matched_arguments_count?(num_of_expected_fields, num_of_format_args)
|
79
79
|
end
|
@@ -199,7 +199,7 @@ module RuboCop
|
|
199
199
|
|
200
200
|
def in_array_percent_literal?(node)
|
201
201
|
parent = node.parent
|
202
|
-
return false unless parent.
|
202
|
+
return false unless parent.type?(:dstr, :dsym)
|
203
203
|
|
204
204
|
grandparent = parent.parent
|
205
205
|
grandparent&.array_type? && grandparent.percent_literal?
|
@@ -97,7 +97,7 @@ module RuboCop
|
|
97
97
|
|
98
98
|
# @!method class_new_block(node)
|
99
99
|
def_node_matcher :class_new_block, <<~RUBY
|
100
|
-
(
|
100
|
+
(any_block
|
101
101
|
(send
|
102
102
|
(const {nil? cbase} :Class) :new $_) ...)
|
103
103
|
RUBY
|
@@ -135,7 +135,7 @@ module RuboCop
|
|
135
135
|
end
|
136
136
|
|
137
137
|
def inside_class_with_stateful_parent?(node)
|
138
|
-
if (block_node = node.each_ancestor(:
|
138
|
+
if (block_node = node.each_ancestor(:any_block).first)
|
139
139
|
return false unless (super_class = class_new_block(block_node))
|
140
140
|
|
141
141
|
!allowed_class?(super_class)
|
@@ -102,7 +102,7 @@ module RuboCop
|
|
102
102
|
return unless def_ancestor
|
103
103
|
|
104
104
|
within_scoping_def =
|
105
|
-
node.each_ancestor(:
|
105
|
+
node.each_ancestor(:any_block, :sclass).any? do |ancestor|
|
106
106
|
scoping_method_call?(ancestor)
|
107
107
|
end
|
108
108
|
|
@@ -129,12 +129,12 @@ module RuboCop
|
|
129
129
|
|
130
130
|
# @!method eval_call?(node)
|
131
131
|
def_node_matcher :eval_call?, <<~PATTERN
|
132
|
-
(
|
132
|
+
(any_block (send _ {:instance_eval :class_eval :module_eval} ...) ...)
|
133
133
|
PATTERN
|
134
134
|
|
135
135
|
# @!method exec_call?(node)
|
136
136
|
def_node_matcher :exec_call?, <<~PATTERN
|
137
|
-
(
|
137
|
+
(any_block (send _ {:instance_exec :class_exec :module_exec} ...) ...)
|
138
138
|
PATTERN
|
139
139
|
end
|
140
140
|
end
|
@@ -9,7 +9,7 @@ module RuboCop
|
|
9
9
|
# As such, they can be replaced with that result.
|
10
10
|
# These are probably leftover from debugging, or are mistakes.
|
11
11
|
# Other numeric operations that are similarly leftover from debugging or mistakes
|
12
|
-
# are handled by Lint/UselessNumericOperation
|
12
|
+
# are handled by `Lint/UselessNumericOperation`.
|
13
13
|
#
|
14
14
|
# NOTE: This cop doesn't detect offenses for the `-` and `%` operator because it
|
15
15
|
# can't determine the type of `x`. If `x` is an `Array` or `String`, it doesn't perform
|
@@ -38,16 +38,12 @@ module RuboCop
|
|
38
38
|
|
39
39
|
def valid_context?(node)
|
40
40
|
return true unless node.arguments.one? && node.first_argument.parenthesized_call?
|
41
|
-
return true if
|
41
|
+
return true if node.first_argument.any_block_type?
|
42
42
|
|
43
43
|
node.operator_method? || node.setter_method? || chained_calls?(node) ||
|
44
44
|
valid_first_argument?(node.first_argument)
|
45
45
|
end
|
46
46
|
|
47
|
-
def first_argument_block_type?(first_arg)
|
48
|
-
first_arg.block_type? || first_arg.numblock_type?
|
49
|
-
end
|
50
|
-
|
51
47
|
def valid_first_argument?(first_arg)
|
52
48
|
first_arg.operator_keyword? || first_arg.hash_type? || ternary_expression?(first_arg) ||
|
53
49
|
compound_range?(first_arg)
|
@@ -42,7 +42,7 @@ module RuboCop
|
|
42
42
|
def on_send(node)
|
43
43
|
return if node.receiver
|
44
44
|
|
45
|
-
node.each_child_node(:
|
45
|
+
node.each_child_node(:call) do |child|
|
46
46
|
next if !child.method?(:to_s) || child.arguments.any?
|
47
47
|
|
48
48
|
register_offense(child, "`#{node.method_name}`")
|
@@ -116,7 +116,7 @@ module RuboCop
|
|
116
116
|
private
|
117
117
|
|
118
118
|
def comment_between_rescue_and_end?(node)
|
119
|
-
ancestor = node.each_ancestor(:kwbegin, :def, :defs, :
|
119
|
+
ancestor = node.each_ancestor(:kwbegin, :def, :defs, :any_block).first
|
120
120
|
return false unless ancestor
|
121
121
|
|
122
122
|
end_line = ancestor.loc.end&.line || ancestor.loc.last_line
|
@@ -78,7 +78,7 @@ module RuboCop
|
|
78
78
|
def on_send(node)
|
79
79
|
return unless node.receiver
|
80
80
|
|
81
|
-
if node.receiver.
|
81
|
+
if node.receiver.type?(:str, :sym)
|
82
82
|
register_offense(node, correction: node.receiver.value.to_sym.inspect)
|
83
83
|
elsif node.receiver.dstr_type?
|
84
84
|
register_offense(node, correction: ":\"#{node.receiver.value.to_sym}\"")
|
@@ -130,7 +130,7 @@ module RuboCop
|
|
130
130
|
|
131
131
|
block_body_node.each_descendant(:next, :break) do |n|
|
132
132
|
# Ignore `next`/`break` inside an inner block
|
133
|
-
next if n.each_ancestor(:
|
133
|
+
next if n.each_ancestor(:any_block).first != block_body_node.parent
|
134
134
|
next unless n.first_argument
|
135
135
|
|
136
136
|
nodes << n.first_argument
|
@@ -108,7 +108,7 @@ module RuboCop
|
|
108
108
|
private
|
109
109
|
|
110
110
|
def loop_method?(node)
|
111
|
-
return false unless node.
|
111
|
+
return false unless node.any_block_type?
|
112
112
|
|
113
113
|
send_node = node.send_node
|
114
114
|
loopable = send_node.enumerable_method? || send_node.enumerator_method? ||
|
@@ -159,12 +159,12 @@ module RuboCop
|
|
159
159
|
|
160
160
|
# @!method dynamic_method_definition?(node)
|
161
161
|
def_node_matcher :dynamic_method_definition?, <<~PATTERN
|
162
|
-
{(send nil? :define_method ...) (
|
162
|
+
{(send nil? :define_method ...) (any_block (send nil? :define_method ...) ...)}
|
163
163
|
PATTERN
|
164
164
|
|
165
165
|
# @!method class_or_instance_eval?(node)
|
166
166
|
def_node_matcher :class_or_instance_eval?, <<~PATTERN
|
167
|
-
(
|
167
|
+
(any_block (send _ {:class_eval :instance_eval}) ...)
|
168
168
|
PATTERN
|
169
169
|
|
170
170
|
def check_node(node)
|
@@ -268,7 +268,7 @@ module RuboCop
|
|
268
268
|
end
|
269
269
|
|
270
270
|
def start_of_new_scope?(child)
|
271
|
-
child.
|
271
|
+
child.type?(:module, :class, :sclass) || eval_call?(child)
|
272
272
|
end
|
273
273
|
|
274
274
|
def eval_call?(child)
|
@@ -282,7 +282,7 @@ module RuboCop
|
|
282
282
|
matcher_name = :"#{m}_block?"
|
283
283
|
unless respond_to?(matcher_name)
|
284
284
|
self.class.def_node_matcher matcher_name, <<~PATTERN
|
285
|
-
(
|
285
|
+
(any_block (send {nil? const} {:#{m}} ...) ...)
|
286
286
|
PATTERN
|
287
287
|
end
|
288
288
|
|
@@ -59,7 +59,7 @@ module RuboCop
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def use_rest_or_optional_args?(node)
|
62
|
-
node.arguments.any? { |arg| arg.
|
62
|
+
node.arguments.any? { |arg| arg.type?(:restarg, :optarg, :kwoptarg) }
|
63
63
|
end
|
64
64
|
|
65
65
|
def delegating?(node, def_node)
|
@@ -72,7 +72,7 @@ module RuboCop
|
|
72
72
|
def_node_matcher :method_definition, <<~PATTERN
|
73
73
|
{
|
74
74
|
(def %1 ...)
|
75
|
-
(
|
75
|
+
(any_block (send _ :define_method (sym %1)) ...)
|
76
76
|
}
|
77
77
|
PATTERN
|
78
78
|
|
@@ -108,7 +108,7 @@ module RuboCop
|
|
108
108
|
|
109
109
|
def find_method_definition(node, method_name)
|
110
110
|
node.each_ancestor.lazy.map do |ancestor|
|
111
|
-
ancestor.each_child_node(:def, :
|
111
|
+
ancestor.each_child_node(:def, :any_block).find do |child|
|
112
112
|
method_definition(child, method_name)
|
113
113
|
end
|
114
114
|
end.find(&:itself)
|