rubocop 0.75.0 → 0.76.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 +1 -1
- data/config/default.yml +53 -54
- data/lib/rubocop.rb +10 -9
- data/lib/rubocop/ast/builder.rb +1 -0
- data/lib/rubocop/ast/node.rb +4 -0
- data/lib/rubocop/ast/node/return_node.rb +24 -0
- data/lib/rubocop/cli.rb +7 -4
- data/lib/rubocop/comment_config.rb +2 -2
- data/lib/rubocop/config.rb +7 -0
- data/lib/rubocop/config_loader.rb +1 -1
- data/lib/rubocop/config_loader_resolver.rb +2 -1
- data/lib/rubocop/config_obsoletion.rb +9 -0
- data/lib/rubocop/config_validator.rb +24 -15
- data/lib/rubocop/cop/commissioner.rb +15 -7
- data/lib/rubocop/cop/cop.rb +10 -6
- data/lib/rubocop/cop/corrector.rb +8 -7
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/layout/align_hash.rb +6 -2
- data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
- data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +22 -7
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +2 -2
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +2 -2
- data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
- data/lib/rubocop/cop/layout/indent_assignment.rb +2 -1
- data/lib/rubocop/cop/layout/indent_first_argument.rb +9 -7
- data/lib/rubocop/cop/layout/indent_first_hash_element.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -4
- data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
- data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +23 -23
- data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +6 -8
- data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
- data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +5 -5
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
- data/lib/rubocop/cop/lint/unused_block_argument.rb +22 -6
- data/lib/rubocop/cop/lint/unused_method_argument.rb +23 -5
- data/lib/rubocop/cop/lint/void.rb +7 -26
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/line_length.rb +1 -4
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
- data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +5 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -6
- data/lib/rubocop/cop/naming/file_name.rb +12 -5
- data/lib/rubocop/cop/registry.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +2 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +6 -6
- data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
- data/lib/rubocop/cop/style/copyright.rb +11 -7
- data/lib/rubocop/cop/style/documentation_method.rb +44 -0
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +2 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +2 -2
- data/lib/rubocop/cop/style/empty_method.rb +5 -5
- data/lib/rubocop/cop/style/expand_path_arguments.rb +1 -1
- data/lib/rubocop/cop/style/format_string.rb +10 -7
- data/lib/rubocop/cop/style/format_string_token.rb +15 -34
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +10 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +9 -2
- data/lib/rubocop/cop/style/infinite_loop.rb +4 -3
- data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
- data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +20 -20
- data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
- data/lib/rubocop/cop/style/multiline_when_then.rb +1 -1
- data/lib/rubocop/cop/style/nested_modifier.rb +4 -2
- data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
- data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
- data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
- data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
- data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +37 -21
- data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +4 -4
- data/lib/rubocop/cop/style/safe_navigation.rb +19 -8
- data/lib/rubocop/cop/style/semicolon.rb +13 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/utils/format_string.rb +10 -18
- data/lib/rubocop/cop/variable_force.rb +7 -5
- data/lib/rubocop/formatter/clang_style_formatter.rb +8 -3
- data/lib/rubocop/formatter/emacs_style_formatter.rb +22 -12
- data/lib/rubocop/formatter/file_list_formatter.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +16 -16
- data/lib/rubocop/formatter/pacman_formatter.rb +3 -3
- data/lib/rubocop/formatter/simple_text_formatter.rb +7 -3
- data/lib/rubocop/formatter/tap_formatter.rb +8 -3
- data/lib/rubocop/node_pattern.rb +3 -1
- data/lib/rubocop/options.rb +16 -22
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/runner.rb +32 -27
- data/lib/rubocop/target_finder.rb +12 -6
- data/lib/rubocop/version.rb +1 -1
- metadata +12 -11
@@ -73,11 +73,11 @@ module RuboCop
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def corrected(node)
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
scope
|
76
|
+
if node.arguments?
|
77
|
+
arguments = node.arguments.source
|
78
|
+
extra_space = ' ' unless parentheses?(node.arguments)
|
79
|
+
end
|
80
|
+
scope = node.receiver ? "#{node.receiver.source}." : ''
|
81
81
|
|
82
82
|
signature = [scope, node.method_name, extra_space, arguments].join
|
83
83
|
|
@@ -94,10 +94,12 @@ module RuboCop
|
|
94
94
|
private
|
95
95
|
|
96
96
|
def autocorrect_from_percent(corrector, node)
|
97
|
-
|
98
|
-
|
97
|
+
percent_rhs = node.first_argument
|
98
|
+
args = case percent_rhs.type
|
99
|
+
when :array, :hash
|
100
|
+
percent_rhs.children.map(&:source).join(', ')
|
99
101
|
else
|
100
|
-
|
102
|
+
percent_rhs.source
|
101
103
|
end
|
102
104
|
|
103
105
|
corrected = "#{style}(#{node.receiver.source}, #{args})"
|
@@ -106,14 +108,15 @@ module RuboCop
|
|
106
108
|
end
|
107
109
|
|
108
110
|
def autocorrect_to_percent(corrector, node)
|
109
|
-
|
111
|
+
format_arg, *param_args = node.arguments
|
112
|
+
format = format_arg.source
|
110
113
|
|
111
|
-
args = if
|
112
|
-
arg =
|
114
|
+
args = if param_args.one?
|
115
|
+
arg = param_args.last
|
113
116
|
|
114
117
|
arg.hash_type? ? "{ #{arg.source} }" : arg.source
|
115
118
|
else
|
116
|
-
"[#{
|
119
|
+
"[#{param_args.map(&:source).join(', ')}]"
|
117
120
|
end
|
118
121
|
|
119
122
|
corrector.replace(node.loc.expression, "#{format} % #{args}")
|
@@ -8,7 +8,7 @@ module RuboCop
|
|
8
8
|
# **Note:**
|
9
9
|
# `unannotated` style cop only works for strings
|
10
10
|
# which are passed as arguments to those methods:
|
11
|
-
# `sprintf`, `format`, `%`.
|
11
|
+
# `printf`, `sprintf`, `format`, `%`.
|
12
12
|
# The reason is that *unannotated* format is very similar
|
13
13
|
# to encoded URLs or Date/Time formatting strings.
|
14
14
|
#
|
@@ -41,10 +41,7 @@ module RuboCop
|
|
41
41
|
class FormatStringToken < Cop
|
42
42
|
include ConfigurableEnforcedStyle
|
43
43
|
|
44
|
-
FORMAT_STRING_METHODS = %i[sprintf format %].freeze
|
45
|
-
|
46
44
|
def on_str(node)
|
47
|
-
return if placeholder_argument?(node)
|
48
45
|
return if node.each_ancestor(:xstr, :regexp).any?
|
49
46
|
|
50
47
|
tokens(node) do |detected_style, token_range|
|
@@ -61,14 +58,16 @@ module RuboCop
|
|
61
58
|
|
62
59
|
private
|
63
60
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
def_node_matcher :format_string_in_typical_context?, <<~PATTERN
|
62
|
+
{
|
63
|
+
^(send _ {:format :sprintf :printf} %0 ...)
|
64
|
+
^(send %0 :% _)
|
65
|
+
}
|
66
|
+
PATTERN
|
69
67
|
|
70
68
|
def unannotated_format?(node, detected_style)
|
71
|
-
detected_style == :unannotated &&
|
69
|
+
detected_style == :unannotated &&
|
70
|
+
!format_string_in_typical_context?(node)
|
72
71
|
end
|
73
72
|
|
74
73
|
def message(detected_style)
|
@@ -95,11 +94,7 @@ module RuboCop
|
|
95
94
|
if source_map.is_a?(Parser::Source::Map::Heredoc)
|
96
95
|
source_map.heredoc_body
|
97
96
|
elsif source_map.begin
|
98
|
-
|
99
|
-
source_map.expression,
|
100
|
-
source_map.expression.begin_pos + 1,
|
101
|
-
source_map.expression.end_pos - 1
|
102
|
-
)
|
97
|
+
source_map.expression.adjust(begin_pos: +1, end_pos: -1)
|
103
98
|
else
|
104
99
|
source_map.expression
|
105
100
|
end
|
@@ -109,31 +104,17 @@ module RuboCop
|
|
109
104
|
format_string = RuboCop::Cop::Utils::FormatString.new(contents.source)
|
110
105
|
|
111
106
|
format_string.format_sequences.each do |seq|
|
107
|
+
next if seq.percent?
|
108
|
+
|
112
109
|
detected_style = seq.style
|
113
|
-
token =
|
114
|
-
|
115
|
-
|
116
|
-
contents.begin_pos + seq.end_pos
|
110
|
+
token = contents.begin.adjust(
|
111
|
+
begin_pos: seq.begin_pos,
|
112
|
+
end_pos: seq.end_pos
|
117
113
|
)
|
118
114
|
|
119
115
|
yield(detected_style, token)
|
120
116
|
end
|
121
117
|
end
|
122
|
-
|
123
|
-
def slice_source(source_range, new_begin, new_end)
|
124
|
-
Parser::Source::Range.new(
|
125
|
-
source_range.source_buffer,
|
126
|
-
new_begin,
|
127
|
-
new_end
|
128
|
-
)
|
129
|
-
end
|
130
|
-
|
131
|
-
def placeholder_argument?(node)
|
132
|
-
return false unless node.parent
|
133
|
-
return true if node.parent.pair_type?
|
134
|
-
|
135
|
-
placeholder_argument?(node.parent)
|
136
|
-
end
|
137
118
|
end
|
138
119
|
end
|
139
120
|
end
|
@@ -11,6 +11,9 @@ module RuboCop
|
|
11
11
|
# encoding comment. The frozen string literal comment is only valid in
|
12
12
|
# Ruby 2.3+.
|
13
13
|
#
|
14
|
+
# Note that the cop will ignore files where the comment exists but is set
|
15
|
+
# to `false` instead of `true`.
|
16
|
+
#
|
14
17
|
# @example EnforcedStyle: always (default)
|
15
18
|
# # The `always` style will always add the frozen string literal comment
|
16
19
|
# # to a file, regardless of the Ruby version or if `freeze` or `<<` are
|
@@ -27,6 +30,13 @@ module RuboCop
|
|
27
30
|
# # ...
|
28
31
|
# end
|
29
32
|
#
|
33
|
+
# # good
|
34
|
+
# # frozen_string_literal: false
|
35
|
+
#
|
36
|
+
# module Bar
|
37
|
+
# # ...
|
38
|
+
# end
|
39
|
+
#
|
30
40
|
# @example EnforcedStyle: never
|
31
41
|
# # The `never` will enforce that the frozen string literal comment does
|
32
42
|
# # not exist in a file.
|
@@ -168,10 +168,10 @@ module RuboCop
|
|
168
168
|
end
|
169
169
|
|
170
170
|
def autocorrect_ruby19(corrector, pair_node)
|
171
|
-
key = pair_node.key
|
171
|
+
key = pair_node.key.source_range
|
172
172
|
op = pair_node.loc.operator
|
173
173
|
|
174
|
-
range =
|
174
|
+
range = key.join(op)
|
175
175
|
range = range_with_surrounding_space(range: range, side: :right)
|
176
176
|
|
177
177
|
space = argument_without_space?(pair_node.parent) ? ' ' : ''
|
@@ -70,8 +70,15 @@ module RuboCop
|
|
70
70
|
return false unless max_line_length
|
71
71
|
|
72
72
|
range = node.source_range
|
73
|
-
range.first_line == range.last_line
|
74
|
-
|
73
|
+
return false unless range.first_line == range.last_line
|
74
|
+
return false unless line_length_enabled_at_line?(range.first_line)
|
75
|
+
|
76
|
+
range.last_column > max_line_length
|
77
|
+
end
|
78
|
+
|
79
|
+
def line_length_enabled_at_line?(line)
|
80
|
+
processed_source.comment_config
|
81
|
+
.cop_enabled_at_line?('Metrics/LineLength', line)
|
75
82
|
end
|
76
83
|
|
77
84
|
def named_capture_in_condition?(node)
|
@@ -97,12 +97,13 @@ module RuboCop
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def modifier_replacement(node)
|
100
|
+
body = node.body
|
100
101
|
if node.single_line?
|
101
|
-
'loop { ' +
|
102
|
+
'loop { ' + body.source + ' }'
|
102
103
|
else
|
103
|
-
indentation =
|
104
|
+
indentation = body.source_range.source_line[LEADING_SPACE]
|
104
105
|
|
105
|
-
['loop do',
|
106
|
+
['loop do', body.source.gsub(/^/, configured_indent),
|
106
107
|
'end'].join("\n#{indentation}")
|
107
108
|
end
|
108
109
|
end
|
@@ -94,20 +94,25 @@ module RuboCop
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def autocorrect(node)
|
97
|
+
if node.block_type?
|
98
|
+
correct_inverse_block(node)
|
99
|
+
elsif node.send_type?
|
100
|
+
correct_inverse_method(node)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def correct_inverse_method(node)
|
97
105
|
method_call, _lhs, method, _rhs = inverse_candidate?(node)
|
106
|
+
return unless method_call && method
|
98
107
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
inverse_methods[method].to_s)
|
108
|
+
lambda do |corrector|
|
109
|
+
corrector.remove(not_to_receiver(node, method_call))
|
110
|
+
corrector.replace(method_call.loc.selector,
|
111
|
+
inverse_methods[method].to_s)
|
104
112
|
|
105
|
-
|
106
|
-
|
107
|
-
end
|
113
|
+
if EQUALITY_METHODS.include?(method)
|
114
|
+
corrector.remove(end_parentheses(node, method_call))
|
108
115
|
end
|
109
|
-
else
|
110
|
-
correct_inverse_block(node)
|
111
116
|
end
|
112
117
|
end
|
113
118
|
|
@@ -122,18 +127,19 @@ module RuboCop
|
|
122
127
|
end
|
123
128
|
|
124
129
|
def correct_inverse_selector(block, corrector)
|
125
|
-
|
130
|
+
selector_loc = block.loc.selector
|
131
|
+
selector = selector_loc.source
|
126
132
|
|
127
133
|
if NEGATED_EQUALITY_METHODS.include?(selector.to_sym)
|
128
134
|
selector[0] = '='
|
129
|
-
corrector.replace(
|
135
|
+
corrector.replace(selector_loc, selector)
|
130
136
|
else
|
131
137
|
if block.loc.dot
|
132
138
|
range = dot_range(block.loc)
|
133
139
|
corrector.remove(range)
|
134
140
|
end
|
135
141
|
|
136
|
-
corrector.remove(
|
142
|
+
corrector.remove(selector_loc)
|
137
143
|
end
|
138
144
|
end
|
139
145
|
|
@@ -26,13 +26,14 @@ module RuboCop
|
|
26
26
|
'those strings.'
|
27
27
|
CONCAT_TOKEN_TYPES = %i[tPLUS tLSHFT].freeze
|
28
28
|
SIMPLE_STRING_TOKEN_TYPE = :tSTRING
|
29
|
-
|
29
|
+
COMPLEX_STRING_BEGIN_TOKEN = :tSTRING_BEG
|
30
|
+
COMPLEX_STRING_END_TOKEN = :tSTRING_END
|
30
31
|
HIGH_PRECEDENCE_OP_TOKEN_TYPES = %i[tSTAR2 tPERCENT tDOT
|
31
32
|
tLBRACK2].freeze
|
32
33
|
QUOTE_DELIMITERS = %w[' "].freeze
|
33
34
|
|
34
35
|
def self.autocorrect_incompatible_with
|
35
|
-
[Style::
|
36
|
+
[Style::RedundantInterpolation]
|
36
37
|
end
|
37
38
|
|
38
39
|
def investigate(processed_source)
|
@@ -59,9 +60,7 @@ module RuboCop
|
|
59
60
|
def check_token_set(index)
|
60
61
|
predecessor, operator, successor = processed_source.tokens[index, 3]
|
61
62
|
|
62
|
-
return unless
|
63
|
-
eligible_operator?(operator) &&
|
64
|
-
eligible_predecessor?(predecessor)
|
63
|
+
return unless eligible_token_set?(predecessor, operator, successor)
|
65
64
|
|
66
65
|
return if operator.line == successor.line
|
67
66
|
|
@@ -72,6 +71,12 @@ module RuboCop
|
|
72
71
|
add_offense(operator.pos, location: operator.pos)
|
73
72
|
end
|
74
73
|
|
74
|
+
def eligible_token_set?(predecessor, operator, successor)
|
75
|
+
eligible_successor?(successor) &&
|
76
|
+
eligible_operator?(operator) &&
|
77
|
+
eligible_predecessor?(predecessor)
|
78
|
+
end
|
79
|
+
|
75
80
|
def eligible_successor?(successor)
|
76
81
|
successor && standard_string_literal?(successor)
|
77
82
|
end
|
@@ -91,13 +96,12 @@ module RuboCop
|
|
91
96
|
|
92
97
|
def token_after_last_string(successor, base_index)
|
93
98
|
index = base_index + 3
|
94
|
-
|
95
|
-
if successor.type == begin_token
|
99
|
+
if successor.type == COMPLEX_STRING_BEGIN_TOKEN
|
96
100
|
ends_to_find = 1
|
97
101
|
while ends_to_find.positive?
|
98
102
|
case processed_source.tokens[index].type
|
99
|
-
when
|
100
|
-
when
|
103
|
+
when COMPLEX_STRING_BEGIN_TOKEN then ends_to_find += 1
|
104
|
+
when COMPLEX_STRING_END_TOKEN then ends_to_find -= 1
|
101
105
|
end
|
102
106
|
index += 1
|
103
107
|
end
|
@@ -109,7 +113,7 @@ module RuboCop
|
|
109
113
|
case token.type
|
110
114
|
when SIMPLE_STRING_TOKEN_TYPE
|
111
115
|
true
|
112
|
-
when
|
116
|
+
when COMPLEX_STRING_BEGIN_TOKEN, COMPLEX_STRING_END_TOKEN
|
113
117
|
QUOTE_DELIMITERS.include?(token.text)
|
114
118
|
else
|
115
119
|
false
|
@@ -64,20 +64,6 @@ module RuboCop
|
|
64
64
|
# # okay with `^assert` listed in `IgnoredPatterns`
|
65
65
|
# assert_equal 'test', x
|
66
66
|
#
|
67
|
-
# # IgnoreMacros: true (default)
|
68
|
-
#
|
69
|
-
# # good
|
70
|
-
# class Foo
|
71
|
-
# bar :baz
|
72
|
-
# end
|
73
|
-
#
|
74
|
-
# # IgnoreMacros: false
|
75
|
-
#
|
76
|
-
# # bad
|
77
|
-
# class Foo
|
78
|
-
# bar :baz
|
79
|
-
# end
|
80
|
-
#
|
81
67
|
# @example EnforcedStyle: omit_parentheses
|
82
68
|
#
|
83
69
|
# # bad
|
@@ -92,7 +78,21 @@ module RuboCop
|
|
92
78
|
# # good
|
93
79
|
# foo.enforce strict: true
|
94
80
|
#
|
95
|
-
#
|
81
|
+
# @example IgnoreMacros: true (default)
|
82
|
+
#
|
83
|
+
# # good
|
84
|
+
# class Foo
|
85
|
+
# bar :baz
|
86
|
+
# end
|
87
|
+
#
|
88
|
+
# @example IgnoreMacros: false
|
89
|
+
#
|
90
|
+
# # bad
|
91
|
+
# class Foo
|
92
|
+
# bar :baz
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# @example AllowParenthesesInMultilineCall: false (default)
|
96
96
|
#
|
97
97
|
# # bad
|
98
98
|
# foo.enforce(
|
@@ -103,7 +103,7 @@ module RuboCop
|
|
103
103
|
# foo.enforce \
|
104
104
|
# strict: true
|
105
105
|
#
|
106
|
-
#
|
106
|
+
# @example AllowParenthesesInMultilineCall: true
|
107
107
|
#
|
108
108
|
# # good
|
109
109
|
# foo.enforce(
|
@@ -114,7 +114,7 @@ module RuboCop
|
|
114
114
|
# foo.enforce \
|
115
115
|
# strict: true
|
116
116
|
#
|
117
|
-
#
|
117
|
+
# @example AllowParenthesesInChaining: false (default)
|
118
118
|
#
|
119
119
|
# # bad
|
120
120
|
# foo().bar(1)
|
@@ -122,7 +122,7 @@ module RuboCop
|
|
122
122
|
# # good
|
123
123
|
# foo().bar 1
|
124
124
|
#
|
125
|
-
#
|
125
|
+
# @example AllowParenthesesInChaining: true
|
126
126
|
#
|
127
127
|
# # good
|
128
128
|
# foo().bar(1)
|
@@ -130,7 +130,7 @@ module RuboCop
|
|
130
130
|
# # good
|
131
131
|
# foo().bar 1
|
132
132
|
#
|
133
|
-
#
|
133
|
+
# @example AllowParenthesesInCamelCaseMethod: false (default)
|
134
134
|
#
|
135
135
|
# # bad
|
136
136
|
# Array(1)
|
@@ -138,7 +138,7 @@ module RuboCop
|
|
138
138
|
# # good
|
139
139
|
# Array 1
|
140
140
|
#
|
141
|
-
#
|
141
|
+
# @example AllowParenthesesInCamelCaseMethod: true
|
142
142
|
#
|
143
143
|
# # good
|
144
144
|
# Array(1)
|
@@ -113,22 +113,30 @@ module RuboCop
|
|
113
113
|
lambda do |corrector|
|
114
114
|
if node.args_type?
|
115
115
|
# offense is registered on args node when parentheses are unwanted
|
116
|
-
|
117
|
-
corrector.remove(node.loc.end)
|
116
|
+
correct_arguments(node, corrector)
|
118
117
|
else
|
119
|
-
|
120
|
-
args_with_space = range_with_surrounding_space(range: args_expr,
|
121
|
-
side: :left)
|
122
|
-
just_space = range_between(args_with_space.begin_pos,
|
123
|
-
args_expr.begin_pos)
|
124
|
-
corrector.replace(just_space, '(')
|
125
|
-
corrector.insert_after(args_expr, ')')
|
118
|
+
correct_definition(node, corrector)
|
126
119
|
end
|
127
120
|
end
|
128
121
|
end
|
129
122
|
|
130
123
|
private
|
131
124
|
|
125
|
+
def correct_arguments(arg_node, corrector)
|
126
|
+
corrector.replace(arg_node.loc.begin, ' ')
|
127
|
+
corrector.remove(arg_node.loc.end)
|
128
|
+
end
|
129
|
+
|
130
|
+
def correct_definition(def_node, corrector)
|
131
|
+
arguments_range = def_node.arguments.source_range
|
132
|
+
args_with_space = range_with_surrounding_space(range: arguments_range,
|
133
|
+
side: :left)
|
134
|
+
leading_space = range_between(args_with_space.begin_pos,
|
135
|
+
arguments_range.begin_pos)
|
136
|
+
corrector.replace(leading_space, '(')
|
137
|
+
corrector.insert_after(arguments_range, ')')
|
138
|
+
end
|
139
|
+
|
132
140
|
def require_parentheses?(args)
|
133
141
|
style == :require_parentheses ||
|
134
142
|
(style == :require_no_parentheses_except_multiline &&
|