rubocop 1.10.0 → 1.11.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 +12 -12
- data/assets/output.html.erb +1 -1
- data/config/default.yml +13 -0
- data/lib/rubocop.rb +1 -0
- data/lib/rubocop/cli/command/execute_runner.rb +1 -1
- data/lib/rubocop/cli/command/suggest_extensions.rb +1 -1
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -1
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -0
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -0
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -0
- data/lib/rubocop/cop/gemspec/date_assignment.rb +1 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -0
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -0
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +2 -0
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +2 -0
- data/lib/rubocop/cop/generator.rb +2 -2
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +2 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +151 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +2 -0
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.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 +3 -0
- data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +4 -0
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -0
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +1 -0
- data/lib/rubocop/cop/layout/extra_spacing.rb +2 -2
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -0
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -0
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -0
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +2 -0
- data/lib/rubocop/cop/lint/constant_resolution.rb +1 -0
- data/lib/rubocop/cop/lint/debugger.rb +3 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -0
- data/lib/rubocop/cop/lint/duplicate_branch.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -0
- data/lib/rubocop/cop/lint/duplicate_require.rb +1 -0
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -0
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -0
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +1 -0
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -0
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -0
- data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -0
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -0
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +7 -0
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -0
- data/lib/rubocop/cop/lint/number_conversion.rb +2 -0
- data/lib/rubocop/cop/lint/raise_exception.rb +2 -0
- data/lib/rubocop/cop/lint/rand_one.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -0
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -0
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -0
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -0
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -0
- data/lib/rubocop/cop/lint/struct_new_override.rb +1 -0
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +3 -0
- data/lib/rubocop/cop/lint/unified_integer.rb +1 -0
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +5 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -0
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -0
- data/lib/rubocop/cop/lint/useless_times.rb +3 -0
- data/lib/rubocop/cop/metrics/module_length.rb +1 -0
- data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -0
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +6 -4
- data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +2 -0
- data/lib/rubocop/cop/mixin/def_node.rb +1 -0
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -0
- data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -0
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +1 -0
- data/lib/rubocop/cop/mixin/negative_conditional.rb +3 -0
- data/lib/rubocop/cop/mixin/preferred_delimiters.rb +1 -1
- data/lib/rubocop/cop/mixin/rational_literal.rb +1 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +5 -0
- data/lib/rubocop/cop/mixin/visibility_help.rb +1 -0
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -0
- data/lib/rubocop/cop/naming/constant_name.rb +2 -0
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -0
- data/lib/rubocop/cop/naming/method_name.rb +3 -0
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -0
- 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 +1 -0
- data/lib/rubocop/cop/style/alias.rb +1 -0
- data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -0
- data/lib/rubocop/cop/style/array_coercion.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/case_equality.rb +2 -1
- data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -0
- data/lib/rubocop/cop/style/collection_compact.rb +2 -0
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -0
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -0
- data/lib/rubocop/cop/style/constant_visibility.rb +1 -0
- data/lib/rubocop/cop/style/date_time.rb +3 -0
- data/lib/rubocop/cop/style/dir.rb +1 -0
- data/lib/rubocop/cop/style/documentation.rb +5 -0
- data/lib/rubocop/cop/style/documentation_method.rb +1 -0
- data/lib/rubocop/cop/style/double_negation.rb +1 -0
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -0
- data/lib/rubocop/cop/style/each_with_object.rb +1 -0
- data/lib/rubocop/cop/style/empty_literal.rb +9 -0
- data/lib/rubocop/cop/style/endless_method.rb +1 -0
- data/lib/rubocop/cop/style/eval_with_location.rb +2 -0
- data/lib/rubocop/cop/style/even_odd.rb +1 -0
- data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -0
- data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -0
- data/lib/rubocop/cop/style/float_division.rb +4 -0
- data/lib/rubocop/cop/style/format_string.rb +2 -0
- data/lib/rubocop/cop/style/format_string_token.rb +1 -0
- data/lib/rubocop/cop/style/global_std_stream.rb +1 -0
- data/lib/rubocop/cop/style/hash_conversion.rb +26 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +1 -0
- data/lib/rubocop/cop/style/hash_except.rb +1 -0
- data/lib/rubocop/cop/style/hash_like_case.rb +1 -0
- data/lib/rubocop/cop/style/hash_transform_keys.rb +4 -0
- data/lib/rubocop/cop/style/hash_transform_values.rb +4 -0
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
- data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +2 -0
- data/lib/rubocop/cop/style/min_max.rb +1 -0
- data/lib/rubocop/cop/style/mixin_usage.rb +2 -0
- data/lib/rubocop/cop/style/module_function.rb +5 -0
- data/lib/rubocop/cop/style/multiple_comparison.rb +21 -2
- data/lib/rubocop/cop/style/mutable_constant.rb +3 -0
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +3 -0
- data/lib/rubocop/cop/style/nil_lambda.rb +1 -0
- data/lib/rubocop/cop/style/non_nil_check.rb +7 -0
- data/lib/rubocop/cop/style/numeric_predicate.rb +3 -0
- data/lib/rubocop/cop/style/option_hash.rb +1 -0
- data/lib/rubocop/cop/style/or_assignment.rb +2 -0
- data/lib/rubocop/cop/style/parallel_assignment.rb +6 -0
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -0
- data/lib/rubocop/cop/style/proc.rb +1 -0
- data/lib/rubocop/cop/style/random_with_offset.rb +5 -0
- data/lib/rubocop/cop/style/redundant_assignment.rb +1 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +7 -1
- data/lib/rubocop/cop/style/redundant_conditional.rb +2 -0
- data/lib/rubocop/cop/style/redundant_exception.rb +2 -0
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +2 -0
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +13 -0
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +2 -0
- data/lib/rubocop/cop/style/redundant_sort.rb +1 -0
- data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -0
- data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
- data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -0
- data/lib/rubocop/cop/style/return_nil.rb +6 -0
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -0
- data/lib/rubocop/cop/style/sample.rb +1 -0
- data/lib/rubocop/cop/style/signal_exception.rb +3 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -0
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +1 -0
- data/lib/rubocop/cop/style/string_hash_keys.rb +2 -0
- data/lib/rubocop/cop/style/strip.rb +1 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +1 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +25 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -0
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +1 -0
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -0
- data/lib/rubocop/cop/style/unless_logical_operators.rb +99 -0
- data/lib/rubocop/cop/style/unpack_first.rb +1 -0
- data/lib/rubocop/cop/style/yoda_condition.rb +1 -0
- data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -0
- data/lib/rubocop/name_similarity.rb +1 -1
- data/lib/rubocop/target_ruby.rb +21 -13
- data/lib/rubocop/version.rb +1 -1
- metadata +9 -7
@@ -34,10 +34,12 @@ module RuboCop
|
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
|
+
# @!method node_type_check(node)
|
37
38
|
def_node_matcher :node_type_check, <<~PATTERN
|
38
39
|
(send nil? :add_offense $_node $hash)
|
39
40
|
PATTERN
|
40
41
|
|
42
|
+
# @!method offending_location_argument(node)
|
41
43
|
def_node_matcher :offending_location_argument, <<~PATTERN
|
42
44
|
(pair (sym :location) $(send (send $_node :loc) $_keyword))
|
43
45
|
PATTERN
|
@@ -23,6 +23,7 @@ module RuboCop
|
|
23
23
|
MSG = 'Redundant location argument to `#add_offense`.'
|
24
24
|
RESTRICT_ON_SEND = %i[add_offense].freeze
|
25
25
|
|
26
|
+
# @!method redundant_location_argument(node)
|
26
27
|
def_node_matcher :redundant_location_argument, <<~PATTERN
|
27
28
|
(send nil? :add_offense _
|
28
29
|
(hash <$(pair (sym :location) (sym :expression)) ...>)
|
@@ -26,16 +26,19 @@ module RuboCop
|
|
26
26
|
MSG = 'Redundant message argument to `#add_offense`.'
|
27
27
|
RESTRICT_ON_SEND = %i[add_offense].freeze
|
28
28
|
|
29
|
+
# @!method node_type_check(node)
|
29
30
|
def_node_matcher :node_type_check, <<~PATTERN
|
30
31
|
(send nil? :add_offense $_node $hash)
|
31
32
|
PATTERN
|
32
33
|
|
34
|
+
# @!method redundant_message_argument(node)
|
33
35
|
def_node_matcher :redundant_message_argument, <<~PATTERN
|
34
36
|
(pair
|
35
37
|
(sym :message)
|
36
38
|
${(const nil? :MSG) (send nil? :message) (send nil? :message _)})
|
37
39
|
PATTERN
|
38
40
|
|
41
|
+
# @!method message_method_call(node)
|
39
42
|
def_node_matcher :message_method_call, '(send nil? :message $_node)'
|
40
43
|
|
41
44
|
def on_send(node)
|
@@ -67,18 +67,22 @@ module RuboCop
|
|
67
67
|
no_acceptable_style! style_detected
|
68
68
|
].freeze
|
69
69
|
|
70
|
+
# @!method correct_style_detected_check(node)
|
70
71
|
def_node_matcher :correct_style_detected_check, <<~PATTERN
|
71
72
|
(send nil? :correct_style_detected)
|
72
73
|
PATTERN
|
73
74
|
|
75
|
+
# @!method negative_style_detected_method_check(node)
|
74
76
|
def_node_matcher :negative_style_detected_method_check, <<~PATTERN
|
75
77
|
(send nil? /(?:opposite|unexpected|ambiguous|unrecognized)_style_detected|conflicting_styles_detected/ ...)
|
76
78
|
PATTERN
|
77
79
|
|
80
|
+
# @!method no_acceptable_style_check(node)
|
78
81
|
def_node_matcher :no_acceptable_style_check, <<~PATTERN
|
79
82
|
(send nil? :no_acceptable_style!)
|
80
83
|
PATTERN
|
81
84
|
|
85
|
+
# @!method style_detected_check(node)
|
82
86
|
def_node_matcher :style_detected_check, <<~PATTERN
|
83
87
|
(send nil? :style_detected ...)
|
84
88
|
PATTERN
|
@@ -16,10 +16,12 @@ module RuboCop
|
|
16
16
|
class UselessMessageAssertion < Base
|
17
17
|
MSG = 'Do not specify cop behavior using `described_class::MSG`.'
|
18
18
|
|
19
|
+
# @!method described_class_msg(node)
|
19
20
|
def_node_search :described_class_msg, <<~PATTERN
|
20
21
|
(const (send nil? :described_class) :MSG)
|
21
22
|
PATTERN
|
22
23
|
|
24
|
+
# @!method rspec_expectation_on_msg?(node)
|
23
25
|
def_node_matcher :rspec_expectation_on_msg?, <<~PATTERN
|
24
26
|
(send (send nil? :expect #contains_described_class_msg?) :to ...)
|
25
27
|
PATTERN
|
@@ -11,12 +11,12 @@ module RuboCop
|
|
11
11
|
# name = "RuboCop"
|
12
12
|
# # Some comment and an empty line
|
13
13
|
#
|
14
|
-
# website += "/rubocop
|
14
|
+
# website += "/rubocop/rubocop" unless cond
|
15
15
|
# puts "rubocop" if debug
|
16
16
|
#
|
17
17
|
# # bad for any configuration
|
18
18
|
# set_app("RuboCop")
|
19
|
-
# website = "https://github.com/rubocop
|
19
|
+
# website = "https://github.com/rubocop/rubocop"
|
20
20
|
#
|
21
21
|
# # good only if AllowBeforeTrailingComments is true
|
22
22
|
# object.method(arg) # this is a comment
|
@@ -153,7 +153,7 @@ module RuboCop
|
|
153
153
|
|
154
154
|
def on_send(node)
|
155
155
|
return if style != :consistent && enforce_first_argument_with_fixed_indentation?
|
156
|
-
return if !node.arguments? || node
|
156
|
+
return if !node.arguments? || bare_operator?(node)
|
157
157
|
|
158
158
|
indent = base_indentation(node) + configured_indentation_width
|
159
159
|
|
@@ -167,6 +167,10 @@ module RuboCop
|
|
167
167
|
|
168
168
|
private
|
169
169
|
|
170
|
+
def bare_operator?(node)
|
171
|
+
node.operator_method? && !node.dot?
|
172
|
+
end
|
173
|
+
|
170
174
|
def message(arg_node)
|
171
175
|
return 'Bad indentation of the first argument.' unless arg_node
|
172
176
|
|
@@ -206,6 +210,7 @@ module RuboCop
|
|
206
210
|
node.source_range.begin_pos > parent.source_range.begin_pos
|
207
211
|
end
|
208
212
|
|
213
|
+
# @!method eligible_method_call?(node)
|
209
214
|
def_node_matcher :eligible_method_call?, <<~PATTERN
|
210
215
|
(send _ !:[]= ...)
|
211
216
|
PATTERN
|
@@ -61,7 +61,7 @@ module RuboCop
|
|
61
61
|
# by `EnforcedStyle: line_count_based` of `Style/BlockDelimiters` cop.
|
62
62
|
# That means preventing auto-correction to incorrect auto-corrected
|
63
63
|
# code.
|
64
|
-
# See: https://github.com/rubocop
|
64
|
+
# See: https://github.com/rubocop/rubocop/issues/7534
|
65
65
|
return if conflict_with_block_delimiters?(node)
|
66
66
|
|
67
67
|
left_brace = node.loc.begin
|
@@ -89,7 +89,7 @@ module RuboCop
|
|
89
89
|
# preventing auto-correction to single-line empty braces. It will
|
90
90
|
# conflict with auto-correction by `Layout/SpaceInsideBlockBraces` cop
|
91
91
|
# if auto-corrected to a single-line empty braces.
|
92
|
-
# See: https://github.com/rubocop
|
92
|
+
# See: https://github.com/rubocop/rubocop/issues/7363
|
93
93
|
return if node.body.nil? && node.multiline?
|
94
94
|
|
95
95
|
left_brace = node.loc.begin
|
@@ -66,10 +66,12 @@ module RuboCop
|
|
66
66
|
|
67
67
|
MSG = 'Do not define constants this way within a block.'
|
68
68
|
|
69
|
+
# @!method constant_assigned_in_block?(node)
|
69
70
|
def_node_matcher :constant_assigned_in_block?, <<~PATTERN
|
70
71
|
({^block_type? [^begin_type? ^^block_type?]} nil? ...)
|
71
72
|
PATTERN
|
72
73
|
|
74
|
+
# @!method module_defined_in_block?(node)
|
73
75
|
def_node_matcher :module_defined_in_block?, <<~PATTERN
|
74
76
|
({^block_type? [^begin_type? ^^block_type?]} ...)
|
75
77
|
PATTERN
|
@@ -58,6 +58,7 @@ module RuboCop
|
|
58
58
|
class ConstantResolution < Base
|
59
59
|
MSG = 'Fully qualify this constant to avoid possibly ambiguous resolution.'
|
60
60
|
|
61
|
+
# @!method unqualified_const?(node)
|
61
62
|
def_node_matcher :unqualified_const?, <<~PATTERN
|
62
63
|
(const nil? #const_name?)
|
63
64
|
PATTERN
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
# ----
|
17
17
|
# Lint/Debugger:
|
18
18
|
# WebConsole: ~
|
19
|
-
#
|
19
|
+
# ----
|
20
20
|
#
|
21
21
|
#
|
22
22
|
# @example
|
@@ -59,10 +59,12 @@ module RuboCop
|
|
59
59
|
|
60
60
|
RESTRICT_ON_SEND = [].freeze
|
61
61
|
|
62
|
+
# @!method kernel?(node)
|
62
63
|
def_node_matcher :kernel?, <<~PATTERN
|
63
64
|
(const {nil? cbase} :Kernel)
|
64
65
|
PATTERN
|
65
66
|
|
67
|
+
# @!method valid_receiver?(node, arg1)
|
66
68
|
def_node_matcher :valid_receiver?, <<~PATTERN
|
67
69
|
{
|
68
70
|
(const {nil? cbase} %1)
|
@@ -82,6 +82,7 @@ module RuboCop
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
# @!method method_alias?(node)
|
85
86
|
def_node_matcher :method_alias?, <<~PATTERN
|
86
87
|
(alias (sym $_name) sym)
|
87
88
|
PATTERN
|
@@ -94,10 +95,12 @@ module RuboCop
|
|
94
95
|
found_instance_method(node, name)
|
95
96
|
end
|
96
97
|
|
98
|
+
# @!method alias_method?(node)
|
97
99
|
def_node_matcher :alias_method?, <<~PATTERN
|
98
100
|
(send nil? :alias_method (sym $_name) _)
|
99
101
|
PATTERN
|
100
102
|
|
103
|
+
# @!method sym_name(node)
|
101
104
|
def_node_matcher :sym_name, '(sym $_name)'
|
102
105
|
def on_send(node)
|
103
106
|
if (name = alias_method?(node))
|
@@ -24,6 +24,7 @@ module RuboCop
|
|
24
24
|
REQUIRE_METHODS = Set.new(%i[require require_relative]).freeze
|
25
25
|
RESTRICT_ON_SEND = REQUIRE_METHODS
|
26
26
|
|
27
|
+
# @!method require_call?(node)
|
27
28
|
def_node_matcher :require_call?, <<~PATTERN
|
28
29
|
(send {nil? (const _ :Kernel)} %REQUIRE_METHODS _)
|
29
30
|
PATTERN
|
@@ -25,6 +25,7 @@ module RuboCop
|
|
25
25
|
MSG = 'The argument to each_with_object cannot be immutable.'
|
26
26
|
RESTRICT_ON_SEND = %i[each_with_object].freeze
|
27
27
|
|
28
|
+
# @!method each_with_object?(node)
|
28
29
|
def_node_matcher :each_with_object?, <<~PATTERN
|
29
30
|
({send csend} _ :each_with_object $_)
|
30
31
|
PATTERN
|
@@ -24,6 +24,7 @@ module RuboCop
|
|
24
24
|
|
25
25
|
MSG = 'Use `Hash#compare_by_identity` instead of using `object_id` for keys.'
|
26
26
|
|
27
|
+
# @!method id_as_hash_key?(node)
|
27
28
|
def_node_matcher :id_as_hash_key?, <<~PATTERN
|
28
29
|
(send _ {:key? :has_key? :fetch :[] :[]=} (send _ :object_id) ...)
|
29
30
|
PATTERN
|
@@ -25,6 +25,7 @@ module RuboCop
|
|
25
25
|
SET_OPERATION_OPERATORS = %i[& | ^].freeze
|
26
26
|
RESTRICT_ON_SEND = COMPARISON_METHODS
|
27
27
|
|
28
|
+
# @!method multiple_compare?(node)
|
28
29
|
def_node_matcher :multiple_compare?, <<~PATTERN
|
29
30
|
(send (send _ {:< :> :<= :>=} $_) {:#{COMPARISON_METHODS.join(' :')}} _)
|
30
31
|
PATTERN
|
@@ -81,14 +81,17 @@ module RuboCop
|
|
81
81
|
class_or_module_or_struct_new_call?(child)
|
82
82
|
end
|
83
83
|
|
84
|
+
# @!method eval_call?(node)
|
84
85
|
def_node_matcher :eval_call?, <<~PATTERN
|
85
86
|
(block (send _ {:instance_eval :class_eval :module_eval} ...) ...)
|
86
87
|
PATTERN
|
87
88
|
|
89
|
+
# @!method exec_call?(node)
|
88
90
|
def_node_matcher :exec_call?, <<~PATTERN
|
89
91
|
(block (send _ {:instance_exec :class_exec :module_exec} ...) ...)
|
90
92
|
PATTERN
|
91
93
|
|
94
|
+
# @!method class_or_module_or_struct_new_call?(node)
|
92
95
|
def_node_matcher :class_or_module_or_struct_new_call?, <<~PATTERN
|
93
96
|
(block (send (const {nil? cbase} {:Class :Module :Struct}) :new ...) ...)
|
94
97
|
PATTERN
|
@@ -25,6 +25,7 @@ module RuboCop
|
|
25
25
|
class NextWithoutAccumulator < Base
|
26
26
|
MSG = 'Use `next` with an accumulator argument in a `reduce`.'
|
27
27
|
|
28
|
+
# @!method on_body_of_reduce(node)
|
28
29
|
def_node_matcher :on_body_of_reduce, <<~PATTERN
|
29
30
|
(block (send _recv {:reduce :inject} !sym) _blockargs $(begin ...))
|
30
31
|
PATTERN
|
@@ -129,32 +129,39 @@ module RuboCop
|
|
129
129
|
unsorted_dir_glob_pass?(node) || unsorted_dir_each_pass?(node)
|
130
130
|
end
|
131
131
|
|
132
|
+
# @!method unsorted_dir_block?(node)
|
132
133
|
def_node_matcher :unsorted_dir_block?, <<~PATTERN
|
133
134
|
(send (const {nil? cbase} :Dir) :glob ...)
|
134
135
|
PATTERN
|
135
136
|
|
137
|
+
# @!method unsorted_dir_each?(node)
|
136
138
|
def_node_matcher :unsorted_dir_each?, <<~PATTERN
|
137
139
|
(send (send (const {nil? cbase} :Dir) {:[] :glob} ...) :each)
|
138
140
|
PATTERN
|
139
141
|
|
142
|
+
# @!method method_require?(node)
|
140
143
|
def_node_matcher :method_require?, <<~PATTERN
|
141
144
|
(block-pass (send nil? :method (sym :require)))
|
142
145
|
PATTERN
|
143
146
|
|
147
|
+
# @!method unsorted_dir_glob_pass?(node)
|
144
148
|
def_node_matcher :unsorted_dir_glob_pass?, <<~PATTERN
|
145
149
|
(send (const {nil? cbase} :Dir) :glob ...
|
146
150
|
(block-pass (send nil? :method (sym :require))))
|
147
151
|
PATTERN
|
148
152
|
|
153
|
+
# @!method unsorted_dir_each_pass?(node)
|
149
154
|
def_node_matcher :unsorted_dir_each_pass?, <<~PATTERN
|
150
155
|
(send (send (const {nil? cbase} :Dir) {:[] :glob} ...) :each
|
151
156
|
(block-pass (send nil? :method (sym :require))))
|
152
157
|
PATTERN
|
153
158
|
|
159
|
+
# @!method loop_variable(node)
|
154
160
|
def_node_matcher :loop_variable, <<~PATTERN
|
155
161
|
(args (arg $_))
|
156
162
|
PATTERN
|
157
163
|
|
164
|
+
# @!method var_is_required?(node, name)
|
158
165
|
def_node_search :var_is_required?, <<~PATTERN
|
159
166
|
(send nil? :require (lvar %1))
|
160
167
|
PATTERN
|