rubocop 1.57.2 → 1.59.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/README.md +2 -2
- data/config/default.yml +43 -2
- data/lib/rubocop/config_obsoletion.rb +11 -8
- data/lib/rubocop/cop/bundler/gem_comment.rb +2 -2
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +19 -20
- data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +53 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +2 -2
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +4 -10
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +6 -6
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/redundant_line_break.rb +2 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +4 -4
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +5 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +50 -20
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +4 -4
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +2 -2
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +2 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +3 -3
- data/lib/rubocop/cop/lint/float_comparison.rb +10 -0
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +2 -1
- data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +56 -0
- data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +78 -0
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +6 -21
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +3 -5
- data/lib/rubocop/cop/lint/number_conversion.rb +9 -4
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +43 -0
- data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +3 -4
- data/lib/rubocop/cop/lint/self_assignment.rb +38 -0
- data/lib/rubocop/cop/lint/symbol_conversion.rb +7 -2
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -1
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +2 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -2
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +14 -1
- data/lib/rubocop/cop/metrics/abc_size.rb +3 -3
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +2 -2
- data/lib/rubocop/cop/naming/constant_name.rb +1 -2
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +2 -2
- data/lib/rubocop/cop/style/accessor_grouping.rb +1 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +68 -6
- data/lib/rubocop/cop/style/array_first_last.rb +64 -0
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +21 -14
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +2 -2
- data/lib/rubocop/cop/style/case_like_if.rb +4 -4
- data/lib/rubocop/cop/style/class_check.rb +1 -0
- data/lib/rubocop/cop/style/collection_compact.rb +7 -6
- data/lib/rubocop/cop/style/combinable_loops.rb +13 -7
- data/lib/rubocop/cop/style/concat_array_literals.rb +1 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
- data/lib/rubocop/cop/style/date_time.rb +5 -4
- data/lib/rubocop/cop/style/each_with_object.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
- data/lib/rubocop/cop/style/exact_regexp_match.rb +2 -1
- data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +83 -10
- data/lib/rubocop/cop/style/hash_except.rb +2 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +6 -5
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +3 -2
- data/lib/rubocop/cop/style/map_to_hash.rb +10 -4
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +1 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +20 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/missing_respond_to_missing.rb +2 -2
- data/lib/rubocop/cop/style/next.rb +1 -1
- data/lib/rubocop/cop/style/operator_method_call.rb +2 -2
- data/lib/rubocop/cop/style/redundant_argument.rb +3 -2
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +3 -3
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +3 -3
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +2 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +15 -8
- data/lib/rubocop/cop/style/redundant_return.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self.rb +17 -2
- data/lib/rubocop/cop/style/redundant_sort.rb +9 -8
- data/lib/rubocop/cop/style/redundant_sort_by.rb +2 -2
- data/lib/rubocop/cop/style/redundant_string_escape.rb +1 -1
- data/lib/rubocop/cop/style/sample.rb +2 -1
- data/lib/rubocop/cop/style/select_by_regexp.rb +7 -6
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +8 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +5 -2
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
- data/lib/rubocop/cop/style/string_chars.rb +1 -0
- data/lib/rubocop/cop/style/strip.rb +7 -4
- data/lib/rubocop/cop/style/super_with_args_parentheses.rb +35 -0
- data/lib/rubocop/cop/style/unpack_first.rb +11 -14
- data/lib/rubocop/formatter/html_formatter.rb +1 -2
- data/lib/rubocop/result_cache.rb +0 -1
- data/lib/rubocop/runner.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +4 -0
- metadata +14 -9
@@ -17,12 +17,11 @@ module RuboCop
|
|
17
17
|
include Parentheses
|
18
18
|
extend AutoCorrector
|
19
19
|
|
20
|
+
ALLOWED_NODE_TYPES = %i[and or send splat kwsplat].freeze
|
21
|
+
|
20
22
|
# @!method square_brackets?(node)
|
21
23
|
def_node_matcher :square_brackets?, '(send {(send _recv _msg) str array hash} :[] ...)'
|
22
24
|
|
23
|
-
# @!method range_end?(node)
|
24
|
-
def_node_matcher :range_end?, '^^{irange erange}'
|
25
|
-
|
26
25
|
# @!method method_node_and_args(node)
|
27
26
|
def_node_matcher :method_node_and_args, '$(call _recv _msg $...)'
|
28
27
|
|
@@ -62,7 +61,8 @@ module RuboCop
|
|
62
61
|
allowed_ancestor?(node) ||
|
63
62
|
allowed_method_call?(node) ||
|
64
63
|
allowed_multiple_expression?(node) ||
|
65
|
-
allowed_ternary?(node)
|
64
|
+
allowed_ternary?(node) ||
|
65
|
+
node.parent&.range_type?
|
66
66
|
end
|
67
67
|
|
68
68
|
def allowed_ancestor?(node)
|
@@ -136,23 +136,31 @@ module RuboCop
|
|
136
136
|
check_send(begin_node, node) if node.call_type?
|
137
137
|
end
|
138
138
|
|
139
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
139
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
140
140
|
def find_offense_message(begin_node, node)
|
141
141
|
return 'a keyword' if keyword_with_redundant_parentheses?(node)
|
142
142
|
return 'a literal' if disallowed_literal?(begin_node, node)
|
143
143
|
return 'a variable' if node.variable?
|
144
144
|
return 'a constant' if node.const_type?
|
145
|
+
if node.lambda_or_proc? && (node.braces? || node.send_node.lambda_literal?)
|
146
|
+
return 'an expression'
|
147
|
+
end
|
145
148
|
return 'an interpolated expression' if interpolation?(begin_node)
|
146
149
|
|
147
|
-
return if begin_node.chained?
|
150
|
+
return if begin_node.chained?
|
148
151
|
|
149
152
|
if node.and_type? || node.or_type?
|
153
|
+
return if ALLOWED_NODE_TYPES.include?(begin_node.parent&.type)
|
154
|
+
return if begin_node.parent&.if_type? && begin_node.parent&.ternary?
|
155
|
+
|
150
156
|
'a logical expression'
|
151
157
|
elsif node.respond_to?(:comparison_method?) && node.comparison_method?
|
158
|
+
return unless begin_node.parent.nil?
|
159
|
+
|
152
160
|
'a comparison expression'
|
153
161
|
end
|
154
162
|
end
|
155
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
163
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
156
164
|
|
157
165
|
# @!method interpolation?(node)
|
158
166
|
def_node_matcher :interpolation?, '[^begin ^^dstr]'
|
@@ -221,7 +229,6 @@ module RuboCop
|
|
221
229
|
def method_call_with_redundant_parentheses?(node)
|
222
230
|
return false unless node.call_type?
|
223
231
|
return false if node.prefix_not?
|
224
|
-
return false if range_end?(node)
|
225
232
|
|
226
233
|
send_node, args = method_node_and_args(node)
|
227
234
|
|
@@ -58,7 +58,7 @@ module RuboCop
|
|
58
58
|
|
59
59
|
MSG = 'Redundant `return` detected.'
|
60
60
|
MULTI_RETURN_MSG = 'To return multiple values, use an array.'
|
61
|
-
RESTRICT_ON_SEND = %i[define_method define_singleton_method].freeze
|
61
|
+
RESTRICT_ON_SEND = %i[define_method define_singleton_method lambda].freeze
|
62
62
|
|
63
63
|
def on_send(node)
|
64
64
|
return unless (parent = node.parent) && parent.block_type?
|
@@ -17,7 +17,8 @@ module RuboCop
|
|
17
17
|
# protected scope, you cannot send private messages this way.
|
18
18
|
#
|
19
19
|
# Note we allow uses of `self` with operators because it would be awkward
|
20
|
-
# otherwise.
|
20
|
+
# otherwise. Also allows the use of `self.it` without arguments in blocks,
|
21
|
+
# as in `0.times { self.it }`, following `Lint/ItWithoutArgumentsInBlock` cop.
|
21
22
|
#
|
22
23
|
# @example
|
23
24
|
#
|
@@ -107,8 +108,8 @@ module RuboCop
|
|
107
108
|
def on_send(node)
|
108
109
|
return unless node.self_receiver? && regular_method_call?(node)
|
109
110
|
return if node.parent&.mlhs_type?
|
110
|
-
|
111
111
|
return if allowed_send_node?(node)
|
112
|
+
return if it_method_in_block?(node)
|
112
113
|
|
113
114
|
add_offense(node.receiver) do |corrector|
|
114
115
|
corrector.remove(node.receiver)
|
@@ -155,6 +156,20 @@ module RuboCop
|
|
155
156
|
KERNEL_METHODS.include?(node.method_name)
|
156
157
|
end
|
157
158
|
|
159
|
+
# Respects `Lint/ItWithoutArgumentsInBlock` cop and the following Ruby 3.3's warning:
|
160
|
+
#
|
161
|
+
# $ ruby -e '0.times { begin; it; end }'
|
162
|
+
# -e:1: warning: `it` calls without arguments will refer to the first block param in
|
163
|
+
# Ruby 3.4; use it() or self.it
|
164
|
+
#
|
165
|
+
def it_method_in_block?(node)
|
166
|
+
return false unless node.method?(:it)
|
167
|
+
return false unless (block_node = node.each_ancestor(:block).first)
|
168
|
+
return false unless block_node.arguments.empty_and_without_delimiters?
|
169
|
+
|
170
|
+
node.arguments.empty? && !node.block_literal?
|
171
|
+
end
|
172
|
+
|
158
173
|
def regular_method_call?(node)
|
159
174
|
!(node.operator_method? ||
|
160
175
|
KEYWORDS.include?(node.method_name) ||
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
# This cop is unsafe, because `sort...last` and `max` may not return the
|
17
17
|
# same element in all cases.
|
18
18
|
#
|
19
|
-
# In an enumerable where there are multiple elements where
|
19
|
+
# In an enumerable where there are multiple elements where ``a <=> b == 0``,
|
20
20
|
# or where the transformation done by the `sort_by` block has the
|
21
21
|
# same result, `sort.last` and `max` (or `sort_by.last` and `max_by`)
|
22
22
|
# will return different elements. `sort.last` will return the last
|
@@ -87,15 +87,15 @@ module RuboCop
|
|
87
87
|
# @!method redundant_sort?(node)
|
88
88
|
def_node_matcher :redundant_sort?, <<~MATCHER
|
89
89
|
{
|
90
|
-
(
|
91
|
-
(
|
90
|
+
(call $(call _ $:sort) ${:last :first})
|
91
|
+
(call $(call _ $:sort) ${:[] :at :slice} {(int 0) (int -1)})
|
92
92
|
|
93
|
-
(
|
93
|
+
(call $(call _ $:sort_by _) ${:last :first})
|
94
94
|
(send $(send _ $:sort_by _) ${:[] :at :slice} {(int 0) (int -1)})
|
95
95
|
|
96
|
-
(
|
97
|
-
(
|
98
|
-
({block numblock} $(
|
96
|
+
(call ({block numblock} $(call _ ${:sort_by :sort}) ...) ${:last :first})
|
97
|
+
(call
|
98
|
+
({block numblock} $(call _ ${:sort_by :sort}) ...)
|
99
99
|
${:[] :at :slice} {(int 0) (int -1)}
|
100
100
|
)
|
101
101
|
}
|
@@ -108,6 +108,7 @@ module RuboCop
|
|
108
108
|
|
109
109
|
register_offense(ancestor, sort_node, sorter, accessor)
|
110
110
|
end
|
111
|
+
alias on_csend on_send
|
111
112
|
|
112
113
|
private
|
113
114
|
|
@@ -180,7 +181,7 @@ module RuboCop
|
|
180
181
|
end
|
181
182
|
|
182
183
|
def arg_node(node)
|
183
|
-
node.
|
184
|
+
node.first_argument
|
184
185
|
end
|
185
186
|
|
186
187
|
def arg_value(node)
|
@@ -46,12 +46,12 @@ module RuboCop
|
|
46
46
|
|
47
47
|
# @!method redundant_sort_by_block(node)
|
48
48
|
def_node_matcher :redundant_sort_by_block, <<~PATTERN
|
49
|
-
(block $(
|
49
|
+
(block $(call _ :sort_by) (args (arg $_x)) (lvar _x))
|
50
50
|
PATTERN
|
51
51
|
|
52
52
|
# @!method redundant_sort_by_numblock(node)
|
53
53
|
def_node_matcher :redundant_sort_by_numblock, <<~PATTERN
|
54
|
-
(numblock $(
|
54
|
+
(numblock $(call _ :sort_by) 1 (lvar :_1))
|
55
55
|
PATTERN
|
56
56
|
|
57
57
|
def sort_by_range(send, node)
|
@@ -133,7 +133,7 @@ module RuboCop
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def percent_array_literal?(node)
|
136
|
-
|
136
|
+
percent_w_literal?(node) || percent_w_upper_literal?(node)
|
137
137
|
end
|
138
138
|
|
139
139
|
def heredoc_with_disabled_interpolation?(node)
|
@@ -35,7 +35,7 @@ module RuboCop
|
|
35
35
|
|
36
36
|
# @!method sample_candidate?(node)
|
37
37
|
def_node_matcher :sample_candidate?, <<~PATTERN
|
38
|
-
(
|
38
|
+
(call $(call _ :shuffle $...) ${:#{RESTRICT_ON_SEND.join(' :')}} $...)
|
39
39
|
PATTERN
|
40
40
|
|
41
41
|
def on_send(node)
|
@@ -52,6 +52,7 @@ module RuboCop
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
|
+
alias on_csend on_send
|
55
56
|
|
56
57
|
private
|
57
58
|
|
@@ -55,8 +55,8 @@ module RuboCop
|
|
55
55
|
# @!method regexp_match?(node)
|
56
56
|
def_node_matcher :regexp_match?, <<~PATTERN
|
57
57
|
{
|
58
|
-
(block
|
59
|
-
(numblock
|
58
|
+
(block call (args (arg $_)) ${(send _ %REGEXP_METHODS _) match-with-lvasgn})
|
59
|
+
(numblock call $1 ${(send _ %REGEXP_METHODS _) match-with-lvasgn})
|
60
60
|
}
|
61
61
|
PATTERN
|
62
62
|
|
@@ -64,9 +64,9 @@ module RuboCop
|
|
64
64
|
# @!method creates_hash?(node)
|
65
65
|
def_node_matcher :creates_hash?, <<~PATTERN
|
66
66
|
{
|
67
|
-
(
|
68
|
-
(block (
|
69
|
-
(
|
67
|
+
(call (const _ :Hash) {:new :[]} ...)
|
68
|
+
(block (call (const _ :Hash) :new ...) ...)
|
69
|
+
(call _ { :to_h :to_hash } ...)
|
70
70
|
}
|
71
71
|
PATTERN
|
72
72
|
|
@@ -100,6 +100,7 @@ module RuboCop
|
|
100
100
|
register_offense(node, block_node, regexp, replacement)
|
101
101
|
end
|
102
102
|
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
103
|
+
alias on_csend on_send
|
103
104
|
|
104
105
|
private
|
105
106
|
|
@@ -146,7 +147,7 @@ module RuboCop
|
|
146
147
|
return node.child_nodes.first if node.match_with_lvasgn_type?
|
147
148
|
|
148
149
|
if node.receiver.lvar_type? &&
|
149
|
-
(block.numblock_type? || node.receiver.source == block.
|
150
|
+
(block.numblock_type? || node.receiver.source == block.first_argument.source)
|
150
151
|
node.first_argument
|
151
152
|
elsif node.first_argument.lvar_type?
|
152
153
|
node.receiver
|
@@ -80,6 +80,7 @@ module RuboCop
|
|
80
80
|
processed_source.tokens.group_by(&:line)
|
81
81
|
end
|
82
82
|
|
83
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
83
84
|
def semicolon_position(tokens)
|
84
85
|
if tokens.last.semicolon?
|
85
86
|
-1
|
@@ -90,10 +91,13 @@ module RuboCop
|
|
90
91
|
elsif exist_semicolon_after_left_curly_brace?(tokens) ||
|
91
92
|
exist_semicolon_after_left_string_interpolation_brace?(tokens)
|
92
93
|
2
|
94
|
+
elsif exist_semicolon_after_left_lambda_curly_brace?(tokens)
|
95
|
+
3
|
93
96
|
elsif exist_semicolon_before_right_string_interpolation_brace?(tokens)
|
94
97
|
-4
|
95
98
|
end
|
96
99
|
end
|
100
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
97
101
|
|
98
102
|
def exist_semicolon_before_right_curly_brace?(tokens)
|
99
103
|
tokens[-2]&.right_curly_brace? && tokens[-3]&.semicolon?
|
@@ -103,6 +107,10 @@ module RuboCop
|
|
103
107
|
tokens[1]&.left_curly_brace? && tokens[2]&.semicolon?
|
104
108
|
end
|
105
109
|
|
110
|
+
def exist_semicolon_after_left_lambda_curly_brace?(tokens)
|
111
|
+
tokens[2]&.type == :tLAMBEG && tokens[3]&.semicolon?
|
112
|
+
end
|
113
|
+
|
106
114
|
def exist_semicolon_before_right_string_interpolation_brace?(tokens)
|
107
115
|
tokens[-3]&.type == :tSTRING_DEND && tokens[-4]&.semicolon?
|
108
116
|
end
|
@@ -3,8 +3,11 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
# Sometimes using dig method ends up with just a single
|
7
|
-
# argument. In such cases, dig should be replaced with []
|
6
|
+
# Sometimes using `dig` method ends up with just a single
|
7
|
+
# argument. In such cases, dig should be replaced with `[]`.
|
8
|
+
#
|
9
|
+
# Since replacing `hash&.dig(:key)` with `hash[:key]` could potentially lead to error,
|
10
|
+
# calls to the `dig` method using safe navigation will be ignored.
|
8
11
|
#
|
9
12
|
# @safety
|
10
13
|
# This cop is unsafe because it cannot be guaranteed that the receiver
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
|
40
40
|
def on_send(node)
|
41
41
|
return unless node.arguments.count == 1
|
42
|
-
return unless range_till_minus_one?(node.
|
42
|
+
return unless range_till_minus_one?(node.first_argument)
|
43
43
|
|
44
44
|
add_offense(node.first_argument) do |corrector|
|
45
45
|
corrector.remove(node.first_argument.end)
|
@@ -22,20 +22,23 @@ module RuboCop
|
|
22
22
|
|
23
23
|
# @!method lstrip_rstrip(node)
|
24
24
|
def_node_matcher :lstrip_rstrip, <<~PATTERN
|
25
|
-
{
|
26
|
-
|
25
|
+
{
|
26
|
+
(call $(call _ :rstrip) :lstrip)
|
27
|
+
(call $(call _ :lstrip) :rstrip)
|
28
|
+
}
|
27
29
|
PATTERN
|
28
30
|
|
29
31
|
def on_send(node)
|
30
|
-
lstrip_rstrip(node) do |first_send
|
32
|
+
lstrip_rstrip(node) do |first_send|
|
31
33
|
range = range_between(first_send.loc.selector.begin_pos, node.source_range.end_pos)
|
32
|
-
message = format(MSG, methods:
|
34
|
+
message = format(MSG, methods: range.source)
|
33
35
|
|
34
36
|
add_offense(range, message: message) do |corrector|
|
35
37
|
corrector.replace(range, 'strip')
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
41
|
+
alias on_csend on_send
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# Enforces the presence of parentheses in `super` containing arguments.
|
7
|
+
#
|
8
|
+
# `super` is a keyword and is provided as a distinct cop from those designed for method call.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
#
|
12
|
+
# # bad
|
13
|
+
# super name, age
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# super(name, age)
|
17
|
+
#
|
18
|
+
class SuperWithArgsParentheses < Base
|
19
|
+
extend AutoCorrector
|
20
|
+
|
21
|
+
MSG = 'Use parentheses for `super` with arguments.'
|
22
|
+
|
23
|
+
def on_super(node)
|
24
|
+
return if node.parenthesized?
|
25
|
+
|
26
|
+
add_offense(node) do |corrector|
|
27
|
+
range = node.loc.keyword.end.join(node.first_argument.source_range.begin)
|
28
|
+
corrector.replace(range, '(')
|
29
|
+
corrector.insert_after(node.last_argument, ')')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -23,38 +23,35 @@ module RuboCop
|
|
23
23
|
|
24
24
|
minimum_target_ruby_version 2.4
|
25
25
|
|
26
|
-
MSG = 'Use
|
27
|
-
'`%<receiver>s.unpack(%<format>s)%<method>s`.'
|
26
|
+
MSG = 'Use `unpack1(%<format>s)` instead of `%<current>s`.'
|
28
27
|
RESTRICT_ON_SEND = %i[first [] slice at].freeze
|
29
28
|
|
30
29
|
# @!method unpack_and_first_element?(node)
|
31
30
|
def_node_matcher :unpack_and_first_element?, <<~PATTERN
|
32
31
|
{
|
33
|
-
(
|
34
|
-
(
|
32
|
+
(call $(call (...) :unpack $(...)) :first)
|
33
|
+
(call $(call (...) :unpack $(...)) {:[] :slice :at} (int 0))
|
35
34
|
}
|
36
35
|
PATTERN
|
37
36
|
|
38
37
|
def on_send(node)
|
39
38
|
unpack_and_first_element?(node) do |unpack_call, unpack_arg|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
corrector.remove(first_element_range(node, unpack_call))
|
39
|
+
first_element_range = first_element_range(node, unpack_call)
|
40
|
+
offense_range = unpack_call.loc.selector.join(node.source_range.end)
|
41
|
+
message = format(MSG, format: unpack_arg.source, current: offense_range.source)
|
42
|
+
|
43
|
+
add_offense(offense_range, message: message) do |corrector|
|
44
|
+
corrector.remove(first_element_range)
|
47
45
|
corrector.replace(unpack_call.loc.selector, 'unpack1')
|
48
46
|
end
|
49
47
|
end
|
50
48
|
end
|
49
|
+
alias on_csend on_send
|
51
50
|
|
52
51
|
private
|
53
52
|
|
54
53
|
def first_element_range(node, unpack_call)
|
55
|
-
|
56
|
-
unpack_call.source_range.end_pos,
|
57
|
-
node.source_range.end_pos)
|
54
|
+
unpack_call.source_range.end.join(node.source_range.end)
|
58
55
|
end
|
59
56
|
end
|
60
57
|
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'cgi'
|
4
4
|
require 'erb'
|
5
|
-
require 'ostruct'
|
6
5
|
|
7
6
|
module RuboCop
|
8
7
|
module Formatter
|
@@ -87,7 +86,7 @@ module RuboCop
|
|
87
86
|
# rubocop:enable Lint/UselessMethodDefinition
|
88
87
|
|
89
88
|
def decorated_message(offense)
|
90
|
-
offense.message.gsub(/`(.+?)`/) { "<code>#{Regexp.last_match(1)}</code>" }
|
89
|
+
offense.message.gsub(/`(.+?)`/) { "<code>#{escape(Regexp.last_match(1))}</code>" }
|
91
90
|
end
|
92
91
|
|
93
92
|
def highlighted_source_line(offense)
|
data/lib/rubocop/result_cache.rb
CHANGED
data/lib/rubocop/runner.rb
CHANGED
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
@@ -332,8 +332,10 @@ require_relative 'rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler'
|
|
332
332
|
require_relative 'rubocop/cop/lint/ineffective_access_modifier'
|
333
333
|
require_relative 'rubocop/cop/lint/inherit_exception'
|
334
334
|
require_relative 'rubocop/cop/lint/interpolation_check'
|
335
|
+
require_relative 'rubocop/cop/lint/it_without_arguments_in_block'
|
335
336
|
require_relative 'rubocop/cop/lint/lambda_without_literal_block'
|
336
337
|
require_relative 'rubocop/cop/lint/literal_as_condition'
|
338
|
+
require_relative 'rubocop/cop/lint/literal_assignment_in_condition'
|
337
339
|
require_relative 'rubocop/cop/lint/literal_in_interpolation'
|
338
340
|
require_relative 'rubocop/cop/lint/loop'
|
339
341
|
require_relative 'rubocop/cop/lint/missing_cop_enable_directive'
|
@@ -454,6 +456,7 @@ require_relative 'rubocop/cop/style/alias'
|
|
454
456
|
require_relative 'rubocop/cop/style/and_or'
|
455
457
|
require_relative 'rubocop/cop/style/arguments_forwarding'
|
456
458
|
require_relative 'rubocop/cop/style/array_coercion'
|
459
|
+
require_relative 'rubocop/cop/style/array_first_last'
|
457
460
|
require_relative 'rubocop/cop/style/array_intersect'
|
458
461
|
require_relative 'rubocop/cop/style/array_join'
|
459
462
|
require_relative 'rubocop/cop/style/ascii_comments'
|
@@ -678,6 +681,7 @@ require_relative 'rubocop/cop/style/string_literals_in_interpolation'
|
|
678
681
|
require_relative 'rubocop/cop/style/string_methods'
|
679
682
|
require_relative 'rubocop/cop/style/strip'
|
680
683
|
require_relative 'rubocop/cop/style/struct_inheritance'
|
684
|
+
require_relative 'rubocop/cop/style/super_with_args_parentheses'
|
681
685
|
require_relative 'rubocop/cop/style/swap_values'
|
682
686
|
require_relative 'rubocop/cop/style/symbol_array'
|
683
687
|
require_relative 'rubocop/cop/style/symbol_literal'
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.59.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
8
8
|
- Jonas Arvidsson
|
9
9
|
- Yuji Nakayama
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-
|
13
|
+
date: 2023-12-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -134,7 +134,7 @@ dependencies:
|
|
134
134
|
requirements:
|
135
135
|
- - ">="
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: 1.
|
137
|
+
version: 1.30.0
|
138
138
|
- - "<"
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '2.0'
|
@@ -144,7 +144,7 @@ dependencies:
|
|
144
144
|
requirements:
|
145
145
|
- - ">="
|
146
146
|
- !ruby/object:Gem::Version
|
147
|
-
version: 1.
|
147
|
+
version: 1.30.0
|
148
148
|
- - "<"
|
149
149
|
- !ruby/object:Gem::Version
|
150
150
|
version: '2.0'
|
@@ -294,6 +294,7 @@ files:
|
|
294
294
|
- lib/rubocop/cop/internal_affairs/method_name_end_with.rb
|
295
295
|
- lib/rubocop/cop/internal_affairs/method_name_equal.rb
|
296
296
|
- lib/rubocop/cop/internal_affairs/node_destructuring.rb
|
297
|
+
- lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb
|
297
298
|
- lib/rubocop/cop/internal_affairs/node_matcher_directive.rb
|
298
299
|
- lib/rubocop/cop/internal_affairs/node_type_predicate.rb
|
299
300
|
- lib/rubocop/cop/internal_affairs/numblock_handler.rb
|
@@ -466,8 +467,10 @@ files:
|
|
466
467
|
- lib/rubocop/cop/lint/ineffective_access_modifier.rb
|
467
468
|
- lib/rubocop/cop/lint/inherit_exception.rb
|
468
469
|
- lib/rubocop/cop/lint/interpolation_check.rb
|
470
|
+
- lib/rubocop/cop/lint/it_without_arguments_in_block.rb
|
469
471
|
- lib/rubocop/cop/lint/lambda_without_literal_block.rb
|
470
472
|
- lib/rubocop/cop/lint/literal_as_condition.rb
|
473
|
+
- lib/rubocop/cop/lint/literal_assignment_in_condition.rb
|
471
474
|
- lib/rubocop/cop/lint/literal_in_interpolation.rb
|
472
475
|
- lib/rubocop/cop/lint/loop.rb
|
473
476
|
- lib/rubocop/cop/lint/missing_cop_enable_directive.rb
|
@@ -670,6 +673,7 @@ files:
|
|
670
673
|
- lib/rubocop/cop/style/and_or.rb
|
671
674
|
- lib/rubocop/cop/style/arguments_forwarding.rb
|
672
675
|
- lib/rubocop/cop/style/array_coercion.rb
|
676
|
+
- lib/rubocop/cop/style/array_first_last.rb
|
673
677
|
- lib/rubocop/cop/style/array_intersect.rb
|
674
678
|
- lib/rubocop/cop/style/array_join.rb
|
675
679
|
- lib/rubocop/cop/style/ascii_comments.rb
|
@@ -897,6 +901,7 @@ files:
|
|
897
901
|
- lib/rubocop/cop/style/string_methods.rb
|
898
902
|
- lib/rubocop/cop/style/strip.rb
|
899
903
|
- lib/rubocop/cop/style/struct_inheritance.rb
|
904
|
+
- lib/rubocop/cop/style/super_with_args_parentheses.rb
|
900
905
|
- lib/rubocop/cop/style/swap_values.rb
|
901
906
|
- lib/rubocop/cop/style/symbol_array.rb
|
902
907
|
- lib/rubocop/cop/style/symbol_literal.rb
|
@@ -1025,10 +1030,10 @@ metadata:
|
|
1025
1030
|
homepage_uri: https://rubocop.org/
|
1026
1031
|
changelog_uri: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md
|
1027
1032
|
source_code_uri: https://github.com/rubocop/rubocop/
|
1028
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
1033
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.59/
|
1029
1034
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|
1030
1035
|
rubygems_mfa_required: 'true'
|
1031
|
-
post_install_message:
|
1036
|
+
post_install_message:
|
1032
1037
|
rdoc_options: []
|
1033
1038
|
require_paths:
|
1034
1039
|
- lib
|
@@ -1043,8 +1048,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1043
1048
|
- !ruby/object:Gem::Version
|
1044
1049
|
version: '0'
|
1045
1050
|
requirements: []
|
1046
|
-
rubygems_version: 3.
|
1047
|
-
signing_key:
|
1051
|
+
rubygems_version: 3.3.7
|
1052
|
+
signing_key:
|
1048
1053
|
specification_version: 4
|
1049
1054
|
summary: Automatic Ruby code style checking tool.
|
1050
1055
|
test_files: []
|