rubocop 1.50.2 → 1.52.1
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 +3 -3
- data/config/default.yml +38 -5
- data/lib/rubocop/config.rb +4 -0
- data/lib/rubocop/config_obsoletion.rb +2 -2
- data/lib/rubocop/cop/base.rb +5 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +1 -1
- data/lib/rubocop/cop/gemspec/development_dependencies.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +32 -8
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +2 -2
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +0 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -0
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +13 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +3 -4
- data/lib/rubocop/cop/lint/identity_comparison.rb +0 -1
- data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +5 -3
- data/lib/rubocop/cop/lint/inherit_exception.rb +9 -0
- data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +1 -1
- data/lib/rubocop/cop/lint/missing_super.rb +3 -0
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +2 -2
- data/lib/rubocop/cop/lint/ordered_magic_comments.rb +0 -1
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -2
- data/lib/rubocop/cop/lint/shadowed_exception.rb +5 -11
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +23 -9
- data/lib/rubocop/cop/lint/useless_assignment.rb +59 -1
- data/lib/rubocop/cop/lint/void.rb +62 -6
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -2
- data/lib/rubocop/cop/mixin/allowed_receivers.rb +34 -0
- data/lib/rubocop/cop/mixin/comments_help.rb +6 -2
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +1 -1
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +22 -7
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +11 -3
- data/lib/rubocop/cop/naming/variable_name.rb +6 -1
- data/lib/rubocop/cop/style/accessor_grouping.rb +5 -1
- data/lib/rubocop/cop/style/attr.rb +11 -1
- data/lib/rubocop/cop/style/begin_block.rb +1 -2
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/class_equality_comparison.rb +17 -39
- data/lib/rubocop/cop/style/collection_compact.rb +16 -6
- data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
- data/lib/rubocop/cop/style/combinable_loops.rb +26 -6
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
- data/lib/rubocop/cop/style/copyright.rb +5 -2
- data/lib/rubocop/cop/style/dir.rb +1 -1
- data/lib/rubocop/cop/style/dir_empty.rb +8 -14
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +5 -5
- data/lib/rubocop/cop/style/exact_regexp_match.rb +68 -0
- data/lib/rubocop/cop/style/file_read.rb +2 -2
- data/lib/rubocop/cop/style/guard_clause.rb +2 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +1 -22
- data/lib/rubocop/cop/style/hash_except.rb +19 -8
- data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
- data/lib/rubocop/cop/style/if_inside_else.rb +6 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +3 -0
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +9 -5
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +1 -2
- data/lib/rubocop/cop/style/multiple_comparison.rb +14 -0
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/redundant_array_constructor.rb +77 -0
- data/lib/rubocop/cop/style/redundant_filter_chain.rb +101 -0
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +5 -1
- data/lib/rubocop/cop/style/redundant_regexp_constructor.rb +46 -0
- data/lib/rubocop/cop/style/regexp_literal.rb +11 -2
- data/lib/rubocop/cop/style/require_order.rb +11 -5
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -3
- data/lib/rubocop/cop/style/select_by_regexp.rb +15 -5
- data/lib/rubocop/cop/style/semicolon.rb +12 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +3 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -4
- data/lib/rubocop/cop/team.rb +1 -1
- data/lib/rubocop/cop/variable_force/assignment.rb +33 -1
- data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
- data/lib/rubocop/cop/variable_force.rb +1 -0
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/server/client_command/exec.rb +2 -1
- data/lib/rubocop/target_ruby.rb +3 -2
- data/lib/rubocop/version.rb +10 -6
- data/lib/rubocop.rb +5 -0
- metadata +15 -10
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# Identifies usages of `any?`, `empty?` or `none?` predicate methods
|
7
|
+
# chained to `select`/`filter`/`find_all` and change them to use predicate method instead.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# arr.select { |x| x > 1 }.any?
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# arr.any? { |x| x > 1 }
|
15
|
+
#
|
16
|
+
# # bad
|
17
|
+
# arr.select { |x| x > 1 }.empty?
|
18
|
+
# arr.select { |x| x > 1 }.none?
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# arr.none? { |x| x > 1 }
|
22
|
+
#
|
23
|
+
# # good
|
24
|
+
# relation.select(:name).any?
|
25
|
+
# arr.select { |x| x > 1 }.any?(&:odd?)
|
26
|
+
#
|
27
|
+
# @example AllCops:ActiveSupportExtensionsEnabled: false (default)
|
28
|
+
# # good
|
29
|
+
# arr.select { |x| x > 1 }.many?
|
30
|
+
#
|
31
|
+
# @example AllCops:ActiveSupportExtensionsEnabled: true
|
32
|
+
# # bad
|
33
|
+
# arr.select { |x| x > 1 }.many?
|
34
|
+
#
|
35
|
+
# # good
|
36
|
+
# arr.many? { |x| x > 1 }
|
37
|
+
#
|
38
|
+
class RedundantFilterChain < Base
|
39
|
+
extend AutoCorrector
|
40
|
+
|
41
|
+
MSG = 'Use `%<prefer>s` instead of `%<first_method>s.%<second_method>s`.'
|
42
|
+
|
43
|
+
RAILS_METHODS = %i[many?].freeze
|
44
|
+
RESTRICT_ON_SEND = (%i[any? empty? none? one?] + RAILS_METHODS).freeze
|
45
|
+
|
46
|
+
# @!method select_predicate?(node)
|
47
|
+
def_node_matcher :select_predicate?, <<~PATTERN
|
48
|
+
(send
|
49
|
+
{
|
50
|
+
(block $(send _ {:select :filter :find_all}) ...)
|
51
|
+
$(send _ {:select :filter :find_all} block_pass_type?)
|
52
|
+
}
|
53
|
+
${:#{RESTRICT_ON_SEND.join(' :')}})
|
54
|
+
PATTERN
|
55
|
+
|
56
|
+
REPLACEMENT_METHODS = {
|
57
|
+
any?: :any?,
|
58
|
+
empty?: :none?,
|
59
|
+
none?: :none?,
|
60
|
+
one?: :one?,
|
61
|
+
many?: :many?
|
62
|
+
}.freeze
|
63
|
+
private_constant :REPLACEMENT_METHODS
|
64
|
+
|
65
|
+
def on_send(node)
|
66
|
+
return if node.arguments? || node.block_node
|
67
|
+
|
68
|
+
select_predicate?(node) do |select_node, filter_method|
|
69
|
+
return if RAILS_METHODS.include?(filter_method) && !active_support_extensions_enabled?
|
70
|
+
|
71
|
+
register_offense(select_node, node)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def register_offense(select_node, predicate_node)
|
78
|
+
replacement = REPLACEMENT_METHODS[predicate_node.method_name]
|
79
|
+
message = format(MSG, prefer: replacement,
|
80
|
+
first_method: select_node.method_name,
|
81
|
+
second_method: predicate_node.method_name)
|
82
|
+
|
83
|
+
offense_range = offense_range(select_node, predicate_node)
|
84
|
+
|
85
|
+
add_offense(offense_range, message: message) do |corrector|
|
86
|
+
corrector.remove(predicate_range(predicate_node))
|
87
|
+
corrector.replace(select_node.loc.selector, replacement)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def offense_range(select_node, predicate_node)
|
92
|
+
select_node.loc.selector.join(predicate_node.loc.selector)
|
93
|
+
end
|
94
|
+
|
95
|
+
def predicate_range(predicate_node)
|
96
|
+
predicate_node.receiver.source_range.end.join(predicate_node.loc.selector)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -70,6 +70,10 @@ module RuboCop
|
|
70
70
|
|
71
71
|
MSG = 'Redundant line continuation.'
|
72
72
|
ALLOWED_STRING_TOKENS = %i[tSTRING tSTRING_CONTENT].freeze
|
73
|
+
ARGUMENT_TYPES = %i[
|
74
|
+
kFALSE kNIL kSELF kTRUE tCONSTANT tCVAR tFLOAT tGVAR tIDENTIFIER tINTEGER tIVAR
|
75
|
+
tLBRACK tLCURLY tLPAREN_ARG tSTRING tSTRING_BEG tSYMBOL tXSTRING_BEG
|
76
|
+
].freeze
|
73
77
|
|
74
78
|
def on_new_investigation
|
75
79
|
return unless processed_source.ast
|
@@ -124,7 +128,7 @@ module RuboCop
|
|
124
128
|
# do_something \
|
125
129
|
# argument
|
126
130
|
def method_with_argument?(current_token, next_token)
|
127
|
-
current_token.type == :tIDENTIFIER && next_token.type
|
131
|
+
current_token.type == :tIDENTIFIER && ARGUMENT_TYPES.include?(next_token.type)
|
128
132
|
end
|
129
133
|
|
130
134
|
def argument_newline?(node)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# Checks for the instantiation of regexp using redundant `Regexp.new` or `Regexp.compile`.
|
7
|
+
# Autocorrect replaces to regexp literal which is the simplest and fastest.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# Regexp.new(/regexp/)
|
13
|
+
# Regexp.compile(/regexp/)
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# /regexp/
|
17
|
+
# Regexp.new('regexp')
|
18
|
+
# Regexp.compile('regexp')
|
19
|
+
#
|
20
|
+
class RedundantRegexpConstructor < Base
|
21
|
+
extend AutoCorrector
|
22
|
+
|
23
|
+
MSG = 'Remove the redundant `Regexp.%<method>s`.'
|
24
|
+
RESTRICT_ON_SEND = %i[new compile].freeze
|
25
|
+
|
26
|
+
# @!method redundant_regexp_constructor(node)
|
27
|
+
def_node_matcher :redundant_regexp_constructor, <<~PATTERN
|
28
|
+
(send
|
29
|
+
(const {nil? cbase} :Regexp) {:new :compile}
|
30
|
+
(regexp $... (regopt $...)))
|
31
|
+
PATTERN
|
32
|
+
|
33
|
+
def on_send(node)
|
34
|
+
return unless (regexp, regopt = redundant_regexp_constructor(node))
|
35
|
+
|
36
|
+
add_offense(node, message: format(MSG, method: node.method_name)) do |corrector|
|
37
|
+
pattern = regexp.map(&:source).join
|
38
|
+
regopt = regopt.join
|
39
|
+
|
40
|
+
corrector.replace(node, "/#{pattern}/#{regopt}")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -3,7 +3,16 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
# Enforces using
|
6
|
+
# Enforces using `//` or `%r` around regular expressions.
|
7
|
+
#
|
8
|
+
# NOTE: The following `%r` cases using a regexp starts with a blank or `=`
|
9
|
+
# as a method argument allowed to prevent syntax errors.
|
10
|
+
#
|
11
|
+
# [source,ruby]
|
12
|
+
# ----
|
13
|
+
# do_something %r{ regexp} # `do_something / regexp/` is an invalid syntax.
|
14
|
+
# do_something %r{=regexp} # `do_something /=regexp/` is an invalid syntax.
|
15
|
+
# ----
|
7
16
|
#
|
8
17
|
# @example EnforcedStyle: slashes (default)
|
9
18
|
# # bad
|
@@ -151,7 +160,7 @@ module RuboCop
|
|
151
160
|
|
152
161
|
def allowed_omit_parentheses_with_percent_r_literal?(node)
|
153
162
|
return false unless node.parent&.call_type?
|
154
|
-
return true if node.content.start_with?(' ')
|
163
|
+
return true if node.content.start_with?(' ', '=')
|
155
164
|
|
156
165
|
enforced_style = config.for_cop('Style/MethodCallWithArgsParentheses')['EnforcedStyle']
|
157
166
|
|
@@ -88,10 +88,7 @@ module RuboCop
|
|
88
88
|
return unless previous_older_sibling
|
89
89
|
|
90
90
|
add_offense(node, message: format(MSG, name: node.method_name)) do |corrector|
|
91
|
-
corrector
|
92
|
-
range_with_comments_and_lines(previous_older_sibling),
|
93
|
-
range_with_comments_and_lines(node.parent.if_type? ? node.parent : node)
|
94
|
-
)
|
91
|
+
autocorrect(corrector, node, previous_older_sibling)
|
95
92
|
end
|
96
93
|
end
|
97
94
|
|
@@ -109,11 +106,20 @@ module RuboCop
|
|
109
106
|
break unless sibling&.send_type? && sibling&.method?(node.method_name)
|
110
107
|
break unless sibling.arguments? && !sibling.receiver
|
111
108
|
break unless in_same_section?(sibling, node)
|
109
|
+
break unless node.first_argument.str_type? && sibling.first_argument.str_type?
|
112
110
|
|
113
|
-
node.first_argument.
|
111
|
+
node.first_argument.value < sibling.first_argument.value
|
114
112
|
end
|
115
113
|
end
|
116
114
|
|
115
|
+
def autocorrect(corrector, node, previous_older_sibling)
|
116
|
+
range1 = range_with_comments_and_lines(previous_older_sibling)
|
117
|
+
range2 = range_with_comments_and_lines(node.parent.if_type? ? node.parent : node)
|
118
|
+
|
119
|
+
corrector.remove(range2)
|
120
|
+
corrector.insert_before(range1, range2.source)
|
121
|
+
end
|
122
|
+
|
117
123
|
def search_node(node)
|
118
124
|
node.parent.if_type? ? node.parent : node
|
119
125
|
end
|
@@ -3,9 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
# Checks for uses of rescue in its modifier form
|
7
|
-
#
|
8
|
-
# The cop to check `rescue` in its modifier form is added for following
|
6
|
+
# Checks for uses of `rescue` in its modifier form is added for following
|
9
7
|
# reasons:
|
10
8
|
#
|
11
9
|
# * The syntax of modifier form `rescue` can be misleading because it
|
@@ -84,6 +84,7 @@ module RuboCop
|
|
84
84
|
}
|
85
85
|
PATTERN
|
86
86
|
|
87
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
87
88
|
def on_send(node)
|
88
89
|
return unless (block_node = node.block_node)
|
89
90
|
return if block_node.body&.begin_type?
|
@@ -91,11 +92,14 @@ module RuboCop
|
|
91
92
|
return unless (regexp_method_send_node = extract_send_node(block_node))
|
92
93
|
return if match_predicate_without_receiver?(regexp_method_send_node)
|
93
94
|
|
94
|
-
|
95
|
+
replacement = replacement(regexp_method_send_node, node)
|
96
|
+
return if target_ruby_version <= 2.2 && replacement == 'grep_v'
|
97
|
+
|
95
98
|
regexp = find_regexp(regexp_method_send_node, block_node)
|
96
99
|
|
97
|
-
register_offense(node, block_node, regexp,
|
100
|
+
register_offense(node, block_node, regexp, replacement)
|
98
101
|
end
|
102
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
99
103
|
|
100
104
|
private
|
101
105
|
|
@@ -105,9 +109,15 @@ module RuboCop
|
|
105
109
|
node.hash_type? || creates_hash?(node) || env_const?(node)
|
106
110
|
end
|
107
111
|
|
108
|
-
def
|
109
|
-
|
110
|
-
|
112
|
+
def replacement(regexp_method_send_node, node)
|
113
|
+
opposite = opposite?(regexp_method_send_node)
|
114
|
+
|
115
|
+
method_name = node.method_name
|
116
|
+
|
117
|
+
opposite ? OPPOSITE_REPLACEMENTS[method_name] : REPLACEMENTS[method_name]
|
118
|
+
end
|
119
|
+
|
120
|
+
def register_offense(node, block_node, regexp, replacement)
|
111
121
|
message = format(MSG, replacement: replacement, original_method: node.method_name)
|
112
122
|
|
113
123
|
add_offense(block_node, message: message) do |corrector|
|
@@ -90,8 +90,11 @@ module RuboCop
|
|
90
90
|
0
|
91
91
|
elsif exist_semicolon_before_right_curly_brace?(tokens)
|
92
92
|
-3
|
93
|
-
elsif exist_semicolon_after_left_curly_brace?(tokens)
|
93
|
+
elsif exist_semicolon_after_left_curly_brace?(tokens) ||
|
94
|
+
exist_semicolon_after_left_string_interpolation_brace?(tokens)
|
94
95
|
2
|
96
|
+
elsif exist_semicolon_before_right_string_interpolation_brace?(tokens)
|
97
|
+
-4
|
95
98
|
end
|
96
99
|
end
|
97
100
|
|
@@ -103,6 +106,14 @@ module RuboCop
|
|
103
106
|
tokens[1]&.left_curly_brace? && tokens[2]&.semicolon?
|
104
107
|
end
|
105
108
|
|
109
|
+
def exist_semicolon_before_right_string_interpolation_brace?(tokens)
|
110
|
+
tokens[-3]&.type == :tSTRING_DEND && tokens[-4]&.semicolon?
|
111
|
+
end
|
112
|
+
|
113
|
+
def exist_semicolon_after_left_string_interpolation_brace?(tokens)
|
114
|
+
tokens[1]&.type == :tSTRING_DBEG && tokens[2]&.semicolon?
|
115
|
+
end
|
116
|
+
|
106
117
|
def register_semicolon(line, column, after_expression, token_before_semicolon = nil)
|
107
118
|
range = source_range(processed_source.buffer, line, column)
|
108
119
|
|
@@ -135,7 +135,7 @@ module RuboCop
|
|
135
135
|
|
136
136
|
def disallow_endless_method_style?
|
137
137
|
endless_method_config = config.for_cop('Style/EndlessMethod')
|
138
|
-
return
|
138
|
+
return true unless endless_method_config['Enabled']
|
139
139
|
|
140
140
|
endless_method_config['EnforcedStyle'] == 'disallow'
|
141
141
|
end
|
@@ -186,7 +186,9 @@ module RuboCop
|
|
186
186
|
begin_pos = condition.first_argument.source_range.begin_pos
|
187
187
|
return if end_pos > begin_pos
|
188
188
|
|
189
|
-
|
189
|
+
range = range_between(end_pos, begin_pos)
|
190
|
+
corrector.remove(range)
|
191
|
+
corrector.insert_after(range, '(')
|
190
192
|
corrector.insert_after(condition.last_argument, ')')
|
191
193
|
end
|
192
194
|
|
@@ -3,8 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
#
|
7
|
-
# This cop looks for uses of Perl-style global variables.
|
6
|
+
# Looks for uses of Perl-style global variables.
|
8
7
|
# Correcting to global variables in the 'English' library
|
9
8
|
# will add a require statement to the top of the file if
|
10
9
|
# enabled by RequireEnglish config.
|
@@ -234,9 +233,9 @@ module RuboCop
|
|
234
233
|
end
|
235
234
|
|
236
235
|
def matching_styles(global)
|
237
|
-
STYLE_VARS_MAP.
|
236
|
+
STYLE_VARS_MAP.filter_map do |style, vars|
|
238
237
|
style if vars.values.flatten(1).include? global
|
239
|
-
end
|
238
|
+
end
|
240
239
|
end
|
241
240
|
|
242
241
|
def english_name_replacement(preferred_name, node)
|
data/lib/rubocop/cop/team.rb
CHANGED
@@ -47,6 +47,10 @@ module RuboCop
|
|
47
47
|
@node.type == REGEXP_NAMED_CAPTURE_TYPE
|
48
48
|
end
|
49
49
|
|
50
|
+
def exception_assignment?
|
51
|
+
node.parent&.resbody_type? && node.parent.exception_variable == node
|
52
|
+
end
|
53
|
+
|
50
54
|
def operator_assignment?
|
51
55
|
return false unless meta_assignment_node
|
52
56
|
|
@@ -59,6 +63,18 @@ module RuboCop
|
|
59
63
|
meta_assignment_node.type == MULTIPLE_ASSIGNMENT_TYPE
|
60
64
|
end
|
61
65
|
|
66
|
+
def rest_assignment?
|
67
|
+
return false unless meta_assignment_node
|
68
|
+
|
69
|
+
meta_assignment_node.type == REST_ASSIGNMENT_TYPE
|
70
|
+
end
|
71
|
+
|
72
|
+
def for_assignment?
|
73
|
+
return false unless meta_assignment_node
|
74
|
+
|
75
|
+
meta_assignment_node.for_type?
|
76
|
+
end
|
77
|
+
|
62
78
|
def operator
|
63
79
|
assignment_node = meta_assignment_node || @node
|
64
80
|
assignment_node.loc.operator.source
|
@@ -66,7 +82,10 @@ module RuboCop
|
|
66
82
|
|
67
83
|
def meta_assignment_node
|
68
84
|
unless instance_variable_defined?(:@meta_assignment_node)
|
69
|
-
@meta_assignment_node = operator_assignment_node ||
|
85
|
+
@meta_assignment_node = operator_assignment_node ||
|
86
|
+
multiple_assignment_node ||
|
87
|
+
rest_assignment_node ||
|
88
|
+
for_assignment_node
|
70
89
|
end
|
71
90
|
|
72
91
|
@meta_assignment_node
|
@@ -90,6 +109,19 @@ module RuboCop
|
|
90
109
|
|
91
110
|
grandparent_node
|
92
111
|
end
|
112
|
+
|
113
|
+
def rest_assignment_node
|
114
|
+
return nil unless node.parent
|
115
|
+
return nil unless node.parent.type == REST_ASSIGNMENT_TYPE
|
116
|
+
|
117
|
+
node.parent
|
118
|
+
end
|
119
|
+
|
120
|
+
def for_assignment_node
|
121
|
+
return nil unless node.parent&.for_type?
|
122
|
+
|
123
|
+
node.parent
|
124
|
+
end
|
93
125
|
end
|
94
126
|
end
|
95
127
|
end
|
@@ -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.block_type?
|
116
|
+
break variables unless scope.node.block_type? || scope.node.numblock_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.block_type?
|
123
|
+
return unless current_scope.node.block_type? || current_scope.node.numblock_type?
|
124
124
|
return if variable.scope == current_scope
|
125
125
|
|
126
126
|
variable.capture_with_block!
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -83,7 +83,7 @@ module RuboCop
|
|
83
83
|
config_store.for_pwd.for_all_cops['AllowSymlinksInCacheRootDirectory']
|
84
84
|
end
|
85
85
|
|
86
|
-
|
86
|
+
attr_reader :path
|
87
87
|
|
88
88
|
def initialize(file, team, options, config_store, cache_root = nil)
|
89
89
|
cache_root ||= File.join(options[:cache_root], 'rubocop_cache') if options[:cache_root]
|
@@ -18,10 +18,11 @@ module RuboCop
|
|
18
18
|
def run
|
19
19
|
ensure_server!
|
20
20
|
Cache.status_path.delete if Cache.status_path.file?
|
21
|
+
read_stdin = ARGV.include?('-s') || ARGV.include?('--stdin')
|
21
22
|
send_request(
|
22
23
|
command: 'exec',
|
23
24
|
args: ARGV.dup,
|
24
|
-
body: $stdin.
|
25
|
+
body: read_stdin ? $stdin.read : ''
|
25
26
|
)
|
26
27
|
warn stderr unless stderr.empty?
|
27
28
|
status
|
data/lib/rubocop/target_ruby.rb
CHANGED
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
# @api private
|
6
6
|
class TargetRuby
|
7
7
|
KNOWN_RUBIES = [2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3].freeze
|
8
|
-
DEFAULT_VERSION = 2.
|
8
|
+
DEFAULT_VERSION = 2.7
|
9
9
|
|
10
10
|
OBSOLETE_RUBIES = {
|
11
11
|
1.9 => '0.41',
|
@@ -14,7 +14,8 @@ module RuboCop
|
|
14
14
|
2.2 => '0.68',
|
15
15
|
2.3 => '0.81',
|
16
16
|
2.4 => '1.12',
|
17
|
-
2.5 => '1.28'
|
17
|
+
2.5 => '1.28',
|
18
|
+
2.6 => '1.50'
|
18
19
|
}.freeze
|
19
20
|
private_constant :KNOWN_RUBIES, :OBSOLETE_RUBIES
|
20
21
|
|
data/lib/rubocop/version.rb
CHANGED
@@ -3,15 +3,19 @@
|
|
3
3
|
module RuboCop
|
4
4
|
# This module holds the RuboCop version information.
|
5
5
|
module Version
|
6
|
-
STRING = '1.
|
6
|
+
STRING = '1.52.1'
|
7
7
|
|
8
8
|
MSG = '%<version>s (using Parser %<parser_version>s, ' \
|
9
9
|
'rubocop-ast %<rubocop_ast_version>s, ' \
|
10
10
|
'running on %<ruby_engine>s %<ruby_version>s)%<server_mode>s [%<ruby_platform>s]'
|
11
11
|
|
12
|
-
CANONICAL_FEATURE_NAMES = {
|
13
|
-
|
14
|
-
|
12
|
+
CANONICAL_FEATURE_NAMES = {
|
13
|
+
'Rspec' => 'RSpec', 'Graphql' => 'GraphQL', 'Md' => 'Markdown', 'Factory_bot' => 'FactoryBot',
|
14
|
+
'Thread_safety' => 'ThreadSafety'
|
15
|
+
}.freeze
|
16
|
+
EXTENSION_PATH_NAMES = {
|
17
|
+
'rubocop-md' => 'markdown', 'rubocop-factory_bot' => 'factory_bot'
|
18
|
+
}.freeze
|
15
19
|
|
16
20
|
# @api private
|
17
21
|
def self.version(debug: false, env: nil)
|
@@ -43,7 +47,7 @@ module RuboCop
|
|
43
47
|
env.config_store.unvalidated.for_pwd.loaded_features.sort
|
44
48
|
end
|
45
49
|
|
46
|
-
features.
|
50
|
+
features.filter_map do |loaded_feature|
|
47
51
|
next unless (match = loaded_feature.match(/rubocop-(?<feature>.*)/))
|
48
52
|
|
49
53
|
# Get the expected name of the folder containing the extension code.
|
@@ -61,7 +65,7 @@ module RuboCop
|
|
61
65
|
next unless (feature_version = feature_version(feature))
|
62
66
|
|
63
67
|
" - #{loaded_feature} #{feature_version}"
|
64
|
-
end
|
68
|
+
end
|
65
69
|
end
|
66
70
|
|
67
71
|
# Returns feature version in one of two ways:
|
data/lib/rubocop.rb
CHANGED
@@ -69,6 +69,7 @@ require_relative 'rubocop/cop/mixin/alignment'
|
|
69
69
|
require_relative 'rubocop/cop/mixin/allowed_identifiers'
|
70
70
|
require_relative 'rubocop/cop/mixin/allowed_methods'
|
71
71
|
require_relative 'rubocop/cop/mixin/allowed_pattern'
|
72
|
+
require_relative 'rubocop/cop/mixin/allowed_receivers'
|
72
73
|
require_relative 'rubocop/cop/mixin/auto_corrector' # rubocop:todo Naming/InclusiveLanguage
|
73
74
|
require_relative 'rubocop/cop/mixin/check_assignment'
|
74
75
|
require_relative 'rubocop/cop/mixin/check_line_breakable'
|
@@ -507,6 +508,7 @@ require_relative 'rubocop/cop/style/end_block'
|
|
507
508
|
require_relative 'rubocop/cop/style/env_home'
|
508
509
|
require_relative 'rubocop/cop/style/eval_with_location'
|
509
510
|
require_relative 'rubocop/cop/style/even_odd'
|
511
|
+
require_relative 'rubocop/cop/style/exact_regexp_match'
|
510
512
|
require_relative 'rubocop/cop/style/expand_path_arguments'
|
511
513
|
require_relative 'rubocop/cop/style/explicit_block_argument'
|
512
514
|
require_relative 'rubocop/cop/style/exponential_notation'
|
@@ -557,15 +559,18 @@ require_relative 'rubocop/cop/style/multiline_in_pattern_then'
|
|
557
559
|
require_relative 'rubocop/cop/style/numbered_parameters'
|
558
560
|
require_relative 'rubocop/cop/style/open_struct_use'
|
559
561
|
require_relative 'rubocop/cop/style/operator_method_call'
|
562
|
+
require_relative 'rubocop/cop/style/redundant_array_constructor'
|
560
563
|
require_relative 'rubocop/cop/style/redundant_assignment'
|
561
564
|
require_relative 'rubocop/cop/style/redundant_constant_base'
|
562
565
|
require_relative 'rubocop/cop/style/redundant_double_splat_hash_braces'
|
563
566
|
require_relative 'rubocop/cop/style/redundant_each'
|
564
567
|
require_relative 'rubocop/cop/style/redundant_fetch_block'
|
565
568
|
require_relative 'rubocop/cop/style/redundant_file_extension_in_require'
|
569
|
+
require_relative 'rubocop/cop/style/redundant_filter_chain'
|
566
570
|
require_relative 'rubocop/cop/style/redundant_heredoc_delimiter_quotes'
|
567
571
|
require_relative 'rubocop/cop/style/redundant_initialize'
|
568
572
|
require_relative 'rubocop/cop/style/redundant_line_continuation'
|
573
|
+
require_relative 'rubocop/cop/style/redundant_regexp_constructor'
|
569
574
|
require_relative 'rubocop/cop/style/redundant_self_assignment'
|
570
575
|
require_relative 'rubocop/cop/style/redundant_self_assignment_branch'
|
571
576
|
require_relative 'rubocop/cop/style/require_order'
|