rubocop 0.72.0 → 0.73.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 +13 -0
- data/lib/rubocop.rb +2 -0
- data/lib/rubocop/ast/node.rb +8 -8
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +16 -5
- data/lib/rubocop/ast/traversal.rb +3 -3
- data/lib/rubocop/cop/autocorrect_logic.rb +71 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
- data/lib/rubocop/cop/commissioner.rb +3 -9
- data/lib/rubocop/cop/cop.rb +36 -6
- data/lib/rubocop/cop/corrector.rb +2 -3
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +2 -2
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/generator.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -2
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +1 -1
- data/lib/rubocop/cop/layout/indent_first_argument.rb +1 -1
- data/lib/rubocop/cop/layout/indent_heredoc.rb +3 -2
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +28 -0
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +18 -4
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +14 -2
- data/lib/rubocop/cop/layout/tab.rb +10 -22
- data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +3 -3
- data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -3
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
- data/lib/rubocop/cop/lint/multiple_compare.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -3
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +1 -1
- data/lib/rubocop/cop/lint/number_conversion.rb +2 -2
- data/lib/rubocop/cop/lint/rand_one.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -5
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -1
- data/lib/rubocop/cop/lint/unified_integer.rb +1 -1
- data/lib/rubocop/cop/lint/unneeded_require_statement.rb +1 -1
- data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -1
- data/lib/rubocop/cop/lint/uri_regexp.rb +2 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +6 -6
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/metrics/class_length.rb +1 -1
- data/lib/rubocop/cop/metrics/module_length.rb +1 -1
- data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +4 -4
- data/lib/rubocop/cop/mixin/method_complexity.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +3 -3
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +2 -2
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
- data/lib/rubocop/cop/security/eval.rb +1 -1
- data/lib/rubocop/cop/security/json_load.rb +1 -1
- data/lib/rubocop/cop/security/marshal_load.rb +1 -1
- data/lib/rubocop/cop/security/open.rb +1 -1
- data/lib/rubocop/cop/security/yaml_load.rb +1 -1
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
- data/lib/rubocop/cop/style/constant_visibility.rb +1 -1
- data/lib/rubocop/cop/style/date_time.rb +3 -3
- data/lib/rubocop/cop/style/dir.rb +1 -1
- data/lib/rubocop/cop/style/documentation_method.rb +1 -1
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +49 -0
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
- data/lib/rubocop/cop/style/each_with_object.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +2 -2
- data/lib/rubocop/cop/style/even_odd.rb +1 -1
- data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -3
- data/lib/rubocop/cop/style/float_division.rb +4 -4
- data/lib/rubocop/cop/style/format_string.rb +7 -7
- data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
- data/lib/rubocop/cop/style/inverse_methods.rb +2 -2
- data/lib/rubocop/cop/style/min_max.rb +1 -1
- data/lib/rubocop/cop/style/mixin_usage.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +55 -0
- data/lib/rubocop/cop/style/multiple_comparison.rb +1 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +3 -3
- data/lib/rubocop/cop/style/numeric_predicate.rb +3 -3
- data/lib/rubocop/cop/style/option_hash.rb +1 -1
- data/lib/rubocop/cop/style/or_assignment.rb +2 -2
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +6 -6
- data/lib/rubocop/cop/style/redundant_conditional.rb +2 -2
- data/lib/rubocop/cop/style/redundant_exception.rb +2 -2
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -1
- data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -2
- data/lib/rubocop/cop/style/return_nil.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
- data/lib/rubocop/cop/style/sample.rb +1 -1
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/string_hash_keys.rb +2 -2
- data/lib/rubocop/cop/style/strip.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +3 -3
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unneeded_sort.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +1 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -5
- data/lib/rubocop/cop/team.rb +15 -14
- data/lib/rubocop/error.rb +23 -0
- data/lib/rubocop/node_pattern.rb +2 -2
- data/lib/rubocop/options.rb +17 -0
- data/lib/rubocop/rspec/shared_contexts.rb +12 -0
- data/lib/rubocop/target_finder.rb +6 -4
- data/lib/rubocop/version.rb +1 -1
- metadata +4 -2
@@ -223,7 +223,7 @@ module RuboCop
|
|
223
223
|
|
224
224
|
# The shovel operator `<<` does not have its own type. It is a `send`
|
225
225
|
# type.
|
226
|
-
def_node_matcher :assignment_type?,
|
226
|
+
def_node_matcher :assignment_type?, <<~PATTERN
|
227
227
|
{
|
228
228
|
#{ASSIGNMENT_TYPES.join(' ')}
|
229
229
|
(send _recv {:[]= :<< :=~ :!~ :<=> #end_with_eq?} ...)
|
@@ -45,15 +45,15 @@ module RuboCop
|
|
45
45
|
CLASS_MSG = 'Prefer Time over DateTime.'
|
46
46
|
COERCION_MSG = 'Do not use #to_datetime.'
|
47
47
|
|
48
|
-
def_node_matcher :date_time?,
|
48
|
+
def_node_matcher :date_time?, <<~PATTERN
|
49
49
|
(send (const {nil? (cbase)} :DateTime) ...)
|
50
50
|
PATTERN
|
51
51
|
|
52
|
-
def_node_matcher :historic_date?,
|
52
|
+
def_node_matcher :historic_date?, <<~PATTERN
|
53
53
|
(send _ _ _ (const (const nil? :Date) _))
|
54
54
|
PATTERN
|
55
55
|
|
56
|
-
def_node_matcher :to_datetime?,
|
56
|
+
def_node_matcher :to_datetime?, <<~PATTERN
|
57
57
|
(send _ :to_datetime)
|
58
58
|
PATTERN
|
59
59
|
|
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
MSG = 'Use `__dir__` to get an absolute path to the current ' \
|
21
21
|
"file's directory."
|
22
22
|
|
23
|
-
def_node_matcher :dir_replacement?,
|
23
|
+
def_node_matcher :dir_replacement?, <<~PATTERN
|
24
24
|
{(send (const nil? :File) :expand_path (send (const nil? :File) :dirname #file_keyword?))
|
25
25
|
(send (const nil? :File) :dirname (send (const nil? :File) :realpath #file_keyword?))}
|
26
26
|
PATTERN
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Lint/UnneededCopDisableDirective
|
4
|
+
# rubocop:disable Style/DoubleCopDisableDirective
|
5
|
+
|
6
|
+
module RuboCop
|
7
|
+
module Cop
|
8
|
+
module Style
|
9
|
+
# Detects double disable comments on one line. This is mostly to catch
|
10
|
+
# automatically generated comments that need to be regenerated.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# # bad
|
14
|
+
# def f # rubocop:disable Style/For # rubocop:disable Metrics/AbcSize
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# # rubocop:disable Metrics/AbcSize
|
19
|
+
# def f # rubocop:disable Style/For
|
20
|
+
# end
|
21
|
+
# # rubocop:enable Metrics/AbcSize
|
22
|
+
#
|
23
|
+
# # if both fit on one line
|
24
|
+
# def f # rubocop:disable Style/For, Metrics/AbcSize
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
class DoubleCopDisableDirective < Cop
|
28
|
+
# rubocop:enable Style/For, Style/DoubleCopDisableDirective
|
29
|
+
# rubocop:enable Lint/UnneededCopDisableDirective, Metrics/AbcSize
|
30
|
+
MSG = 'More than one disable comment on one line.'
|
31
|
+
|
32
|
+
def investigate(processed_source)
|
33
|
+
processed_source.comments.each do |comment|
|
34
|
+
next unless comment.text.scan('# rubocop:disable').size > 1
|
35
|
+
|
36
|
+
add_offense(comment)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def autocorrect(comment)
|
41
|
+
lambda do |corrector|
|
42
|
+
corrector.replace(comment.loc.expression,
|
43
|
+
comment.text[/# rubocop:disable \S+/])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
22
22
|
MSG = 'Use `each_with_object` instead of `%<method>s`.'
|
23
23
|
METHODS = %i[inject reduce].freeze
|
24
24
|
|
25
|
-
def_node_matcher :each_with_object_candidate?,
|
25
|
+
def_node_matcher :each_with_object_candidate?, <<~PATTERN
|
26
26
|
(block $(send _ {:inject :reduce} _) $_ $_)
|
27
27
|
PATTERN
|
28
28
|
|
@@ -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
|
-
def_node_matcher :eval_without_location?,
|
40
|
+
def_node_matcher :eval_without_location?, <<~PATTERN
|
41
41
|
{
|
42
42
|
(send nil? :eval ${str dstr})
|
43
43
|
(send nil? :eval ${str dstr} _)
|
@@ -53,7 +53,7 @@ module RuboCop
|
|
53
53
|
}
|
54
54
|
PATTERN
|
55
55
|
|
56
|
-
def_node_matcher :line_with_offset?,
|
56
|
+
def_node_matcher :line_with_offset?, <<~PATTERN
|
57
57
|
{
|
58
58
|
(send #special_line_keyword? %1 (int %2))
|
59
59
|
(send (int %2) %1 #special_line_keyword?)
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
class EvenOdd < Cop
|
19
19
|
MSG = 'Replace with `Integer#%<method>s?`.'
|
20
20
|
|
21
|
-
def_node_matcher :even_odd_candidate?,
|
21
|
+
def_node_matcher :even_odd_candidate?, <<~PATTERN
|
22
22
|
(send
|
23
23
|
{(send $_ :% (int 2))
|
24
24
|
(begin (send $_ :% (int 2)))}
|
@@ -51,21 +51,21 @@ module RuboCop
|
|
51
51
|
'instead of ' \
|
52
52
|
'`Pathname.new(__FILE__).parent.expand_path`.'
|
53
53
|
|
54
|
-
def_node_matcher :file_expand_path,
|
54
|
+
def_node_matcher :file_expand_path, <<~PATTERN
|
55
55
|
(send
|
56
56
|
(const nil? :File) :expand_path
|
57
57
|
$_
|
58
58
|
$_)
|
59
59
|
PATTERN
|
60
60
|
|
61
|
-
def_node_matcher :pathname_parent_expand_path,
|
61
|
+
def_node_matcher :pathname_parent_expand_path, <<~PATTERN
|
62
62
|
(send
|
63
63
|
(send
|
64
64
|
(send nil? :Pathname
|
65
65
|
$_) :parent) :expand_path)
|
66
66
|
PATTERN
|
67
67
|
|
68
|
-
def_node_matcher :pathname_new_parent_expand_path,
|
68
|
+
def_node_matcher :pathname_new_parent_expand_path, <<~PATTERN
|
69
69
|
(send
|
70
70
|
(send
|
71
71
|
(send
|
@@ -42,16 +42,16 @@ module RuboCop
|
|
42
42
|
class FloatDivision < Cop
|
43
43
|
include ConfigurableEnforcedStyle
|
44
44
|
|
45
|
-
def_node_matcher :right_coerce?,
|
45
|
+
def_node_matcher :right_coerce?, <<~PATTERN
|
46
46
|
(send _ :/ (send _ :to_f))
|
47
47
|
PATTERN
|
48
|
-
def_node_matcher :left_coerce?,
|
48
|
+
def_node_matcher :left_coerce?, <<~PATTERN
|
49
49
|
(send (send _ :to_f) :/ _)
|
50
50
|
PATTERN
|
51
|
-
def_node_matcher :both_coerce?,
|
51
|
+
def_node_matcher :both_coerce?, <<~PATTERN
|
52
52
|
(send (send _ :to_f) :/ (send _ :to_f))
|
53
53
|
PATTERN
|
54
|
-
def_node_matcher :any_coerce?,
|
54
|
+
def_node_matcher :any_coerce?, <<~PATTERN
|
55
55
|
{(send _ :/ (send _ :to_f)) (send (send _ :to_f) :/ _)}
|
56
56
|
PATTERN
|
57
57
|
|
@@ -40,15 +40,15 @@ module RuboCop
|
|
40
40
|
|
41
41
|
MSG = 'Favor `%<prefer>s` over `%<current>s`.'
|
42
42
|
|
43
|
-
def_node_matcher :formatter,
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
def_node_matcher :formatter, <<~PATTERN
|
44
|
+
{
|
45
|
+
(send nil? ${:sprintf :format} _ _ ...)
|
46
|
+
(send {str dstr} $:% ... )
|
47
|
+
(send !nil? $:% {array hash})
|
48
|
+
}
|
49
49
|
PATTERN
|
50
50
|
|
51
|
-
def_node_matcher :variable_argument?,
|
51
|
+
def_node_matcher :variable_argument?, <<~PATTERN
|
52
52
|
(send {str dstr} :% {send_type? lvar_type?})
|
53
53
|
PATTERN
|
54
54
|
|
@@ -47,7 +47,7 @@ module RuboCop
|
|
47
47
|
[Style::Not]
|
48
48
|
end
|
49
49
|
|
50
|
-
def_node_matcher :inverse_candidate?,
|
50
|
+
def_node_matcher :inverse_candidate?, <<~PATTERN
|
51
51
|
{
|
52
52
|
(send $(send $(...) $_ $...) :!)
|
53
53
|
(send (block $(send $(...) $_) $...) :!)
|
@@ -55,7 +55,7 @@ module RuboCop
|
|
55
55
|
}
|
56
56
|
PATTERN
|
57
57
|
|
58
|
-
def_node_matcher :inverse_block?,
|
58
|
+
def_node_matcher :inverse_block?, <<~PATTERN
|
59
59
|
(block $(send (...) $_) ... { $(send ... :!)
|
60
60
|
$(send (...) {:!= :!~} ...)
|
61
61
|
(begin ... $(send ... :!))
|
@@ -44,7 +44,7 @@ module RuboCop
|
|
44
44
|
MSG = '`%<statement>s` is used at the top level. Use inside `class` ' \
|
45
45
|
'or `module`.'
|
46
46
|
|
47
|
-
def_node_matcher :include_statement,
|
47
|
+
def_node_matcher :include_statement, <<~PATTERN
|
48
48
|
(send nil? ${:include :extend :prepend}
|
49
49
|
const)
|
50
50
|
PATTERN
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop checks uses of the `then` keyword
|
7
|
+
# in multi-line when statements.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# case foo
|
12
|
+
# when bar then
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# case foo
|
17
|
+
# when bar
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# case foo
|
22
|
+
# when bar then do_something
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
class MultilineWhenThen < Cop
|
26
|
+
include RangeHelp
|
27
|
+
|
28
|
+
MSG = 'Do not use `then` for multiline `when` statement.'
|
29
|
+
|
30
|
+
def on_when(node)
|
31
|
+
# Without `then`, there's no offense
|
32
|
+
return unless node.then?
|
33
|
+
|
34
|
+
# Single line usage of `then` is not an offense
|
35
|
+
return if !node.children.last.nil? && !node.multiline? && node.then?
|
36
|
+
|
37
|
+
# With more than one statements after then, there's not offense
|
38
|
+
return if node.children.last&.begin_type?
|
39
|
+
|
40
|
+
add_offense(node, location: :begin)
|
41
|
+
end
|
42
|
+
|
43
|
+
def autocorrect(node)
|
44
|
+
lambda do |corrector|
|
45
|
+
corrector.remove(
|
46
|
+
range_with_surrounding_space(
|
47
|
+
range: node.loc.begin, side: :left
|
48
|
+
)
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -30,7 +30,7 @@ module RuboCop
|
|
30
30
|
private
|
31
31
|
|
32
32
|
def_node_matcher :simple_double_comparison?, '(send $lvar :== $lvar)'
|
33
|
-
def_node_matcher :simple_comparison?,
|
33
|
+
def_node_matcher :simple_comparison?, <<~PATTERN
|
34
34
|
{(send $lvar :== _)
|
35
35
|
(send _ :== $lvar)}
|
36
36
|
PATTERN
|
@@ -143,13 +143,13 @@ module RuboCop
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
-
def_node_matcher :splat_value,
|
146
|
+
def_node_matcher :splat_value, <<~PATTERN
|
147
147
|
(array (splat $_))
|
148
148
|
PATTERN
|
149
149
|
|
150
150
|
# Some of these patterns may not actually return an immutable object,
|
151
151
|
# but we want to consider them immutable for this cop.
|
152
|
-
def_node_matcher :operation_produces_immutable_object?,
|
152
|
+
def_node_matcher :operation_produces_immutable_object?, <<~PATTERN
|
153
153
|
{
|
154
154
|
(const _ _)
|
155
155
|
(send (const nil? :Struct) :new ...)
|
@@ -165,7 +165,7 @@ module RuboCop
|
|
165
165
|
}
|
166
166
|
PATTERN
|
167
167
|
|
168
|
-
def_node_matcher :range_enclosed_in_parentheses?,
|
168
|
+
def_node_matcher :range_enclosed_in_parentheses?, <<~PATTERN
|
169
169
|
(begin ({irange erange} _ _))
|
170
170
|
PATTERN
|
171
171
|
end
|
@@ -120,15 +120,15 @@ module RuboCop
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
-
def_node_matcher :predicate,
|
123
|
+
def_node_matcher :predicate, <<~PATTERN
|
124
124
|
(send $(...) ${:zero? :positive? :negative?})
|
125
125
|
PATTERN
|
126
126
|
|
127
|
-
def_node_matcher :comparison,
|
127
|
+
def_node_matcher :comparison, <<~PATTERN
|
128
128
|
(send [$(...) !gvar_type?] ${:== :> :<} (int 0))
|
129
129
|
PATTERN
|
130
130
|
|
131
|
-
def_node_matcher :inverted_comparison,
|
131
|
+
def_node_matcher :inverted_comparison, <<~PATTERN
|
132
132
|
(send (int 0) ${:== :> :<} [$(...) !gvar_type?])
|
133
133
|
PATTERN
|
134
134
|
end
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
class OrAssignment < Cop
|
30
30
|
MSG = 'Use the double pipe equals operator `||=` instead.'
|
31
31
|
|
32
|
-
def_node_matcher :ternary_assignment?,
|
32
|
+
def_node_matcher :ternary_assignment?, <<~PATTERN
|
33
33
|
({lvasgn ivasgn cvasgn gvasgn} _var
|
34
34
|
(if
|
35
35
|
({lvar ivar cvar gvar} _var)
|
@@ -37,7 +37,7 @@ module RuboCop
|
|
37
37
|
_))
|
38
38
|
PATTERN
|
39
39
|
|
40
|
-
def_node_matcher :unless_assignment?,
|
40
|
+
def_node_matcher :unless_assignment?, <<~PATTERN
|
41
41
|
(if
|
42
42
|
({lvar ivar cvar gvar} _var) nil?
|
43
43
|
({lvasgn ivasgn cvasgn gvasgn} _var
|