rubocop 1.48.0 → 1.50.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +22 -7
- data/lib/rubocop/cli/command/execute_runner.rb +7 -2
- data/lib/rubocop/cli.rb +6 -6
- data/lib/rubocop/config.rb +3 -3
- data/lib/rubocop/config_loader.rb +8 -8
- data/lib/rubocop/cop/autocorrect_logic.rb +28 -12
- data/lib/rubocop/cop/cop.rb +2 -2
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/gemspec/dependency_version.rb +1 -1
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +29 -2
- data/lib/rubocop/cop/layout/block_end_newline.rb +7 -21
- data/lib/rubocop/cop/layout/class_structure.rb +1 -0
- data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -0
- data/lib/rubocop/cop/layout/end_alignment.rb +5 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +6 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -1
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +25 -34
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +7 -19
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +42 -52
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +38 -55
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
- data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +8 -27
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +7 -26
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +4 -21
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +6 -30
- data/lib/rubocop/cop/layout/redundant_line_break.rb +6 -7
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_parens.rb +2 -2
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +3 -3
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +122 -0
- data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +35 -15
- data/lib/rubocop/cop/lint/syntax.rb +4 -0
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +7 -1
- data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -3
- data/lib/rubocop/cop/lint/useless_method_definition.rb +10 -2
- data/lib/rubocop/cop/lint/useless_rescue.rb +4 -1
- data/lib/rubocop/cop/lint/void.rb +7 -3
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
- data/lib/rubocop/cop/metrics/class_length.rb +1 -0
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +1 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -1
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +23 -4
- data/lib/rubocop/cop/naming/method_name.rb +2 -2
- data/lib/rubocop/cop/style/accessor_grouping.rb +4 -4
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/class_equality_comparison.rb +42 -9
- data/lib/rubocop/cop/style/collection_compact.rb +3 -0
- data/lib/rubocop/cop/style/copyright.rb +1 -1
- data/lib/rubocop/cop/style/data_inheritance.rb +75 -0
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +2 -2
- data/lib/rubocop/cop/style/file_empty.rb +3 -3
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/hash_except.rb +4 -4
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +38 -12
- data/lib/rubocop/cop/style/map_to_hash.rb +4 -1
- data/lib/rubocop/cop/style/map_to_set.rb +4 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +3 -7
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +43 -36
- data/lib/rubocop/cop/style/multiline_method_signature.rb +6 -3
- data/lib/rubocop/cop/style/parallel_assignment.rb +26 -18
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -3
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +6 -4
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +179 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
- data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -3
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +2 -2
- data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
- data/lib/rubocop/cop/style/trailing_body_on_class.rb +1 -0
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_logical_operators.rb +1 -0
- data/lib/rubocop/cops_documentation_generator.rb +10 -3
- data/lib/rubocop/ext/regexp_node.rb +1 -1
- data/lib/rubocop/ext/regexp_parser.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
- data/lib/rubocop/options.rb +4 -1
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/rspec/support.rb +1 -0
- data/lib/rubocop/server/cache.rb +1 -1
- data/lib/rubocop/server/helper.rb +1 -1
- data/lib/rubocop/server/server_command/exec.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +3 -0
- metadata +12 -9
@@ -31,22 +31,26 @@ module RuboCop
|
|
31
31
|
def on_masgn(node)
|
32
32
|
lhs, rhs = *node
|
33
33
|
lhs_elements = *lhs
|
34
|
+
rhs = rhs.body if rhs.rescue_type?
|
34
35
|
rhs_elements = Array(rhs).compact # edge case for one constant
|
35
36
|
|
36
37
|
return if allowed_lhs?(lhs) || allowed_rhs?(rhs) ||
|
37
38
|
allowed_masign?(lhs_elements, rhs_elements)
|
38
39
|
|
39
|
-
|
40
|
+
range = node.source_range.begin.join(rhs.source_range.end)
|
41
|
+
|
42
|
+
add_offense(range) do |corrector|
|
43
|
+
autocorrect(corrector, node, lhs, rhs)
|
44
|
+
end
|
40
45
|
end
|
41
46
|
|
42
47
|
private
|
43
48
|
|
44
|
-
def autocorrect(corrector, node)
|
45
|
-
|
46
|
-
|
47
|
-
right_elements = Array(right).compact
|
49
|
+
def autocorrect(corrector, node, lhs, rhs)
|
50
|
+
left_elements = *lhs
|
51
|
+
right_elements = Array(rhs).compact
|
48
52
|
order = find_valid_order(left_elements, right_elements)
|
49
|
-
correction = assignment_corrector(node, order)
|
53
|
+
correction = assignment_corrector(node, rhs, order)
|
50
54
|
|
51
55
|
corrector.replace(correction.correction_range, correction.correction)
|
52
56
|
end
|
@@ -77,14 +81,19 @@ module RuboCop
|
|
77
81
|
node.block_type? || node.send_type?
|
78
82
|
end
|
79
83
|
|
80
|
-
def assignment_corrector(node, order)
|
81
|
-
|
84
|
+
def assignment_corrector(node, rhs, order)
|
85
|
+
if node.parent&.rescue_type?
|
86
|
+
_assignment, modifier = *node.parent
|
87
|
+
else
|
88
|
+
_assignment, modifier = *rhs.parent
|
89
|
+
end
|
90
|
+
|
82
91
|
if modifier_statement?(node.parent)
|
83
|
-
ModifierCorrector.new(node, config, order)
|
92
|
+
ModifierCorrector.new(node, rhs, modifier, config, order)
|
84
93
|
elsif rescue_modifier?(modifier)
|
85
|
-
RescueCorrector.new(node, config, order)
|
94
|
+
RescueCorrector.new(node, rhs, modifier, config, order)
|
86
95
|
else
|
87
|
-
GenericCorrector.new(node, config, order)
|
96
|
+
GenericCorrector.new(node, rhs, modifier, config, order)
|
88
97
|
end
|
89
98
|
end
|
90
99
|
|
@@ -181,10 +190,12 @@ module RuboCop
|
|
181
190
|
class GenericCorrector
|
182
191
|
include Alignment
|
183
192
|
|
184
|
-
attr_reader :
|
193
|
+
attr_reader :node, :rhs, :rescue_result, :config
|
185
194
|
|
186
|
-
def initialize(node, config, new_elements)
|
195
|
+
def initialize(node, rhs, modifier, config, new_elements)
|
187
196
|
@node = node
|
197
|
+
@rhs = rhs
|
198
|
+
_, _, @rescue_result = *modifier
|
188
199
|
@config = config
|
189
200
|
@new_elements = new_elements
|
190
201
|
end
|
@@ -228,13 +239,10 @@ module RuboCop
|
|
228
239
|
# protected by rescue
|
229
240
|
class RescueCorrector < GenericCorrector
|
230
241
|
def correction
|
231
|
-
_node, rescue_clause = *node.parent
|
232
|
-
_, _, rescue_result = *rescue_clause
|
233
|
-
|
234
242
|
# If the parallel assignment uses a rescue modifier and it is the
|
235
243
|
# only contents of a method, then we want to make use of the
|
236
244
|
# implicit begin
|
237
|
-
if
|
245
|
+
if rhs.parent.parent.parent&.def_type?
|
238
246
|
super + def_correction(rescue_result)
|
239
247
|
else
|
240
248
|
begin_correction(rescue_result)
|
@@ -242,7 +250,7 @@ module RuboCop
|
|
242
250
|
end
|
243
251
|
|
244
252
|
def correction_range
|
245
|
-
|
253
|
+
rhs.parent.parent.source_range
|
246
254
|
end
|
247
255
|
|
248
256
|
private
|
@@ -92,9 +92,8 @@ module RuboCop
|
|
92
92
|
|
93
93
|
def contains_delimiter?(node, delimiters)
|
94
94
|
delimiters_regexp = Regexp.union(delimiters)
|
95
|
-
|
96
|
-
|
97
|
-
.any? { |s| delimiters_regexp.match?(s) }
|
95
|
+
|
96
|
+
node.children.map { |n| string_source(n) }.compact.any?(delimiters_regexp)
|
98
97
|
end
|
99
98
|
|
100
99
|
def string_source(node)
|
@@ -44,7 +44,7 @@ module RuboCop
|
|
44
44
|
|
45
45
|
# Report offense only if changing case doesn't change semantics,
|
46
46
|
# i.e., if the string would become dynamic or has special characters.
|
47
|
-
ast =
|
47
|
+
ast = parse(corrected(node.source)).ast
|
48
48
|
return if node.children != ast.children
|
49
49
|
|
50
50
|
add_offense(node.loc.begin) do |corrector|
|
@@ -3,11 +3,13 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
# Identifies places where `fetch(key) { value }`
|
7
|
-
# can be replaced by `fetch(key, value)`.
|
6
|
+
# Identifies places where `fetch(key) { value }` can be replaced by `fetch(key, value)`.
|
8
7
|
#
|
9
|
-
# In such cases `fetch(key, value)` method is faster
|
10
|
-
#
|
8
|
+
# In such cases `fetch(key, value)` method is faster than `fetch(key) { value }`.
|
9
|
+
#
|
10
|
+
# NOTE: The block string `'value'` in `hash.fetch(:key) { 'value' }` is detected
|
11
|
+
# when frozen string literal magic comment is enabled (i.e. `# frozen_string_literal: true`),
|
12
|
+
# but not when disabled.
|
11
13
|
#
|
12
14
|
# @safety
|
13
15
|
# This cop is unsafe because it cannot be guaranteed that the receiver
|
@@ -0,0 +1,179 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# Check for redundant line continuation.
|
7
|
+
#
|
8
|
+
# This cop marks a line continuation as redundant if removing the backslash
|
9
|
+
# does not result in a syntax error.
|
10
|
+
# However, a backslash at the end of a comment or
|
11
|
+
# for string concatenation is not redundant and is not considered an offense.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# # bad
|
15
|
+
# foo. \
|
16
|
+
# bar
|
17
|
+
# foo \
|
18
|
+
# &.bar \
|
19
|
+
# .baz
|
20
|
+
#
|
21
|
+
# # good
|
22
|
+
# foo.
|
23
|
+
# bar
|
24
|
+
# foo
|
25
|
+
# &.bar
|
26
|
+
# .baz
|
27
|
+
#
|
28
|
+
# # bad
|
29
|
+
# [foo, \
|
30
|
+
# bar]
|
31
|
+
# {foo: \
|
32
|
+
# bar}
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
# [foo,
|
36
|
+
# bar]
|
37
|
+
# {foo:
|
38
|
+
# bar}
|
39
|
+
#
|
40
|
+
# # bad
|
41
|
+
# foo(bar, \
|
42
|
+
# baz)
|
43
|
+
#
|
44
|
+
# # good
|
45
|
+
# foo(bar,
|
46
|
+
# baz)
|
47
|
+
#
|
48
|
+
# # also good - backslash in string concatenation is not redundant
|
49
|
+
# foo('bar' \
|
50
|
+
# 'baz')
|
51
|
+
#
|
52
|
+
# # also good - backslash at the end of a comment is not redundant
|
53
|
+
# foo(bar, # \
|
54
|
+
# baz)
|
55
|
+
#
|
56
|
+
# # also good - backslash at the line following the newline begins with a + or -,
|
57
|
+
# # it is not redundant
|
58
|
+
# 1 \
|
59
|
+
# + 2 \
|
60
|
+
# - 3
|
61
|
+
#
|
62
|
+
# # also good - backslash with newline between the method name and its arguments,
|
63
|
+
# # it is not redundant.
|
64
|
+
# some_method \
|
65
|
+
# (argument)
|
66
|
+
#
|
67
|
+
class RedundantLineContinuation < Base
|
68
|
+
include MatchRange
|
69
|
+
extend AutoCorrector
|
70
|
+
|
71
|
+
MSG = 'Redundant line continuation.'
|
72
|
+
ALLOWED_STRING_TOKENS = %i[tSTRING tSTRING_CONTENT].freeze
|
73
|
+
|
74
|
+
def on_new_investigation
|
75
|
+
return unless processed_source.ast
|
76
|
+
|
77
|
+
each_match_range(processed_source.ast.source_range, /(\\\n)/) do |range|
|
78
|
+
next if require_line_continuation?(range)
|
79
|
+
next unless redundant_line_continuation?(range)
|
80
|
+
|
81
|
+
add_offense(range) do |corrector|
|
82
|
+
corrector.remove_leading(range, 1)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def require_line_continuation?(range)
|
90
|
+
!ends_with_backslash_without_comment?(range.source_line) ||
|
91
|
+
string_concatenation?(range.source_line) ||
|
92
|
+
start_with_arithmetic_operator?(processed_source[range.line]) ||
|
93
|
+
inside_string_literal_or_method_with_argument?(range)
|
94
|
+
end
|
95
|
+
|
96
|
+
def ends_with_backslash_without_comment?(source_line)
|
97
|
+
source_line.gsub(/#.+/, '').end_with?('\\')
|
98
|
+
end
|
99
|
+
|
100
|
+
def string_concatenation?(source_line)
|
101
|
+
/["']\s*\\\z/.match?(source_line)
|
102
|
+
end
|
103
|
+
|
104
|
+
def inside_string_literal_or_method_with_argument?(range)
|
105
|
+
processed_source.tokens.each_cons(2).any? do |token, next_token|
|
106
|
+
inside_string_literal?(range, token) || method_with_argument?(token, next_token)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def redundant_line_continuation?(range)
|
111
|
+
return true unless (node = find_node_for_line(range.line))
|
112
|
+
return false if argument_newline?(node)
|
113
|
+
|
114
|
+
source = node.parent ? node.parent.source : node.source
|
115
|
+
parse(source.gsub(/\\\n/, "\n")).valid_syntax?
|
116
|
+
end
|
117
|
+
|
118
|
+
def inside_string_literal?(range, token)
|
119
|
+
ALLOWED_STRING_TOKENS.include?(token.type) && token.pos.overlaps?(range)
|
120
|
+
end
|
121
|
+
|
122
|
+
# A method call without parentheses such as the following cannot remove `\`:
|
123
|
+
#
|
124
|
+
# do_something \
|
125
|
+
# argument
|
126
|
+
def method_with_argument?(current_token, next_token)
|
127
|
+
current_token.type == :tIDENTIFIER && next_token.type == :tIDENTIFIER
|
128
|
+
end
|
129
|
+
|
130
|
+
def argument_newline?(node)
|
131
|
+
node = node.children.first if node.root? && node.begin_type?
|
132
|
+
|
133
|
+
if argument_is_method?(node)
|
134
|
+
argument_newline?(node.first_argument)
|
135
|
+
else
|
136
|
+
return false unless method_call_with_arguments?(node)
|
137
|
+
|
138
|
+
node.loc.selector.line != node.first_argument.loc.line
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def find_node_for_line(line)
|
143
|
+
processed_source.ast.each_node do |node|
|
144
|
+
return node if same_line?(node, line)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def same_line?(node, line)
|
149
|
+
return unless (source_range = node.source_range)
|
150
|
+
|
151
|
+
if node.is_a?(AST::StrNode)
|
152
|
+
if node.heredoc?
|
153
|
+
(node.loc.heredoc_body.line..node.loc.heredoc_body.last_line).cover?(line)
|
154
|
+
else
|
155
|
+
(source_range.line..source_range.last_line).cover?(line)
|
156
|
+
end
|
157
|
+
else
|
158
|
+
source_range.line == line
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def argument_is_method?(node)
|
163
|
+
return false unless node.send_type?
|
164
|
+
return false unless (first_argument = node.first_argument)
|
165
|
+
|
166
|
+
method_call_with_arguments?(first_argument)
|
167
|
+
end
|
168
|
+
|
169
|
+
def method_call_with_arguments?(node)
|
170
|
+
node.call_type? && !node.arguments.empty?
|
171
|
+
end
|
172
|
+
|
173
|
+
def start_with_arithmetic_operator?(source_line)
|
174
|
+
%r{\A\s*[+\-*/%]}.match?(source_line)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -98,7 +98,7 @@ module RuboCop
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def like_method_argument_parentheses?(node)
|
101
|
-
node.send_type? && node.arguments.one? &&
|
101
|
+
node.send_type? && node.arguments.one? && !node.parenthesized? &&
|
102
102
|
!node.arithmetic_operation? && node.first_argument.begin_type?
|
103
103
|
end
|
104
104
|
|
@@ -63,7 +63,7 @@ module RuboCop
|
|
63
63
|
next if expr.type != :set || expr.expressions.size != 1
|
64
64
|
next if expr.negative?
|
65
65
|
next if %i[set posixclass nonposixclass].include?(expr.expressions.first.type)
|
66
|
-
next if
|
66
|
+
next if multiple_codepoints?(expr.expressions.first)
|
67
67
|
|
68
68
|
yield expr
|
69
69
|
end
|
@@ -80,7 +80,7 @@ module RuboCop
|
|
80
80
|
!non_redundant
|
81
81
|
end
|
82
82
|
|
83
|
-
def
|
83
|
+
def multiple_codepoints?(expression)
|
84
84
|
expression.respond_to?(:codepoints) && expression.codepoints.count >= 2
|
85
85
|
end
|
86
86
|
|
@@ -107,7 +107,7 @@ module RuboCop
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
# Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
|
110
|
-
# It's for compatibility with
|
110
|
+
# It's for compatibility with regexp_parser 1.8 and will never be maintained.
|
111
111
|
else
|
112
112
|
def each_escape(node)
|
113
113
|
node.parsed_tree&.traverse&.reduce(0) do |char_class_depth, (event, expr)|
|
@@ -36,7 +36,6 @@ module RuboCop
|
|
36
36
|
# STR
|
37
37
|
class RedundantStringEscape < Base
|
38
38
|
include MatchRange
|
39
|
-
include RangeHelp
|
40
39
|
extend AutoCorrector
|
41
40
|
|
42
41
|
MSG = 'Redundant escape of %<char>s inside string literal.'
|
@@ -64,10 +63,10 @@ module RuboCop
|
|
64
63
|
def str_contents_range(node)
|
65
64
|
if heredoc?(node)
|
66
65
|
node.loc.heredoc_body
|
66
|
+
elsif node.str_type?
|
67
|
+
node.source_range
|
67
68
|
elsif begin_loc_present?(node)
|
68
69
|
contents_range(node)
|
69
|
-
else
|
70
|
-
node.source_range
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
@@ -167,7 +167,7 @@ module RuboCop
|
|
167
167
|
corrector.insert_before(condition,
|
168
168
|
"#{'!' if node.unless?}#{replace_condition(node.condition)} && ")
|
169
169
|
|
170
|
-
corrector.remove(node.condition
|
170
|
+
corrector.remove(node.condition)
|
171
171
|
corrector.remove(range_with_surrounding_space(node.loc.keyword, newlines: false))
|
172
172
|
corrector.replace(if_branch.loc.keyword, 'if')
|
173
173
|
end
|
@@ -187,7 +187,7 @@ module RuboCop
|
|
187
187
|
return if end_pos > begin_pos
|
188
188
|
|
189
189
|
corrector.replace(range_between(end_pos, begin_pos), '(')
|
190
|
-
corrector.insert_after(condition.last_argument
|
190
|
+
corrector.insert_after(condition.last_argument, ')')
|
191
191
|
end
|
192
192
|
|
193
193
|
def insert_bang(corrector, node, is_modify_form)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'fileutils'
|
4
|
+
|
3
5
|
# Class for generating documentation of all cops departments
|
4
6
|
# @api private
|
5
7
|
class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
@@ -14,6 +16,8 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
14
16
|
@departments = departments.map(&:to_sym).sort!
|
15
17
|
@cops = RuboCop::Cop::Registry.global
|
16
18
|
@config = RuboCop::ConfigLoader.default_configuration
|
19
|
+
@docs_path = "#{Dir.pwd}/docs/modules/ROOT/pages/"
|
20
|
+
FileUtils.mkdir_p(@docs_path)
|
17
21
|
end
|
18
22
|
|
19
23
|
def call
|
@@ -27,7 +31,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
27
31
|
|
28
32
|
private
|
29
33
|
|
30
|
-
attr_reader :departments, :cops, :config
|
34
|
+
attr_reader :departments, :cops, :config, :docs_path
|
31
35
|
|
32
36
|
def cops_of_department(department)
|
33
37
|
cops.with_department(department).sort!
|
@@ -252,7 +256,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
252
256
|
content = +"= #{department}\n"
|
253
257
|
selected_cops.each { |cop| content << print_cop_with_doc(cop) }
|
254
258
|
content << footer_for_department(department)
|
255
|
-
file_name = "#{
|
259
|
+
file_name = "#{docs_path}/#{department_to_basename(department)}.adoc"
|
256
260
|
File.open(file_name, 'w') do |file|
|
257
261
|
puts "* generated #{file_name}"
|
258
262
|
file.write("#{content.strip}\n")
|
@@ -298,7 +302,10 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
298
302
|
end
|
299
303
|
|
300
304
|
def print_table_of_contents
|
301
|
-
path = "#{
|
305
|
+
path = "#{docs_path}/cops.adoc"
|
306
|
+
|
307
|
+
File.write(path, table_contents) and return unless File.exist?(path)
|
308
|
+
|
302
309
|
original = File.read(path)
|
303
310
|
content = +"// START_COP_LIST\n\n"
|
304
311
|
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
@parsed_tree&.each_expression(true) { |e| e.origin = origin }
|
30
30
|
end
|
31
31
|
# Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
|
32
|
-
# It's for compatibility with
|
32
|
+
# It's for compatibility with regexp_parser 1.8 and will never be maintained.
|
33
33
|
else
|
34
34
|
def assign_properties(*)
|
35
35
|
super
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
@expression ||= origin.adjust(begin_pos: ts, end_pos: ts + full_length)
|
29
29
|
end
|
30
30
|
# Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
|
31
|
-
# It's for compatibility with
|
31
|
+
# It's for compatibility with regexp_parser 1.8 and will never be maintained.
|
32
32
|
else
|
33
33
|
attr_accessor :source
|
34
34
|
|
@@ -61,7 +61,7 @@ module RuboCop
|
|
61
61
|
correctable_count,
|
62
62
|
rainbow,
|
63
63
|
# :safe_autocorrect is a derived option based on several command-line
|
64
|
-
# arguments - see
|
64
|
+
# arguments - see RuboCop::Options#add_autocorrection_options
|
65
65
|
safe_autocorrect: @options[:safe_autocorrect])
|
66
66
|
|
67
67
|
output.puts
|
data/lib/rubocop/options.rb
CHANGED
@@ -182,7 +182,10 @@ module RuboCop
|
|
182
182
|
raise OptionArgumentError, message
|
183
183
|
end
|
184
184
|
|
185
|
-
|
185
|
+
cop_names = list.empty? ? [''] : list.split(',')
|
186
|
+
cop_names.unshift('Lint/Syntax') if option == 'only' && !cop_names.include?('Lint/Syntax')
|
187
|
+
|
188
|
+
@options[:"#{option}"] = cop_names
|
186
189
|
end
|
187
190
|
end
|
188
191
|
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -86,7 +86,7 @@ module RuboCop
|
|
86
86
|
attr :path
|
87
87
|
|
88
88
|
def initialize(file, team, options, config_store, cache_root = nil)
|
89
|
-
cache_root ||= options[:cache_root]
|
89
|
+
cache_root ||= File.join(options[:cache_root], 'rubocop_cache') if options[:cache_root]
|
90
90
|
cache_root ||= ResultCache.cache_root(config_store)
|
91
91
|
@allow_symlinks_in_cache_location =
|
92
92
|
ResultCache.allow_symlinks_in_cache_location?(config_store)
|
data/lib/rubocop/server/cache.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
module RuboCop
|
13
13
|
module Server
|
14
|
-
# This module has a helper
|
14
|
+
# This module has a helper method for `RuboCop::Server::SocketReader`.
|
15
15
|
# @api private
|
16
16
|
module Helper
|
17
17
|
def self.redirect(stdin: $stdin, stdout: $stdout, stderr: $stderr, &_block)
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
# We must pass the --color option to preserve this behavior.
|
22
22
|
@args.unshift('--color') unless %w[--color --no-color].any? { |f| @args.include?(f) }
|
23
23
|
status = RuboCop::CLI.new.run(@args)
|
24
|
-
# This status file is read by `rubocop --server` (`RuboCop::Server::
|
24
|
+
# This status file is read by `rubocop --server` (`RuboCop::Server::ClientCommand::Exec`).
|
25
25
|
# so that they use the correct exit code.
|
26
26
|
# Status is 1 when there are any issues, and 0 otherwise.
|
27
27
|
Cache.write_status_file(status)
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
@@ -299,6 +299,7 @@ require_relative 'rubocop/cop/lint/duplicate_case_condition'
|
|
299
299
|
require_relative 'rubocop/cop/lint/duplicate_elsif_condition'
|
300
300
|
require_relative 'rubocop/cop/lint/duplicate_hash_key'
|
301
301
|
require_relative 'rubocop/cop/lint/duplicate_magic_comment'
|
302
|
+
require_relative 'rubocop/cop/lint/duplicate_match_pattern'
|
302
303
|
require_relative 'rubocop/cop/lint/duplicate_methods'
|
303
304
|
require_relative 'rubocop/cop/lint/duplicate_regexp_character_class_element'
|
304
305
|
require_relative 'rubocop/cop/lint/duplicate_require'
|
@@ -480,6 +481,7 @@ require_relative 'rubocop/cop/style/concat_array_literals'
|
|
480
481
|
require_relative 'rubocop/cop/style/conditional_assignment'
|
481
482
|
require_relative 'rubocop/cop/style/constant_visibility'
|
482
483
|
require_relative 'rubocop/cop/style/copyright'
|
484
|
+
require_relative 'rubocop/cop/style/data_inheritance'
|
483
485
|
require_relative 'rubocop/cop/style/date_time'
|
484
486
|
require_relative 'rubocop/cop/style/def_with_parentheses'
|
485
487
|
require_relative 'rubocop/cop/style/dir'
|
@@ -563,6 +565,7 @@ require_relative 'rubocop/cop/style/redundant_fetch_block'
|
|
563
565
|
require_relative 'rubocop/cop/style/redundant_file_extension_in_require'
|
564
566
|
require_relative 'rubocop/cop/style/redundant_heredoc_delimiter_quotes'
|
565
567
|
require_relative 'rubocop/cop/style/redundant_initialize'
|
568
|
+
require_relative 'rubocop/cop/style/redundant_line_continuation'
|
566
569
|
require_relative 'rubocop/cop/style/redundant_self_assignment'
|
567
570
|
require_relative 'rubocop/cop/style/redundant_self_assignment_branch'
|
568
571
|
require_relative 'rubocop/cop/style/require_order'
|