rubocop 0.90.0 → 0.91.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/config/default.yml +35 -0
- data/lib/rubocop.rb +10 -1
- data/lib/rubocop/cli/command/execute_runner.rb +8 -0
- data/lib/rubocop/config_loader.rb +3 -3
- data/lib/rubocop/config_store.rb +3 -3
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +5 -1
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -0
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -0
- data/lib/rubocop/cop/generator.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -0
- data/lib/rubocop/cop/layout/begin_end_alignment.rb +77 -0
- data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +6 -5
- data/lib/rubocop/cop/layout/end_alignment.rb +5 -10
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +17 -4
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -3
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -6
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +2 -0
- data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -2
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +54 -0
- data/lib/rubocop/cop/lint/debugger.rb +2 -3
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -3
- data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -4
- data/lib/rubocop/cop/lint/duplicate_require.rb +7 -2
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
- data/lib/rubocop/cop/lint/empty_file.rb +1 -4
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +2 -0
- data/lib/rubocop/cop/lint/float_comparison.rb +2 -2
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +2 -2
- data/lib/rubocop/cop/lint/identity_comparison.rb +49 -0
- data/lib/rubocop/cop/lint/inherit_exception.rb +2 -2
- data/lib/rubocop/cop/lint/multiple_comparison.rb +3 -1
- data/lib/rubocop/cop/lint/number_conversion.rb +1 -0
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +1 -2
- data/lib/rubocop/cop/lint/raise_exception.rb +1 -0
- data/lib/rubocop/cop/lint/rand_one.rb +2 -1
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -0
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +3 -1
- data/lib/rubocop/cop/lint/struct_new_override.rb +1 -0
- data/lib/rubocop/cop/lint/to_json.rb +16 -5
- data/lib/rubocop/cop/lint/unreachable_loop.rb +2 -1
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +3 -1
- data/lib/rubocop/cop/lint/uri_regexp.rb +2 -1
- data/lib/rubocop/cop/lint/useless_method_definition.rb +20 -27
- data/lib/rubocop/cop/lint/useless_times.rb +97 -0
- data/lib/rubocop/cop/mixin/comments_help.rb +3 -9
- data/lib/rubocop/cop/mixin/configurable_naming.rb +2 -2
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +9 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +9 -1
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/file_name.rb +1 -1
- data/lib/rubocop/cop/security/eval.rb +1 -0
- data/lib/rubocop/cop/security/json_load.rb +1 -0
- data/lib/rubocop/cop/security/marshal_load.rb +1 -0
- data/lib/rubocop/cop/security/open.rb +1 -0
- data/lib/rubocop/cop/security/yaml_load.rb +1 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +3 -11
- data/lib/rubocop/cop/style/alias.rb +2 -0
- data/lib/rubocop/cop/style/array_join.rb +1 -0
- data/lib/rubocop/cop/style/attr.rb +1 -0
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +2 -0
- data/lib/rubocop/cop/style/case_equality.rb +3 -0
- data/lib/rubocop/cop/style/class_and_module_children.rb +2 -0
- data/lib/rubocop/cop/style/class_check.rb +6 -9
- data/lib/rubocop/cop/style/class_methods_definitions.rb +42 -16
- data/lib/rubocop/cop/style/class_vars.rb +1 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +49 -60
- data/lib/rubocop/cop/style/dir.rb +1 -0
- data/lib/rubocop/cop/style/double_negation.rb +1 -0
- data/lib/rubocop/cop/style/empty_literal.rb +3 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -3
- data/lib/rubocop/cop/style/even_odd.rb +1 -0
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
- data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
- data/lib/rubocop/cop/style/float_division.rb +2 -0
- data/lib/rubocop/cop/style/format_string.rb +1 -4
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +12 -2
- data/lib/rubocop/cop/style/hash_transform_keys.rb +5 -11
- data/lib/rubocop/cop/style/hash_transform_values.rb +5 -11
- data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -0
- data/lib/rubocop/cop/style/lambda_call.rb +3 -1
- data/lib/rubocop/cop/style/mixin_usage.rb +1 -0
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +14 -1
- data/lib/rubocop/cop/style/nil_comparison.rb +2 -0
- data/lib/rubocop/cop/style/non_nil_check.rb +2 -0
- data/lib/rubocop/cop/style/not.rb +1 -0
- data/lib/rubocop/cop/style/numeric_predicate.rb +1 -3
- data/lib/rubocop/cop/style/preferred_hash_methods.rb +2 -0
- data/lib/rubocop/cop/style/raise_args.rb +2 -0
- data/lib/rubocop/cop/style/random_with_offset.rb +1 -0
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -3
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +2 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +12 -3
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +2 -2
- data/lib/rubocop/cop/style/redundant_sort.rb +1 -7
- data/lib/rubocop/cop/style/safe_navigation.rb +5 -0
- data/lib/rubocop/cop/style/sample.rb +2 -1
- data/lib/rubocop/cop/style/send.rb +2 -3
- data/lib/rubocop/cop/style/signal_exception.rb +2 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
- data/lib/rubocop/cop/style/slicing_with_range.rb +2 -1
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +16 -2
- data/lib/rubocop/cop/style/strip.rb +1 -0
- data/lib/rubocop/cop/style/unpack_first.rb +1 -0
- data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -5
- data/lib/rubocop/core_ext/string.rb +1 -1
- data/lib/rubocop/ext/regexp_node.rb +4 -4
- data/lib/rubocop/options.rb +19 -1
- data/lib/rubocop/result_cache.rb +30 -13
- data/lib/rubocop/runner.rb +29 -14
- data/lib/rubocop/version.rb +1 -1
- metadata +8 -4
@@ -32,6 +32,8 @@ module RuboCop
|
|
32
32
|
MSG_SYMBOL_ARGS = 'Use `alias %<prefer>s` instead of ' \
|
33
33
|
'`alias %<current>s`.'
|
34
34
|
|
35
|
+
RESTRICT_ON_SEND = %i[alias_method].freeze
|
36
|
+
|
35
37
|
def on_send(node)
|
36
38
|
return unless node.command?(:alias_method)
|
37
39
|
return unless style == :prefer_alias && alias_keyword_possible?(node)
|
@@ -33,11 +33,14 @@ module RuboCop
|
|
33
33
|
extend AutoCorrector
|
34
34
|
|
35
35
|
MSG = 'Avoid the use of the case equality operator `===`.'
|
36
|
+
RESTRICT_ON_SEND = %i[===].freeze
|
36
37
|
|
37
38
|
def_node_matcher :case_equality?, '(send $#const? :=== $_)'
|
38
39
|
|
39
40
|
def on_send(node)
|
40
41
|
case_equality?(node) do |lhs, rhs|
|
42
|
+
return if lhs.const_type? && !lhs.module_name?
|
43
|
+
|
41
44
|
add_offense(node.loc.selector) do |corrector|
|
42
45
|
replacement = replacement(lhs, rhs)
|
43
46
|
corrector.replace(node, replacement) if replacement
|
@@ -28,19 +28,16 @@ module RuboCop
|
|
28
28
|
extend AutoCorrector
|
29
29
|
|
30
30
|
MSG = 'Prefer `Object#%<prefer>s` over `Object#%<current>s`.'
|
31
|
-
|
32
|
-
def_node_matcher :class_check?, '(send _ ${:is_a? :kind_of?} _)'
|
31
|
+
RESTRICT_ON_SEND = %i[is_a? kind_of?].freeze
|
33
32
|
|
34
33
|
def on_send(node)
|
35
|
-
|
36
|
-
return if style == method_name
|
34
|
+
return if style == node.method_name
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
message = message(node)
|
37
|
+
add_offense(node.loc.selector, message: message) do |corrector|
|
38
|
+
replacement = node.method?(:is_a?) ? 'kind_of?' : 'is_a?'
|
41
39
|
|
42
|
-
|
43
|
-
end
|
40
|
+
corrector.replace(node.loc.selector, replacement)
|
44
41
|
end
|
45
42
|
end
|
46
43
|
|
@@ -62,22 +62,19 @@ module RuboCop
|
|
62
62
|
include ConfigurableEnforcedStyle
|
63
63
|
include CommentsHelp
|
64
64
|
include VisibilityHelp
|
65
|
+
include RangeHelp
|
65
66
|
extend AutoCorrector
|
66
67
|
|
67
|
-
MSG = 'Use `%<preferred>s` to define class method.'
|
68
|
+
MSG = 'Use `%<preferred>s` to define a class method.'
|
69
|
+
MSG_SCLASS = 'Do not define public methods within class << self.'
|
68
70
|
|
69
71
|
def on_sclass(node)
|
70
72
|
return unless def_self_style?
|
71
73
|
return unless node.identifier.source == 'self'
|
72
|
-
return
|
74
|
+
return unless all_methods_public?(node)
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
message = format(MSG, preferred: "def self.#{def_node.method_name}")
|
78
|
-
add_offense(def_node, message: message) do |corrector|
|
79
|
-
extract_def_from_sclass(def_node, node, corrector)
|
80
|
-
end
|
76
|
+
add_offense(node, message: MSG_SCLASS) do |corrector|
|
77
|
+
autocorrect_sclass(node, corrector)
|
81
78
|
end
|
82
79
|
end
|
83
80
|
|
@@ -94,8 +91,11 @@ module RuboCop
|
|
94
91
|
style == :def_self
|
95
92
|
end
|
96
93
|
|
97
|
-
def
|
98
|
-
def_nodes
|
94
|
+
def all_methods_public?(sclass_node)
|
95
|
+
def_nodes = def_nodes(sclass_node)
|
96
|
+
return false if def_nodes.empty?
|
97
|
+
|
98
|
+
def_nodes.all? { |def_node| node_visibility(def_node) == :public }
|
99
99
|
end
|
100
100
|
|
101
101
|
def def_nodes(sclass_node)
|
@@ -111,19 +111,45 @@ module RuboCop
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
def
|
114
|
+
def autocorrect_sclass(node, corrector)
|
115
|
+
rewritten_defs = []
|
116
|
+
|
117
|
+
def_nodes(node).each do |def_node|
|
118
|
+
next unless node_visibility(def_node) == :public
|
119
|
+
|
120
|
+
range, source = extract_def_from_sclass(def_node, node)
|
121
|
+
|
122
|
+
corrector.remove(range)
|
123
|
+
rewritten_defs << source
|
124
|
+
end
|
125
|
+
|
126
|
+
if sclass_only_has_methods?(node)
|
127
|
+
corrector.remove(node)
|
128
|
+
rewritten_defs.first&.strip!
|
129
|
+
else
|
130
|
+
corrector.insert_after(node, "\n")
|
131
|
+
end
|
132
|
+
|
133
|
+
corrector.insert_after(node, rewritten_defs.join("\n"))
|
134
|
+
end
|
135
|
+
|
136
|
+
def sclass_only_has_methods?(node)
|
137
|
+
node.body.def_type? || node.body.each_child_node.all?(&:def_type?)
|
138
|
+
end
|
139
|
+
|
140
|
+
def extract_def_from_sclass(def_node, sclass_node)
|
115
141
|
range = source_range_with_comment(def_node)
|
116
142
|
source = range.source.sub!(
|
117
143
|
"def #{def_node.method_name}",
|
118
144
|
"def self.#{def_node.method_name}"
|
119
145
|
)
|
120
146
|
|
121
|
-
|
122
|
-
|
147
|
+
source = source.gsub(/^ {#{indentation_diff(def_node, sclass_node)}}/, '')
|
148
|
+
[range, source.chomp]
|
123
149
|
end
|
124
150
|
|
125
|
-
def
|
126
|
-
|
151
|
+
def indentation_diff(node1, node2)
|
152
|
+
node1.loc.column - node2.loc.column
|
127
153
|
end
|
128
154
|
end
|
129
155
|
end
|
@@ -47,14 +47,13 @@ module RuboCop
|
|
47
47
|
#
|
48
48
|
class ClassVars < Base
|
49
49
|
MSG = 'Replace class var %<class_var>s with a class instance var.'
|
50
|
+
RESTRICT_ON_SEND = %i[class_variable_set].freeze
|
50
51
|
|
51
52
|
def on_cvasgn(node)
|
52
53
|
add_offense(node.loc.name, message: format(MSG, class_var: node.children.first))
|
53
54
|
end
|
54
55
|
|
55
56
|
def on_send(node)
|
56
|
-
return unless node.method?(:class_variable_set)
|
57
|
-
|
58
57
|
add_offense(
|
59
58
|
node.first_argument, message: format(MSG, class_var: node.first_argument.source)
|
60
59
|
)
|
@@ -208,10 +208,11 @@ module RuboCop
|
|
208
208
|
# some_other_method
|
209
209
|
# bar = 2
|
210
210
|
# end
|
211
|
-
class ConditionalAssignment <
|
211
|
+
class ConditionalAssignment < Base
|
212
212
|
include ConditionalAssignmentHelper
|
213
213
|
include ConfigurableEnforcedStyle
|
214
214
|
include IgnoredNode
|
215
|
+
extend AutoCorrector
|
215
216
|
|
216
217
|
MSG = 'Use the return of the conditional for variable assignment ' \
|
217
218
|
'and comparison.'
|
@@ -275,14 +276,6 @@ module RuboCop
|
|
275
276
|
check_node(node, branches)
|
276
277
|
end
|
277
278
|
|
278
|
-
def autocorrect(node)
|
279
|
-
if assignment_type?(node)
|
280
|
-
move_assignment_inside_condition(node)
|
281
|
-
else
|
282
|
-
move_assignment_outside_condition(node)
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
279
|
private
|
287
280
|
|
288
281
|
def check_assignment_to_condition(node)
|
@@ -298,7 +291,9 @@ module RuboCop
|
|
298
291
|
return unless else_branch
|
299
292
|
return if allowed_single_line?([*branches, else_branch])
|
300
293
|
|
301
|
-
add_offense(node, message: ASSIGN_TO_CONDITION_MSG)
|
294
|
+
add_offense(node, message: ASSIGN_TO_CONDITION_MSG) do |corrector|
|
295
|
+
autocorrect(corrector, node)
|
296
|
+
end
|
302
297
|
end
|
303
298
|
|
304
299
|
def candidate_node?(node)
|
@@ -326,25 +321,25 @@ module RuboCop
|
|
326
321
|
assignment
|
327
322
|
end
|
328
323
|
|
329
|
-
def move_assignment_outside_condition(node)
|
324
|
+
def move_assignment_outside_condition(corrector, node)
|
330
325
|
if node.case_type?
|
331
|
-
CaseCorrector.correct(self, node)
|
326
|
+
CaseCorrector.correct(corrector, self, node)
|
332
327
|
elsif node.ternary?
|
333
|
-
TernaryCorrector.correct(node)
|
328
|
+
TernaryCorrector.correct(corrector, node)
|
334
329
|
elsif node.if? || node.unless?
|
335
|
-
IfCorrector.correct(self, node)
|
330
|
+
IfCorrector.correct(corrector, self, node)
|
336
331
|
end
|
337
332
|
end
|
338
333
|
|
339
|
-
def move_assignment_inside_condition(node)
|
334
|
+
def move_assignment_inside_condition(corrector, node)
|
340
335
|
*_assignment, condition = *node
|
341
336
|
|
342
337
|
if ternary_condition?(condition)
|
343
|
-
TernaryCorrector.move_assignment_inside_condition(node)
|
338
|
+
TernaryCorrector.move_assignment_inside_condition(corrector, node)
|
344
339
|
elsif condition.case_type?
|
345
|
-
CaseCorrector.move_assignment_inside_condition(node)
|
340
|
+
CaseCorrector.move_assignment_inside_condition(corrector, node)
|
346
341
|
elsif condition.if_type?
|
347
|
-
IfCorrector.move_assignment_inside_condition(node)
|
342
|
+
IfCorrector.move_assignment_inside_condition(corrector, node)
|
348
343
|
end
|
349
344
|
end
|
350
345
|
|
@@ -371,7 +366,17 @@ module RuboCop
|
|
371
366
|
return if allowed_single_line?(branches)
|
372
367
|
return if correction_exceeds_line_limit?(node, branches)
|
373
368
|
|
374
|
-
add_offense(node)
|
369
|
+
add_offense(node) do |corrector|
|
370
|
+
autocorrect(corrector, node)
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
def autocorrect(corrector, node)
|
375
|
+
if assignment_type?(node)
|
376
|
+
move_assignment_inside_condition(corrector, node)
|
377
|
+
else
|
378
|
+
move_assignment_outside_condition(corrector, node)
|
379
|
+
end
|
375
380
|
end
|
376
381
|
|
377
382
|
def allowed_statements?(branches)
|
@@ -499,24 +504,20 @@ module RuboCop
|
|
499
504
|
include ConditionalAssignmentHelper
|
500
505
|
include ConditionalCorrectorHelper
|
501
506
|
|
502
|
-
def correct(node)
|
503
|
-
|
504
|
-
corrector.replace(node, correction(node))
|
505
|
-
end
|
507
|
+
def correct(corrector, node)
|
508
|
+
corrector.replace(node, correction(node))
|
506
509
|
end
|
507
510
|
|
508
|
-
def move_assignment_inside_condition(node)
|
511
|
+
def move_assignment_inside_condition(corrector, node)
|
509
512
|
*_var, rhs = *node
|
510
513
|
if_branch, else_branch = extract_branches(node)
|
511
514
|
assignment = assignment(node)
|
512
515
|
|
513
|
-
|
514
|
-
|
515
|
-
corrector.remove(assignment)
|
516
|
+
remove_parentheses(corrector, rhs) if Util.parentheses?(rhs)
|
517
|
+
corrector.remove(assignment)
|
516
518
|
|
517
|
-
|
518
|
-
|
519
|
-
end
|
519
|
+
move_branch_inside_condition(corrector, if_branch, assignment)
|
520
|
+
move_branch_inside_condition(corrector, else_branch, assignment)
|
520
521
|
end
|
521
522
|
|
522
523
|
private
|
@@ -565,22 +566,19 @@ module RuboCop
|
|
565
566
|
include ConditionalAssignmentHelper
|
566
567
|
include ConditionalCorrectorHelper
|
567
568
|
|
568
|
-
def correct(cop, node)
|
569
|
-
|
569
|
+
def correct(corrector, cop, node)
|
570
|
+
correct_if_branches(corrector, cop, node)
|
570
571
|
end
|
571
572
|
|
572
|
-
def move_assignment_inside_condition(node)
|
573
|
+
def move_assignment_inside_condition(corrector, node)
|
573
574
|
column = node.loc.expression.column
|
574
575
|
*_var, condition = *node
|
575
576
|
assignment = assignment(node)
|
576
577
|
|
577
|
-
|
578
|
-
corrector.remove(assignment)
|
578
|
+
corrector.remove(assignment)
|
579
579
|
|
580
|
-
|
581
|
-
|
582
|
-
assignment, column)
|
583
|
-
end
|
580
|
+
condition.branches.flatten.each do |branch|
|
581
|
+
move_branch_inside_condition(corrector, branch, condition, assignment, column)
|
584
582
|
end
|
585
583
|
end
|
586
584
|
|
@@ -614,31 +612,25 @@ module RuboCop
|
|
614
612
|
include ConditionalAssignmentHelper
|
615
613
|
include ConditionalCorrectorHelper
|
616
614
|
|
617
|
-
def correct(cop, node)
|
615
|
+
def correct(corrector, cop, node)
|
618
616
|
when_branches, else_branch = extract_tail_branches(node)
|
619
617
|
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
replace_branch_assignment(corrector, else_branch)
|
618
|
+
corrector.insert_before(node, lhs(else_branch))
|
619
|
+
correct_branches(corrector, when_branches)
|
620
|
+
replace_branch_assignment(corrector, else_branch)
|
624
621
|
|
625
|
-
|
626
|
-
indent(cop, lhs(else_branch)))
|
627
|
-
end
|
622
|
+
corrector.insert_before(node.loc.end, indent(cop, lhs(else_branch)))
|
628
623
|
end
|
629
624
|
|
630
|
-
def move_assignment_inside_condition(node)
|
625
|
+
def move_assignment_inside_condition(corrector, node)
|
631
626
|
column = node.loc.expression.column
|
632
627
|
*_var, condition = *node
|
633
628
|
assignment = assignment(node)
|
634
629
|
|
635
|
-
|
636
|
-
corrector.remove(assignment)
|
630
|
+
corrector.remove(assignment)
|
637
631
|
|
638
|
-
|
639
|
-
|
640
|
-
assignment, column)
|
641
|
-
end
|
632
|
+
extract_branches(condition).flatten.each do |branch|
|
633
|
+
move_branch_inside_condition(corrector, branch, condition, assignment, column)
|
642
634
|
end
|
643
635
|
end
|
644
636
|
|
@@ -656,17 +648,14 @@ module RuboCop
|
|
656
648
|
[when_branches, case_node.else_branch]
|
657
649
|
end
|
658
650
|
|
659
|
-
def move_branch_inside_condition(corrector, branch, condition,
|
660
|
-
assignment, column)
|
651
|
+
def move_branch_inside_condition(corrector, branch, condition, assignment, column)
|
661
652
|
branch_assignment = tail(branch)
|
662
|
-
corrector.insert_before(branch_assignment,
|
663
|
-
assignment.source)
|
653
|
+
corrector.insert_before(branch_assignment, assignment.source)
|
664
654
|
|
665
655
|
remove_whitespace_in_branches(corrector, branch, condition, column)
|
666
656
|
|
667
657
|
parent_keyword = branch.parent.loc.keyword
|
668
|
-
corrector.remove_preceding(parent_keyword,
|
669
|
-
parent_keyword.column - column)
|
658
|
+
corrector.remove_preceding(parent_keyword, parent_keyword.column - column)
|
670
659
|
end
|
671
660
|
end
|
672
661
|
end
|
@@ -20,6 +20,7 @@ module RuboCop
|
|
20
20
|
extend AutoCorrector
|
21
21
|
|
22
22
|
MSG = "Use `__dir__` to get an absolute path to the current file's directory."
|
23
|
+
RESTRICT_ON_SEND = %i[expand_path dirname].freeze
|
23
24
|
|
24
25
|
def_node_matcher :dir_replacement?, <<~PATTERN
|
25
26
|
{(send (const {nil? cbase} :File) :expand_path (send (const {nil? cbase} :File) :dirname #file_keyword?))
|
@@ -25,6 +25,8 @@ module RuboCop
|
|
25
25
|
HASH_MSG = 'Use hash literal `{}` instead of `Hash.new`.'
|
26
26
|
STR_MSG = 'Use string literal `%<prefer>s` instead of `String.new`.'
|
27
27
|
|
28
|
+
RESTRICT_ON_SEND = %i[new].freeze
|
29
|
+
|
28
30
|
def_node_matcher :array_node, '(send (const {nil? cbase} :Array) :new)'
|
29
31
|
def_node_matcher :hash_node, '(send (const {nil? cbase} :Hash) :new)'
|
30
32
|
def_node_matcher :str_node, '(send (const {nil? cbase} :String) :new)'
|
@@ -69,7 +71,7 @@ module RuboCop
|
|
69
71
|
parent = node.parent
|
70
72
|
return false unless parent && %i[send super zsuper].include?(parent.type)
|
71
73
|
|
72
|
-
node.
|
74
|
+
node.equal?(parent.arguments.first) &&
|
73
75
|
!parentheses?(node.parent)
|
74
76
|
end
|
75
77
|
|
@@ -37,7 +37,7 @@ module RuboCop
|
|
37
37
|
MSG_INCORRECT_LINE = 'Use `%<expected>s` instead of `%<actual>s`, ' \
|
38
38
|
'as they are used by backtraces.'
|
39
39
|
|
40
|
-
|
40
|
+
RESTRICT_ON_SEND = %i[eval class_eval module_eval instance_eval].freeze
|
41
41
|
|
42
42
|
def_node_matcher :eval_without_location?, <<~PATTERN
|
43
43
|
{
|
@@ -63,8 +63,6 @@ module RuboCop
|
|
63
63
|
PATTERN
|
64
64
|
|
65
65
|
def on_send(node)
|
66
|
-
return unless EVAL_METHODS.include?(node.method_name)
|
67
|
-
|
68
66
|
eval_without_location?(node) do |code|
|
69
67
|
if with_lineno?(node)
|
70
68
|
on_with_lineno(node, code)
|