rubocop 1.43.0 → 1.45.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 +1 -1
- data/config/default.yml +64 -29
- data/lib/rubocop/cli.rb +54 -8
- data/lib/rubocop/config_loader.rb +12 -15
- data/lib/rubocop/config_loader_resolver.rb +3 -4
- data/lib/rubocop/cop/base.rb +27 -9
- data/lib/rubocop/cop/commissioner.rb +8 -2
- data/lib/rubocop/cop/cop.rb +23 -3
- data/lib/rubocop/cop/corrector.rb +10 -2
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +1 -6
- data/lib/rubocop/cop/gemspec/development_dependencies.rb +107 -0
- data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +11 -3
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/block_end_newline.rb +7 -1
- data/lib/rubocop/cop/layout/class_structure.rb +2 -16
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +2 -6
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +6 -9
- data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +11 -13
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +4 -4
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +5 -4
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +4 -0
- data/lib/rubocop/cop/lint/debugger.rb +8 -27
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +62 -112
- data/lib/rubocop/cop/lint/else_layout.rb +2 -6
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +14 -7
- data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +15 -17
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +8 -5
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +11 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +7 -4
- data/lib/rubocop/cop/lint/useless_method_definition.rb +3 -3
- data/lib/rubocop/cop/lint/useless_rescue.rb +15 -1
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +9 -1
- data/lib/rubocop/cop/lint/void.rb +19 -10
- data/lib/rubocop/cop/metrics/block_length.rb +1 -1
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +2 -5
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/allowed_methods.rb +3 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +5 -3
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +51 -25
- data/lib/rubocop/cop/mixin/line_length_help.rb +3 -1
- data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -3
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +4 -0
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/registry.rb +12 -7
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -11
- data/lib/rubocop/cop/style/arguments_forwarding.rb +1 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +8 -2
- data/lib/rubocop/cop/style/class_and_module_children.rb +3 -10
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/comparable_clamp.rb +125 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +0 -6
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/documentation_method.rb +6 -0
- data/lib/rubocop/cop/style/infinite_loop.rb +2 -5
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +114 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +11 -5
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -0
- data/lib/rubocop/cop/style/min_max_comparison.rb +11 -1
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +0 -4
- data/lib/rubocop/cop/style/multiline_memoization.rb +2 -2
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +18 -3
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -5
- data/lib/rubocop/cop/style/numbered_parameters_limit.rb +11 -3
- data/lib/rubocop/cop/style/one_line_conditional.rb +3 -6
- data/lib/rubocop/cop/style/operator_method_call.rb +2 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +3 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +16 -1
- data/lib/rubocop/cop/style/redundant_conditional.rb +0 -4
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +16 -10
- data/lib/rubocop/cop/style/redundant_heredoc_delimiter_quotes.rb +58 -0
- data/lib/rubocop/cop/style/require_order.rb +2 -9
- data/lib/rubocop/cop/style/self_assignment.rb +2 -2
- data/lib/rubocop/cop/style/semicolon.rb +24 -2
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +12 -5
- data/lib/rubocop/cop/style/yoda_expression.rb +11 -2
- data/lib/rubocop/cop/team.rb +19 -14
- data/lib/rubocop/cop/variable_force/scope.rb +3 -3
- data/lib/rubocop/cop/variable_force/variable_table.rb +3 -1
- data/lib/rubocop/cop/variable_force.rb +1 -1
- data/lib/rubocop/formatter.rb +0 -1
- data/lib/rubocop/options.rb +22 -1
- data/lib/rubocop/rspec/expect_offense.rb +6 -4
- data/lib/rubocop/runner.rb +40 -4
- data/lib/rubocop/server/cache.rb +10 -3
- data/lib/rubocop/server/cli.rb +37 -18
- data/lib/rubocop/server/client_command/exec.rb +1 -1
- data/lib/rubocop/server/client_command/start.rb +6 -1
- data/lib/rubocop/server/core.rb +23 -8
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +4 -0
- metadata +11 -27
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Gemspec
|
6
|
+
# Enforce that development dependencies for a gem are specified in
|
7
|
+
# `Gemfile`, rather than in the `gemspec` using
|
8
|
+
# `add_development_dependency`. Alternatively, using `EnforcedStyle:
|
9
|
+
# gemspec`, enforce that all dependencies are specified in `gemspec`,
|
10
|
+
# rather than in `Gemfile`.
|
11
|
+
#
|
12
|
+
# @example EnforcedStyle: Gemfile (default)
|
13
|
+
# # Specify runtime dependencies in your gemspec,
|
14
|
+
# # but all other dependencies in your Gemfile.
|
15
|
+
#
|
16
|
+
# # bad
|
17
|
+
# # example.gemspec
|
18
|
+
# s.add_development_dependency "foo"
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# # Gemfile
|
22
|
+
# gem "foo"
|
23
|
+
#
|
24
|
+
# # good
|
25
|
+
# # gems.rb
|
26
|
+
# gem "foo"
|
27
|
+
#
|
28
|
+
# # good (with AllowedGems: ["bar"])
|
29
|
+
# # example.gemspec
|
30
|
+
# s.add_development_dependency "bar"
|
31
|
+
#
|
32
|
+
# @example EnforcedStyle: gems.rb
|
33
|
+
# # Specify runtime dependencies in your gemspec,
|
34
|
+
# # but all other dependencies in your Gemfile.
|
35
|
+
# #
|
36
|
+
# # Identical to `EnforcedStyle: Gemfile`, but with a different error message.
|
37
|
+
# # Rely on Bundler/GemFilename to enforce the use of `Gemfile` vs `gems.rb`.
|
38
|
+
#
|
39
|
+
# # bad
|
40
|
+
# # example.gemspec
|
41
|
+
# s.add_development_dependency "foo"
|
42
|
+
#
|
43
|
+
# # good
|
44
|
+
# # Gemfile
|
45
|
+
# gem "foo"
|
46
|
+
#
|
47
|
+
# # good
|
48
|
+
# # gems.rb
|
49
|
+
# gem "foo"
|
50
|
+
#
|
51
|
+
# # good (with AllowedGems: ["bar"])
|
52
|
+
# # example.gemspec
|
53
|
+
# s.add_development_dependency "bar"
|
54
|
+
#
|
55
|
+
# @example EnforcedStyle: gemspec
|
56
|
+
# # Specify all dependencies in your gemspec.
|
57
|
+
#
|
58
|
+
# # bad
|
59
|
+
# # Gemfile
|
60
|
+
# gem "foo"
|
61
|
+
#
|
62
|
+
# # good
|
63
|
+
# # example.gemspec
|
64
|
+
# s.add_development_dependency "foo"
|
65
|
+
#
|
66
|
+
# # good (with AllowedGems: ["bar"])
|
67
|
+
# # Gemfile
|
68
|
+
# gem "bar"
|
69
|
+
#
|
70
|
+
class DevelopmentDependencies < Base
|
71
|
+
include ConfigurableEnforcedStyle
|
72
|
+
|
73
|
+
MSG = 'Specify development dependencies in %<preferred>s.'
|
74
|
+
RESTRICT_ON_SEND = %i[add_development_dependency gem].freeze
|
75
|
+
|
76
|
+
# @!method add_development_dependency?(node)
|
77
|
+
def_node_matcher :add_development_dependency?, <<~PATTERN
|
78
|
+
(send _ :add_development_dependency (str #forbidden_gem? ...))
|
79
|
+
PATTERN
|
80
|
+
|
81
|
+
# @!method gem?(node)
|
82
|
+
def_node_matcher :gem?, <<~PATTERN
|
83
|
+
(send _ :gem (str #forbidden_gem? ...))
|
84
|
+
PATTERN
|
85
|
+
|
86
|
+
def on_send(node)
|
87
|
+
case style
|
88
|
+
when :Gemfile, :'gems.rb'
|
89
|
+
add_offense(node) if add_development_dependency?(node)
|
90
|
+
when :gemspec
|
91
|
+
add_offense(node) if gem?(node)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def forbidden_gem?(gem_name)
|
98
|
+
!cop_config['AllowedGems'].include?(gem_name)
|
99
|
+
end
|
100
|
+
|
101
|
+
def message(_range)
|
102
|
+
format(MSG, preferred: style)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -31,9 +31,17 @@ module RuboCop
|
|
31
31
|
(send nil? :let
|
32
32
|
(sym :config))
|
33
33
|
(args)
|
34
|
-
|
35
|
-
(
|
36
|
-
(const
|
34
|
+
{
|
35
|
+
(send
|
36
|
+
(const
|
37
|
+
(const nil? :RuboCop) :Config) :new)
|
38
|
+
(send
|
39
|
+
(const
|
40
|
+
(const nil? :RuboCop) :Config) :new
|
41
|
+
(hash (pair (send (send (send nil? :described_class) :badge) :to_s)
|
42
|
+
(send nil? :cop_config))))
|
43
|
+
}
|
44
|
+
)
|
37
45
|
PATTERN
|
38
46
|
|
39
47
|
def on_block(node)
|
@@ -46,7 +46,7 @@ module RuboCop
|
|
46
46
|
def register_offense(node)
|
47
47
|
add_offense(node.loc.end, message: message(node)) do |corrector|
|
48
48
|
offense_range = offense_range(node)
|
49
|
-
replacement =
|
49
|
+
replacement = replacement(node)
|
50
50
|
|
51
51
|
if (heredoc = last_heredoc_argument(node.body))
|
52
52
|
corrector.remove(offense_range)
|
@@ -79,6 +79,12 @@ module RuboCop
|
|
79
79
|
)
|
80
80
|
end
|
81
81
|
|
82
|
+
def replacement(node)
|
83
|
+
end_with_method_chain = node.loc.end.join(end_of_method_chain(node).loc.expression.end)
|
84
|
+
|
85
|
+
"\n#{end_with_method_chain.source.strip}"
|
86
|
+
end
|
87
|
+
|
82
88
|
def end_of_method_chain(node)
|
83
89
|
return node unless node.parent&.call_type?
|
84
90
|
|
@@ -134,6 +134,7 @@ module RuboCop
|
|
134
134
|
#
|
135
135
|
class ClassStructure < Base
|
136
136
|
include VisibilityHelp
|
137
|
+
include CommentsHelp
|
137
138
|
extend AutoCorrector
|
138
139
|
|
139
140
|
HUMANIZED_NODE_TYPE = {
|
@@ -163,7 +164,7 @@ module RuboCop
|
|
163
164
|
|
164
165
|
# Autocorrect by swapping between two nodes autocorrecting them
|
165
166
|
def autocorrect(corrector, node)
|
166
|
-
previous = node.left_siblings.find do |sibling|
|
167
|
+
previous = node.left_siblings.reverse.find do |sibling|
|
167
168
|
!ignore_for_autocorrect?(node, sibling)
|
168
169
|
end
|
169
170
|
return unless previous
|
@@ -283,21 +284,6 @@ module RuboCop
|
|
283
284
|
node.arguments.any? { |arg| (arg.sym_type? || arg.str_type?) && arg.value == name }
|
284
285
|
end
|
285
286
|
|
286
|
-
def source_range_with_comment(node)
|
287
|
-
begin_pos, end_pos =
|
288
|
-
if (node.def_type? && !node.method?(:initialize)) ||
|
289
|
-
(node.send_type? && node.def_modifier?)
|
290
|
-
start_node = find_visibility_start(node) || node
|
291
|
-
end_node = find_visibility_end(node) || node
|
292
|
-
[begin_pos_with_comment(start_node),
|
293
|
-
end_position_for(end_node) + 1]
|
294
|
-
else
|
295
|
-
[begin_pos_with_comment(node), end_position_for(node)]
|
296
|
-
end
|
297
|
-
|
298
|
-
Parser::Source::Range.new(buffer, begin_pos, end_pos)
|
299
|
-
end
|
300
|
-
|
301
287
|
def end_position_for(node)
|
302
288
|
heredoc = find_heredoc(node)
|
303
289
|
return heredoc.location.heredoc_end.end_pos + 1 if heredoc
|
@@ -144,7 +144,7 @@ module RuboCop
|
|
144
144
|
def expected_column(left_paren, elements)
|
145
145
|
if line_break_after_left_paren?(left_paren, elements)
|
146
146
|
source_indent = processed_source.line_indentation(first_argument_line(elements))
|
147
|
-
new_indent = source_indent -
|
147
|
+
new_indent = source_indent - configured_indentation_width
|
148
148
|
|
149
149
|
new_indent.negative? ? 0 : new_indent
|
150
150
|
elsif all_elements_aligned?(elements)
|
@@ -157,7 +157,7 @@ module RuboCop
|
|
157
157
|
def all_elements_aligned?(elements)
|
158
158
|
elements.flat_map do |e|
|
159
159
|
if e.hash_type?
|
160
|
-
e.
|
160
|
+
e.each_child_node.map { |child| child.loc.column }
|
161
161
|
else
|
162
162
|
e.loc.column
|
163
163
|
end
|
@@ -184,10 +184,6 @@ module RuboCop
|
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
|
-
def indentation_width
|
188
|
-
@config.for_cop('Layout/IndentationWidth')['Width'] || 2
|
189
|
-
end
|
190
|
-
|
191
187
|
def line_break_after_left_paren?(left_paren, elements)
|
192
188
|
elements.first && elements.first.loc.line > left_paren.line
|
193
189
|
end
|
@@ -179,7 +179,7 @@ module RuboCop
|
|
179
179
|
|
180
180
|
send_node = arg_node.parent
|
181
181
|
text = base_range(send_node, arg_node).source.strip
|
182
|
-
base = if
|
182
|
+
base = if !text.include?("\n") && special_inner_call_indentation?(send_node)
|
183
183
|
"`#{text}`"
|
184
184
|
elsif comment_line?(text.lines.reverse_each.first)
|
185
185
|
'the start of the previous line (not counting the comment)'
|
@@ -22,6 +22,7 @@ module RuboCop
|
|
22
22
|
# RUBY
|
23
23
|
#
|
24
24
|
class HeredocIndentation < Base
|
25
|
+
include Alignment
|
25
26
|
include Heredoc
|
26
27
|
extend AutoCorrector
|
27
28
|
|
@@ -37,7 +38,7 @@ module RuboCop
|
|
37
38
|
heredoc_indent_type = heredoc_indent_type(node)
|
38
39
|
|
39
40
|
if heredoc_indent_type == '~'
|
40
|
-
expected_indent_level = base_indent_level(node) +
|
41
|
+
expected_indent_level = base_indent_level(node) + configured_indentation_width
|
41
42
|
return if expected_indent_level == body_indent_level
|
42
43
|
else
|
43
44
|
return unless body_indent_level.zero?
|
@@ -66,9 +67,9 @@ module RuboCop
|
|
66
67
|
current_indent_type = "<<#{heredoc_indent_type}"
|
67
68
|
|
68
69
|
if current_indent_type == '<<~'
|
69
|
-
width_message(
|
70
|
+
width_message(configured_indentation_width)
|
70
71
|
else
|
71
|
-
type_message(
|
72
|
+
type_message(configured_indentation_width, current_indent_type)
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
@@ -89,7 +90,7 @@ module RuboCop
|
|
89
90
|
|
90
91
|
body = heredoc_body(node)
|
91
92
|
|
92
|
-
expected_indent = base_indent_level(node) +
|
93
|
+
expected_indent = base_indent_level(node) + configured_indentation_width
|
93
94
|
actual_indent = indent_level(body)
|
94
95
|
increase_indent_level = expected_indent - actual_indent
|
95
96
|
|
@@ -122,7 +123,7 @@ module RuboCop
|
|
122
123
|
def indented_body(node)
|
123
124
|
body = heredoc_body(node)
|
124
125
|
body_indent_level = indent_level(body)
|
125
|
-
correct_indent_level = base_indent_level(node) +
|
126
|
+
correct_indent_level = base_indent_level(node) + configured_indentation_width
|
126
127
|
body.gsub(/^[^\S\r\n]{#{body_indent_level}}/, ' ' * correct_indent_level)
|
127
128
|
end
|
128
129
|
|
@@ -148,10 +149,6 @@ module RuboCop
|
|
148
149
|
node.source[/^<<([~-])/, 1]
|
149
150
|
end
|
150
151
|
|
151
|
-
def indentation_width
|
152
|
-
@config.for_cop('Layout/IndentationWidth')['Width'] || 2
|
153
|
-
end
|
154
|
-
|
155
152
|
def heredoc_body(node)
|
156
153
|
node.loc.heredoc_body.source
|
157
154
|
end
|
@@ -177,7 +177,7 @@ module RuboCop
|
|
177
177
|
end
|
178
178
|
|
179
179
|
def autocorrect(corrector, range)
|
180
|
-
if
|
180
|
+
if range.source.include?('**') && !space_around_exponent_operator?
|
181
181
|
corrector.replace(range, '**')
|
182
182
|
elsif range.source.end_with?("\n")
|
183
183
|
corrector.replace(range, " #{range.source.strip}\n")
|
@@ -78,8 +78,11 @@ module RuboCop
|
|
78
78
|
def on_array(node)
|
79
79
|
return unless node.square_brackets?
|
80
80
|
|
81
|
-
left, right = array_brackets(node)
|
82
|
-
|
81
|
+
tokens, left, right = array_brackets(node)
|
82
|
+
|
83
|
+
if empty_brackets?(left, right, tokens: tokens)
|
84
|
+
return empty_offenses(node, left, right, EMPTY_MSG)
|
85
|
+
end
|
83
86
|
|
84
87
|
start_ok = next_to_newline?(node, left)
|
85
88
|
end_ok = node.single_line? ? false : end_has_own_line?(right)
|
@@ -90,9 +93,9 @@ module RuboCop
|
|
90
93
|
private
|
91
94
|
|
92
95
|
def autocorrect(corrector, node)
|
93
|
-
left, right = array_brackets(node)
|
96
|
+
tokens, left, right = array_brackets(node)
|
94
97
|
|
95
|
-
if empty_brackets?(left, right)
|
98
|
+
if empty_brackets?(left, right, tokens: tokens)
|
96
99
|
SpaceCorrector.empty_corrections(processed_source, corrector, empty_config, left, right)
|
97
100
|
elsif style == :no_space
|
98
101
|
SpaceCorrector.remove_space(processed_source, corrector, left, right)
|
@@ -104,15 +107,12 @@ module RuboCop
|
|
104
107
|
end
|
105
108
|
|
106
109
|
def array_brackets(node)
|
107
|
-
|
108
|
-
end
|
110
|
+
tokens = processed_source.tokens_within(node)
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
end
|
112
|
+
left = tokens.find(&:left_array_bracket?)
|
113
|
+
right = tokens.reverse_each.find(&:right_bracket?)
|
113
114
|
|
114
|
-
|
115
|
-
processed_source.tokens_within(node).reverse.find(&:right_bracket?)
|
115
|
+
[tokens, left, right]
|
116
116
|
end
|
117
117
|
|
118
118
|
def empty_config
|
@@ -178,8 +178,6 @@ module RuboCop
|
|
178
178
|
def multi_dimensional_array?(node, token, side: :right)
|
179
179
|
offset = side == :right ? -1 : +1
|
180
180
|
i = index_for(node, token) + offset
|
181
|
-
# TODO: change this type check once
|
182
|
-
# https://github.com/rubocop/rubocop-ast/pull/240 is merged
|
183
181
|
i += offset while processed_source.tokens_within(node)[i].new_line?
|
184
182
|
if side == :right
|
185
183
|
processed_source.tokens_within(node)[i].right_bracket?
|
@@ -74,7 +74,7 @@ module RuboCop
|
|
74
74
|
|
75
75
|
right_token = closing_bracket(tokens, left_token)
|
76
76
|
|
77
|
-
if empty_brackets?(left_token, right_token)
|
77
|
+
if empty_brackets?(left_token, right_token, tokens: tokens)
|
78
78
|
return empty_offenses(node, left_token, right_token, EMPTY_MSG)
|
79
79
|
end
|
80
80
|
|
@@ -90,9 +90,9 @@ module RuboCop
|
|
90
90
|
private
|
91
91
|
|
92
92
|
def autocorrect(corrector, node)
|
93
|
-
left, right = reference_brackets(node)
|
93
|
+
tokens, left, right = reference_brackets(node)
|
94
94
|
|
95
|
-
if empty_brackets?(left, right)
|
95
|
+
if empty_brackets?(left, right, tokens: tokens)
|
96
96
|
SpaceCorrector.empty_corrections(processed_source, corrector, empty_config, left, right)
|
97
97
|
elsif style == :no_space
|
98
98
|
SpaceCorrector.remove_space(processed_source, corrector, left, right)
|
@@ -104,7 +104,7 @@ module RuboCop
|
|
104
104
|
def reference_brackets(node)
|
105
105
|
tokens = processed_source.tokens_within(node)
|
106
106
|
left = left_ref_bracket(node, tokens)
|
107
|
-
[left, closing_bracket(tokens, left)]
|
107
|
+
[tokens, left, closing_bracket(tokens, left)]
|
108
108
|
end
|
109
109
|
|
110
110
|
def left_ref_bracket(node, tokens)
|
@@ -31,13 +31,14 @@ module RuboCop
|
|
31
31
|
def on_interpolation(begin_node)
|
32
32
|
return if begin_node.multiline?
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
tokens = processed_source.tokens_within(begin_node)
|
35
|
+
left, right = delimiters(begin_node)
|
36
|
+
return if empty_brackets?(left, right, tokens: tokens)
|
36
37
|
|
37
38
|
if style == :no_space
|
38
|
-
no_space_offenses(begin_node,
|
39
|
+
no_space_offenses(begin_node, left, right, NO_SPACE_MSG)
|
39
40
|
else
|
40
|
-
space_offenses(begin_node,
|
41
|
+
space_offenses(begin_node, left, right, SPACE_MSG)
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
@@ -38,6 +38,10 @@ module RuboCop
|
|
38
38
|
'a whitespace to the right of the `%<operator>s` if it ' \
|
39
39
|
'should be %<possible>s.'
|
40
40
|
|
41
|
+
def self.autocorrect_incompatible_with
|
42
|
+
[Naming::BlockForwarding]
|
43
|
+
end
|
44
|
+
|
41
45
|
def on_new_investigation
|
42
46
|
processed_source.diagnostics.each do |diagnostic|
|
43
47
|
next unless diagnostic.reason == :ambiguous_prefix
|
@@ -82,44 +82,25 @@ module RuboCop
|
|
82
82
|
def debugger_methods
|
83
83
|
@debugger_methods ||= begin
|
84
84
|
config = cop_config.fetch('DebuggerMethods', [])
|
85
|
-
|
86
|
-
values.map do |v|
|
87
|
-
next unless v
|
88
|
-
|
89
|
-
*receiver, method_name = v.split('.')
|
90
|
-
{
|
91
|
-
receiver: receiver.empty? ? nil : receiver.map(&:to_sym),
|
92
|
-
method_name: method_name.to_sym
|
93
|
-
}
|
94
|
-
end.compact
|
85
|
+
config.is_a?(Array) ? config : config.values.flatten
|
95
86
|
end
|
96
87
|
end
|
97
88
|
|
98
89
|
def debugger_method?(send_node)
|
99
|
-
|
100
|
-
|
101
|
-
debugger_methods.any? do |method|
|
102
|
-
next unless method[:method_name] == method_name
|
90
|
+
return if send_node.parent&.send_type? && send_node.parent.receiver == send_node
|
103
91
|
|
104
|
-
|
105
|
-
send_node.receiver.nil?
|
106
|
-
else
|
107
|
-
method[:receiver] == receiver_chain(send_node)
|
108
|
-
end
|
109
|
-
end
|
92
|
+
debugger_methods.include?(chained_method_name(send_node))
|
110
93
|
end
|
111
94
|
|
112
|
-
def
|
113
|
-
|
95
|
+
def chained_method_name(send_node)
|
96
|
+
chained_method_name = send_node.method_name.to_s
|
114
97
|
receiver = send_node.receiver
|
115
|
-
|
116
98
|
while receiver
|
117
|
-
name = receiver.send_type? ? receiver.method_name : receiver.const_name
|
118
|
-
|
99
|
+
name = receiver.send_type? ? receiver.method_name : receiver.const_name
|
100
|
+
chained_method_name = "#{name}.#{chained_method_name}"
|
119
101
|
receiver = receiver.receiver
|
120
102
|
end
|
121
|
-
|
122
|
-
receivers
|
103
|
+
chained_method_name
|
123
104
|
end
|
124
105
|
end
|
125
106
|
end
|