rubocop 1.57.1 → 1.65.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/LICENSE.txt +1 -1
- data/README.md +4 -5
- data/assets/output.css.erb +159 -0
- data/assets/output.html.erb +1 -160
- data/config/default.yml +136 -19
- data/lib/rubocop/cached_data.rb +11 -3
- data/lib/rubocop/cli/command/auto_generate_config.rb +22 -8
- data/lib/rubocop/cli/command/lsp.rb +2 -2
- data/lib/rubocop/cli/command/show_docs_url.rb +2 -2
- data/lib/rubocop/cli.rb +10 -1
- data/lib/rubocop/config.rb +36 -12
- data/lib/rubocop/config_finder.rb +12 -2
- data/lib/rubocop/config_loader.rb +1 -2
- data/lib/rubocop/config_loader_resolver.rb +9 -3
- data/lib/rubocop/config_obsoletion.rb +11 -8
- data/lib/rubocop/config_validator.rb +14 -7
- data/lib/rubocop/cop/autocorrect_logic.rb +6 -1
- data/lib/rubocop/cop/base.rb +63 -16
- data/lib/rubocop/cop/bundler/gem_comment.rb +2 -2
- data/lib/rubocop/cop/bundler/gem_version.rb +3 -5
- data/lib/rubocop/cop/cop.rb +20 -2
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +4 -8
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +5 -13
- data/lib/rubocop/cop/documentation.rb +16 -6
- data/lib/rubocop/cop/exclude_limit.rb +1 -1
- data/lib/rubocop/cop/force.rb +12 -0
- data/lib/rubocop/cop/gemspec/add_runtime_dependency.rb +38 -0
- data/lib/rubocop/cop/gemspec/dependency_version.rb +3 -5
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +5 -1
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +3 -3
- data/lib/rubocop/cop/internal_affairs/example_description.rb +6 -5
- data/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +8 -6
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +19 -20
- data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +53 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +123 -29
- data/lib/rubocop/cop/internal_affairs/redundant_expect_offense_arguments.rb +34 -0
- data/lib/rubocop/cop/internal_affairs.rb +2 -0
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/empty_comment.rb +3 -1
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +14 -7
- data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +1 -1
- data/lib/rubocop/cop/layout/end_alignment.rb +15 -3
- data/lib/rubocop/cop/layout/extra_spacing.rb +4 -10
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +24 -7
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +20 -20
- data/lib/rubocop/cop/layout/redundant_line_break.rb +16 -3
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +4 -4
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +5 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +53 -20
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +19 -10
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +3 -4
- data/lib/rubocop/cop/legacy/corrector.rb +12 -2
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +6 -6
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +2 -2
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +29 -3
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_case_condition.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -1
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +2 -2
- data/lib/rubocop/cop/lint/empty_when.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +24 -17
- data/lib/rubocop/cop/lint/float_comparison.rb +10 -0
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +2 -1
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +14 -7
- data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +56 -0
- data/lib/rubocop/cop/lint/literal_as_condition.rb +1 -1
- data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +85 -0
- data/lib/rubocop/cop/lint/mixed_case_range.rb +9 -4
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +6 -21
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +3 -5
- data/lib/rubocop/cop/lint/number_conversion.rb +9 -4
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +54 -6
- data/lib/rubocop/cop/lint/redundant_with_index.rb +6 -2
- data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
- data/lib/rubocop/cop/lint/rescue_type.rb +1 -3
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +3 -4
- data/lib/rubocop/cop/lint/script_permission.rb +3 -3
- data/lib/rubocop/cop/lint/self_assignment.rb +38 -0
- data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
- data/lib/rubocop/cop/lint/symbol_conversion.rb +7 -2
- data/lib/rubocop/cop/lint/syntax.rb +6 -3
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -3
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -1
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +3 -2
- data/lib/rubocop/cop/lint/unreachable_code.rb +4 -2
- data/lib/rubocop/cop/lint/unreachable_loop.rb +8 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -2
- data/lib/rubocop/cop/lint/useless_times.rb +2 -2
- data/lib/rubocop/cop/lint/void.rb +53 -12
- data/lib/rubocop/cop/metrics/abc_size.rb +3 -3
- data/lib/rubocop/cop/metrics/block_nesting.rb +19 -7
- data/lib/rubocop/cop/metrics/class_length.rb +6 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +5 -5
- data/lib/rubocop/cop/mixin/alignment.rb +5 -1
- data/lib/rubocop/cop/mixin/allowed_methods.rb +7 -1
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +15 -3
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/code_length.rb +12 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +16 -12
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -0
- data/lib/rubocop/cop/mixin/configurable_max.rb +5 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +23 -13
- data/lib/rubocop/cop/mixin/method_complexity.rb +15 -6
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/rescue_node.rb +4 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +1 -1
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +34 -7
- data/lib/rubocop/cop/naming/constant_name.rb +1 -2
- data/lib/rubocop/cop/naming/file_name.rb +2 -2
- data/lib/rubocop/cop/naming/inclusive_language.rb +1 -2
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +2 -2
- data/lib/rubocop/cop/registry.rb +1 -1
- data/lib/rubocop/cop/security/compound_hash.rb +2 -2
- data/lib/rubocop/cop/security/open.rb +2 -2
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +52 -2
- data/lib/rubocop/cop/style/accessor_grouping.rb +1 -1
- data/lib/rubocop/cop/style/alias.rb +1 -0
- data/lib/rubocop/cop/style/arguments_forwarding.rb +155 -21
- data/lib/rubocop/cop/style/array_first_last.rb +64 -0
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +21 -14
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +2 -2
- data/lib/rubocop/cop/style/case_like_if.rb +5 -5
- data/lib/rubocop/cop/style/class_check.rb +1 -0
- data/lib/rubocop/cop/style/class_vars.rb +3 -3
- data/lib/rubocop/cop/style/collection_compact.rb +21 -11
- data/lib/rubocop/cop/style/combinable_loops.rb +13 -7
- data/lib/rubocop/cop/style/commented_keyword.rb +5 -2
- data/lib/rubocop/cop/style/concat_array_literals.rb +1 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +7 -8
- data/lib/rubocop/cop/style/copyright.rb +31 -21
- data/lib/rubocop/cop/style/date_time.rb +5 -4
- data/lib/rubocop/cop/style/documentation.rb +24 -24
- data/lib/rubocop/cop/style/documentation_method.rb +20 -0
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +7 -7
- data/lib/rubocop/cop/style/each_with_object.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +6 -15
- data/lib/rubocop/cop/style/exact_regexp_match.rb +4 -2
- data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -2
- data/lib/rubocop/cop/style/for.rb +2 -0
- data/lib/rubocop/cop/style/format_string.rb +9 -9
- data/lib/rubocop/cop/style/hash_each_methods.rb +105 -11
- data/lib/rubocop/cop/style/hash_except.rb +10 -6
- data/lib/rubocop/cop/style/hash_syntax.rb +24 -2
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +12 -1
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +5 -3
- data/lib/rubocop/cop/style/inverse_methods.rb +14 -13
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +44 -2
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +82 -50
- data/lib/rubocop/cop/style/map_into_array.rb +175 -0
- data/lib/rubocop/cop/style/map_to_hash.rb +18 -8
- data/lib/rubocop/cop/style/map_to_set.rb +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +19 -5
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +20 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/missing_respond_to_missing.rb +2 -2
- data/lib/rubocop/cop/style/multiline_method_signature.rb +10 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +5 -3
- data/lib/rubocop/cop/style/next.rb +1 -1
- data/lib/rubocop/cop/style/nil_comparison.rb +2 -0
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +10 -2
- data/lib/rubocop/cop/style/object_then.rb +5 -3
- data/lib/rubocop/cop/style/one_line_conditional.rb +1 -1
- data/lib/rubocop/cop/style/operator_method_call.rb +2 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +3 -5
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -0
- data/lib/rubocop/cop/style/quoted_symbols.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +4 -1
- data/lib/rubocop/cop/style/redundant_argument.rb +27 -3
- data/lib/rubocop/cop/style/redundant_assignment.rb +10 -2
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +5 -4
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +17 -10
- data/lib/rubocop/cop/style/redundant_each.rb +7 -4
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +3 -3
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -1
- data/lib/rubocop/cop/style/redundant_filter_chain.rb +5 -4
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +19 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +50 -19
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +7 -1
- data/lib/rubocop/cop/style/redundant_self.rb +17 -2
- data/lib/rubocop/cop/style/redundant_sort.rb +9 -8
- data/lib/rubocop/cop/style/redundant_sort_by.rb +2 -2
- data/lib/rubocop/cop/style/redundant_string_escape.rb +1 -1
- data/lib/rubocop/cop/style/require_order.rb +1 -1
- data/lib/rubocop/cop/style/sample.rb +3 -4
- data/lib/rubocop/cop/style/select_by_regexp.rb +7 -6
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +8 -0
- data/lib/rubocop/cop/style/send.rb +4 -4
- data/lib/rubocop/cop/style/send_with_literal_method_name.rb +104 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +7 -3
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +3 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +76 -10
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -2
- data/lib/rubocop/cop/style/string_chars.rb +1 -0
- data/lib/rubocop/cop/style/strip.rb +7 -4
- data/lib/rubocop/cop/style/super_arguments.rb +174 -0
- data/lib/rubocop/cop/style/super_with_args_parentheses.rb +35 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +75 -5
- data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +11 -14
- data/lib/rubocop/cop/style/zero_length_predicate.rb +28 -24
- data/lib/rubocop/cop/team.rb +13 -0
- data/lib/rubocop/cop/util.rb +7 -1
- data/lib/rubocop/cop/utils/regexp_ranges.rb +1 -1
- data/lib/rubocop/cops_documentation_generator.rb +16 -4
- data/lib/rubocop/directive_comment.rb +10 -8
- data/lib/rubocop/ext/regexp_node.rb +9 -4
- data/lib/rubocop/ext/regexp_parser.rb +4 -21
- data/lib/rubocop/formatter/clang_style_formatter.rb +3 -7
- data/lib/rubocop/formatter/disabled_config_formatter.rb +23 -8
- data/lib/rubocop/formatter/formatter_set.rb +7 -1
- data/lib/rubocop/formatter/html_formatter.rb +37 -14
- data/lib/rubocop/formatter/json_formatter.rb +0 -1
- data/lib/rubocop/formatter/offense_count_formatter.rb +12 -2
- data/lib/rubocop/formatter/tap_formatter.rb +3 -7
- data/lib/rubocop/formatter.rb +1 -1
- data/lib/rubocop/lockfile.rb +56 -7
- data/lib/rubocop/lsp/logger.rb +1 -1
- data/lib/rubocop/lsp/routes.rb +12 -15
- data/lib/rubocop/lsp/runtime.rb +1 -1
- data/lib/rubocop/lsp/server.rb +7 -2
- data/lib/rubocop/lsp/severity.rb +1 -1
- data/lib/rubocop/lsp.rb +36 -0
- data/lib/rubocop/magic_comment.rb +1 -1
- data/lib/rubocop/options.rb +14 -11
- data/lib/rubocop/path_util.rb +6 -2
- data/lib/rubocop/rake_task.rb +1 -1
- data/lib/rubocop/result_cache.rb +0 -1
- data/lib/rubocop/rspec/cop_helper.rb +8 -2
- data/lib/rubocop/rspec/expect_offense.rb +16 -8
- data/lib/rubocop/rspec/shared_contexts.rb +73 -16
- data/lib/rubocop/rspec/support.rb +3 -0
- data/lib/rubocop/runner.rb +14 -3
- data/lib/rubocop/server/cache.rb +11 -2
- data/lib/rubocop/server/client_command/exec.rb +2 -3
- data/lib/rubocop/server/client_command/start.rb +1 -1
- data/lib/rubocop/server/core.rb +4 -0
- data/lib/rubocop/server/server_command/exec.rb +0 -1
- data/lib/rubocop/target_finder.rb +84 -78
- data/lib/rubocop/target_ruby.rb +82 -80
- data/lib/rubocop/version.rb +19 -4
- data/lib/rubocop.rb +8 -0
- metadata +27 -29
- /data/lib/rubocop/formatter/{git_hub_actions_formatter.rb → github_actions_formatter.rb} +0 -0
|
@@ -6,10 +6,10 @@ module RuboCop
|
|
|
6
6
|
# Checks for places where binary operator has identical operands.
|
|
7
7
|
#
|
|
8
8
|
# It covers arithmetic operators: `-`, `/`, `%`;
|
|
9
|
-
# comparison operators: `==`, `===`, `=~`, `>`, `>=`, `<`,
|
|
9
|
+
# comparison operators: `==`, `===`, `=~`, `>`, `>=`, `<`, ``<=``;
|
|
10
10
|
# bitwise operators: `|`, `^`, `&`;
|
|
11
11
|
# boolean operators: `&&`, `||`
|
|
12
|
-
# and "spaceship" operator -
|
|
12
|
+
# and "spaceship" operator - ``<=>``.
|
|
13
13
|
#
|
|
14
14
|
# Simple arithmetic operations are allowed by this cop: `+`, `*`, `**`, `<<` and `>>`.
|
|
15
15
|
# Although these can be rewritten in a different way, it should not be necessary to
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
module Cop
|
|
5
5
|
module Lint
|
|
6
|
-
# Checks for overwriting an exception with an exception result by use
|
|
6
|
+
# Checks for overwriting an exception with an exception result by use ``rescue =>``.
|
|
7
7
|
#
|
|
8
8
|
# You intended to write as `rescue StandardError`.
|
|
9
9
|
# However, you have written `rescue => StandardError`.
|
|
@@ -29,6 +29,11 @@ module RuboCop
|
|
|
29
29
|
# MyDebugger.debug_this
|
|
30
30
|
# ----
|
|
31
31
|
#
|
|
32
|
+
# Some gems also ship files that will start a debugging session when required,
|
|
33
|
+
# for example `require 'debug/start'` from `ruby/debug`. These requires can
|
|
34
|
+
# be configured through `DebuggerRequires`. It has the same structure as
|
|
35
|
+
# `DebuggerMethods`, which you can read about above.
|
|
36
|
+
#
|
|
32
37
|
# @example
|
|
33
38
|
#
|
|
34
39
|
# # bad (ok during development)
|
|
@@ -64,13 +69,20 @@ module RuboCop
|
|
|
64
69
|
# def some_method
|
|
65
70
|
# my_debugger
|
|
66
71
|
# end
|
|
72
|
+
#
|
|
73
|
+
# @example DebuggerRequires: [my_debugger/start]
|
|
74
|
+
#
|
|
75
|
+
# # bad (ok during development)
|
|
76
|
+
#
|
|
77
|
+
# require 'my_debugger/start'
|
|
67
78
|
class Debugger < Base
|
|
68
79
|
MSG = 'Remove debugger entry point `%<source>s`.'
|
|
80
|
+
BLOCK_TYPES = %i[block numblock kwbegin].freeze
|
|
69
81
|
|
|
70
82
|
def on_send(node)
|
|
71
|
-
return if
|
|
83
|
+
return if assumed_usage_context?(node)
|
|
72
84
|
|
|
73
|
-
add_offense(node)
|
|
85
|
+
add_offense(node) if debugger_method?(node) || debugger_require?(node)
|
|
74
86
|
end
|
|
75
87
|
|
|
76
88
|
private
|
|
@@ -86,19 +98,33 @@ module RuboCop
|
|
|
86
98
|
end
|
|
87
99
|
end
|
|
88
100
|
|
|
101
|
+
def debugger_requires
|
|
102
|
+
@debugger_requires ||= begin
|
|
103
|
+
config = cop_config.fetch('DebuggerRequires', [])
|
|
104
|
+
config.is_a?(Array) ? config : config.values.flatten
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
89
108
|
def debugger_method?(send_node)
|
|
90
109
|
return false if send_node.parent&.send_type? && send_node.parent.receiver == send_node
|
|
91
110
|
|
|
92
111
|
debugger_methods.include?(chained_method_name(send_node))
|
|
93
112
|
end
|
|
94
113
|
|
|
114
|
+
def debugger_require?(send_node)
|
|
115
|
+
return false unless send_node.method?(:require) && send_node.arguments.one?
|
|
116
|
+
return false unless (argument = send_node.first_argument).str_type?
|
|
117
|
+
|
|
118
|
+
debugger_requires.include?(argument.value)
|
|
119
|
+
end
|
|
120
|
+
|
|
95
121
|
def assumed_usage_context?(node)
|
|
96
122
|
# Basically, debugger methods are not used as a method argument without arguments.
|
|
97
123
|
return false unless node.arguments.empty? && node.each_ancestor(:send, :csend).any?
|
|
98
124
|
return true if assumed_argument?(node)
|
|
99
125
|
|
|
100
126
|
node.each_ancestor.none? do |ancestor|
|
|
101
|
-
|
|
127
|
+
BLOCK_TYPES.include?(ancestor.type) || ancestor.lambda_or_proc?
|
|
102
128
|
end
|
|
103
129
|
end
|
|
104
130
|
|
|
@@ -52,7 +52,7 @@ module RuboCop
|
|
|
52
52
|
# @!method deprecated_class_method?(node)
|
|
53
53
|
def_node_matcher :deprecated_class_method?, <<~PATTERN
|
|
54
54
|
{
|
|
55
|
-
(send (const {cbase nil?}
|
|
55
|
+
(send (const {cbase nil?} :ENV) {:clone :dup :freeze})
|
|
56
56
|
(send (const {cbase nil?} {:File :Dir}) :exists? _)
|
|
57
57
|
(send (const {cbase nil?} :Socket) {:gethostbyaddr :gethostbyname} ...)
|
|
58
58
|
(send nil? :attr _ boolean)
|
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
|
32
32
|
|
|
33
33
|
def on_case(case_node)
|
|
34
34
|
case_node.when_branches.each_with_object(Set.new) do |when_node, previous|
|
|
35
|
-
when_node.
|
|
35
|
+
when_node.conditions.each do |condition|
|
|
36
36
|
add_offense(condition) unless previous.add?(condition)
|
|
37
37
|
end
|
|
38
38
|
end
|
|
@@ -253,7 +253,7 @@ module RuboCop
|
|
|
253
253
|
# Assume that if a method definition is inside any block call which
|
|
254
254
|
# we can't identify, it could be a DSL
|
|
255
255
|
node.each_ancestor(:block).any? do |ancestor|
|
|
256
|
-
ancestor.
|
|
256
|
+
!ancestor.method?(:class_eval) && !ancestor.class_constructor?
|
|
257
257
|
end
|
|
258
258
|
end
|
|
259
259
|
|
|
@@ -104,7 +104,7 @@ module RuboCop
|
|
|
104
104
|
def correct_other_branches(corrector, node)
|
|
105
105
|
return unless require_other_branches_correction?(node)
|
|
106
106
|
|
|
107
|
-
if node.else_branch&.if_type?
|
|
107
|
+
if node.else_branch&.if_type? && !node.else_branch.modifier_form?
|
|
108
108
|
# Replace an orphaned `elsif` with `if`
|
|
109
109
|
corrector.replace(node.else_branch.loc.keyword, 'if')
|
|
110
110
|
else
|
|
@@ -146,7 +146,7 @@ module RuboCop
|
|
|
146
146
|
node.source_range.with(end_pos: node.condition.source_range.end_pos)
|
|
147
147
|
elsif all_branches_body_missing?(node)
|
|
148
148
|
if_node = node.ancestors.detect(&:if?)
|
|
149
|
-
node.source_range.
|
|
149
|
+
node.source_range.join(if_node.loc.end.end)
|
|
150
150
|
else
|
|
151
151
|
node.source_range
|
|
152
152
|
end
|
|
@@ -50,7 +50,7 @@ module RuboCop
|
|
|
50
50
|
MSG = 'Avoid `when` branches without a body.'
|
|
51
51
|
|
|
52
52
|
def on_case(node)
|
|
53
|
-
node.
|
|
53
|
+
node.when_branches.each do |when_node|
|
|
54
54
|
next if when_node.body
|
|
55
55
|
next if cop_config['AllowComments'] && contains_comments?(when_node)
|
|
56
56
|
|
|
@@ -65,17 +65,15 @@ module RuboCop
|
|
|
65
65
|
|
|
66
66
|
minimum_target_ruby_version 2.6
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
'`ERB.new(str, eoutvar: %<arg_value>s)` instead.'
|
|
78
|
-
].freeze
|
|
68
|
+
MESSAGE_SAFE_LEVEL = 'Passing safe_level with the 2nd argument of `ERB.new` is ' \
|
|
69
|
+
'deprecated. Do not use it, and specify other arguments as ' \
|
|
70
|
+
'keyword arguments.'
|
|
71
|
+
MESSAGE_TRIM_MODE = 'Passing trim_mode with the 3rd argument of `ERB.new` is ' \
|
|
72
|
+
'deprecated. Use keyword argument like ' \
|
|
73
|
+
'`ERB.new(str, trim_mode: %<arg_value>s)` instead.'
|
|
74
|
+
MESSAGE_EOUTVAR = 'Passing eoutvar with the 4th argument of `ERB.new` is ' \
|
|
75
|
+
'deprecated. Use keyword argument like ' \
|
|
76
|
+
'`ERB.new(str, eoutvar: %<arg_value>s)` instead.'
|
|
79
77
|
|
|
80
78
|
RESTRICT_ON_SEND = %i[new].freeze
|
|
81
79
|
|
|
@@ -92,10 +90,8 @@ module RuboCop
|
|
|
92
90
|
arguments[1..3].each_with_index do |argument, i|
|
|
93
91
|
next if !argument || argument.hash_type?
|
|
94
92
|
|
|
95
|
-
message = format(MESSAGES[i], arg_value: argument.source)
|
|
96
|
-
|
|
97
93
|
add_offense(
|
|
98
|
-
argument.source_range, message: message
|
|
94
|
+
argument.source_range, message: message(i, argument.source)
|
|
99
95
|
) do |corrector|
|
|
100
96
|
autocorrect(corrector, node)
|
|
101
97
|
end
|
|
@@ -105,8 +101,19 @@ module RuboCop
|
|
|
105
101
|
|
|
106
102
|
private
|
|
107
103
|
|
|
104
|
+
def message(positional_argument_index, arg_value)
|
|
105
|
+
case positional_argument_index
|
|
106
|
+
when 0
|
|
107
|
+
MESSAGE_SAFE_LEVEL
|
|
108
|
+
when 1
|
|
109
|
+
format(MESSAGE_TRIM_MODE, arg_value: arg_value)
|
|
110
|
+
when 2
|
|
111
|
+
format(MESSAGE_EOUTVAR, arg_value: arg_value)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
108
115
|
def autocorrect(corrector, node)
|
|
109
|
-
str_arg = node.
|
|
116
|
+
str_arg = node.first_argument.source
|
|
110
117
|
|
|
111
118
|
kwargs = build_kwargs(node)
|
|
112
119
|
overridden_kwargs = override_by_legacy_args(kwargs, node)
|
|
@@ -121,11 +128,11 @@ module RuboCop
|
|
|
121
128
|
end
|
|
122
129
|
|
|
123
130
|
def build_kwargs(node)
|
|
124
|
-
return [nil, nil] unless node.
|
|
131
|
+
return [nil, nil] unless node.last_argument.hash_type?
|
|
125
132
|
|
|
126
133
|
trim_mode_arg, eoutvar_arg = nil
|
|
127
134
|
|
|
128
|
-
node.
|
|
135
|
+
node.last_argument.pairs.each do |pair|
|
|
129
136
|
case pair.key.source
|
|
130
137
|
when 'trim_mode'
|
|
131
138
|
trim_mode_arg = "trim_mode: #{pair.value.source}"
|
|
@@ -18,6 +18,10 @@ module RuboCop
|
|
|
18
18
|
# # good - using BigDecimal
|
|
19
19
|
# x.to_d == 0.1.to_d
|
|
20
20
|
#
|
|
21
|
+
# # good - comparing against zero
|
|
22
|
+
# x == 0.0
|
|
23
|
+
# x != 0.0
|
|
24
|
+
#
|
|
21
25
|
# # good
|
|
22
26
|
# (x - 0.1).abs < Float::EPSILON
|
|
23
27
|
#
|
|
@@ -39,6 +43,8 @@ module RuboCop
|
|
|
39
43
|
|
|
40
44
|
def on_send(node)
|
|
41
45
|
lhs, _method, rhs = *node
|
|
46
|
+
return if literal_zero?(lhs) || literal_zero?(rhs)
|
|
47
|
+
|
|
42
48
|
add_offense(node) if float?(lhs) || float?(rhs)
|
|
43
49
|
end
|
|
44
50
|
|
|
@@ -59,6 +65,10 @@ module RuboCop
|
|
|
59
65
|
end
|
|
60
66
|
end
|
|
61
67
|
|
|
68
|
+
def literal_zero?(node)
|
|
69
|
+
node&.numeric_type? && node.value.zero?
|
|
70
|
+
end
|
|
71
|
+
|
|
62
72
|
# rubocop:disable Metrics/PerceivedComplexity
|
|
63
73
|
def check_send(node)
|
|
64
74
|
if node.arithmetic_operation?
|
|
@@ -35,12 +35,13 @@ module RuboCop
|
|
|
35
35
|
|
|
36
36
|
# @!method id_as_hash_key?(node)
|
|
37
37
|
def_node_matcher :id_as_hash_key?, <<~PATTERN
|
|
38
|
-
(
|
|
38
|
+
(call _ {:key? :has_key? :fetch :[] :[]=} (send _ :object_id) ...)
|
|
39
39
|
PATTERN
|
|
40
40
|
|
|
41
41
|
def on_send(node)
|
|
42
42
|
add_offense(node) if id_as_hash_key?(node)
|
|
43
43
|
end
|
|
44
|
+
alias on_csend on_send
|
|
44
45
|
end
|
|
45
46
|
end
|
|
46
47
|
end
|
|
@@ -23,27 +23,34 @@ module RuboCop
|
|
|
23
23
|
# 'Item 2'
|
|
24
24
|
# ]
|
|
25
25
|
class ImplicitStringConcatenation < Base
|
|
26
|
-
|
|
26
|
+
extend AutoCorrector
|
|
27
|
+
|
|
28
|
+
MSG = 'Combine %<lhs>s and %<rhs>s into a single string ' \
|
|
27
29
|
'literal, rather than using implicit string concatenation.'
|
|
28
30
|
FOR_ARRAY = ' Or, if they were intended to be separate array ' \
|
|
29
31
|
'elements, separate them with a comma.'
|
|
30
32
|
FOR_METHOD = ' Or, if they were intended to be separate method ' \
|
|
31
33
|
'arguments, separate them with a comma.'
|
|
32
34
|
|
|
35
|
+
# rubocop:disable Metrics/AbcSize
|
|
33
36
|
def on_dstr(node)
|
|
34
|
-
each_bad_cons(node) do |
|
|
35
|
-
range
|
|
36
|
-
message = format(MSG,
|
|
37
|
-
string1: display_str(child_node1),
|
|
38
|
-
string2: display_str(child_node2))
|
|
37
|
+
each_bad_cons(node) do |lhs_node, rhs_node|
|
|
38
|
+
range = lhs_node.source_range.join(rhs_node.source_range)
|
|
39
|
+
message = format(MSG, lhs: display_str(lhs_node), rhs: display_str(rhs_node))
|
|
39
40
|
if node.parent&.array_type?
|
|
40
41
|
message << FOR_ARRAY
|
|
41
42
|
elsif node.parent&.send_type?
|
|
42
43
|
message << FOR_METHOD
|
|
43
44
|
end
|
|
44
|
-
|
|
45
|
+
|
|
46
|
+
add_offense(range, message: message) do |corrector|
|
|
47
|
+
preferred = "#{lhs_node.source} + #{rhs_node.source}"
|
|
48
|
+
|
|
49
|
+
corrector.replace(range, preferred)
|
|
50
|
+
end
|
|
45
51
|
end
|
|
46
52
|
end
|
|
53
|
+
# rubocop:enable Metrics/AbcSize
|
|
47
54
|
|
|
48
55
|
private
|
|
49
56
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Lint
|
|
6
|
+
# Emulates the following Ruby warning in Ruby 3.3.
|
|
7
|
+
#
|
|
8
|
+
# [source,ruby]
|
|
9
|
+
# ----
|
|
10
|
+
# $ ruby -e '0.times { it }'
|
|
11
|
+
# -e:1: warning: `it` calls without arguments will refer to the first block param in Ruby 3.4;
|
|
12
|
+
# use it() or self.it
|
|
13
|
+
# ----
|
|
14
|
+
#
|
|
15
|
+
# `it` calls without arguments will refer to the first block param in Ruby 3.4.
|
|
16
|
+
# So use `it()` or `self.it` to ensure compatibility.
|
|
17
|
+
#
|
|
18
|
+
# @example
|
|
19
|
+
#
|
|
20
|
+
# # bad
|
|
21
|
+
# do_something { it }
|
|
22
|
+
#
|
|
23
|
+
# # good
|
|
24
|
+
# do_something { it() }
|
|
25
|
+
# do_something { self.it }
|
|
26
|
+
#
|
|
27
|
+
class ItWithoutArgumentsInBlock < Base
|
|
28
|
+
include NodePattern::Macros
|
|
29
|
+
|
|
30
|
+
MSG = '`it` calls without arguments will refer to the first block param in Ruby 3.4; ' \
|
|
31
|
+
'use `it()` or `self.it`.'
|
|
32
|
+
|
|
33
|
+
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
|
|
34
|
+
return unless (body = node.body)
|
|
35
|
+
return unless node.arguments.empty_and_without_delimiters?
|
|
36
|
+
|
|
37
|
+
if body.send_type? && deprecated_it_method?(body)
|
|
38
|
+
add_offense(body)
|
|
39
|
+
else
|
|
40
|
+
body.each_descendant(:send).each do |send_node|
|
|
41
|
+
next unless deprecated_it_method?(send_node)
|
|
42
|
+
|
|
43
|
+
add_offense(send_node)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def deprecated_it_method?(node)
|
|
49
|
+
return false unless node.method?(:it)
|
|
50
|
+
|
|
51
|
+
!node.receiver && node.arguments.empty? && !node.parenthesized? && !node.block_literal?
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Lint
|
|
6
|
+
# Checks for literal assignments in the conditions of `if`, `while`, and `until`.
|
|
7
|
+
# It emulates the following Ruby warning:
|
|
8
|
+
#
|
|
9
|
+
# [source,console]
|
|
10
|
+
# ----
|
|
11
|
+
# $ ruby -we 'if x = true; end'
|
|
12
|
+
# -e:1: warning: found `= literal' in conditional, should be ==
|
|
13
|
+
# ----
|
|
14
|
+
#
|
|
15
|
+
# As a lint cop, it cannot be determined if `==` is appropriate as intended,
|
|
16
|
+
# therefore this cop does not provide autocorrection.
|
|
17
|
+
#
|
|
18
|
+
# @example
|
|
19
|
+
#
|
|
20
|
+
# # bad
|
|
21
|
+
# if x = 42
|
|
22
|
+
# do_something
|
|
23
|
+
# end
|
|
24
|
+
#
|
|
25
|
+
# # good
|
|
26
|
+
# if x == 42
|
|
27
|
+
# do_something
|
|
28
|
+
# end
|
|
29
|
+
#
|
|
30
|
+
# # good
|
|
31
|
+
# if x = y
|
|
32
|
+
# do_something
|
|
33
|
+
# end
|
|
34
|
+
#
|
|
35
|
+
class LiteralAssignmentInCondition < Base
|
|
36
|
+
MSG = "Don't use literal assignment `= %<literal>s` in conditional, " \
|
|
37
|
+
'should be `==` or non-literal operand.'
|
|
38
|
+
|
|
39
|
+
def on_if(node)
|
|
40
|
+
traverse_node(node.condition) do |asgn_node|
|
|
41
|
+
next unless asgn_node.loc.operator
|
|
42
|
+
|
|
43
|
+
rhs = asgn_node.to_a.last
|
|
44
|
+
next if !all_literals?(rhs) || parallel_assignment_with_splat_operator?(rhs)
|
|
45
|
+
|
|
46
|
+
range = offense_range(asgn_node, rhs)
|
|
47
|
+
|
|
48
|
+
add_offense(range, message: format(MSG, literal: rhs.source))
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
alias on_while on_if
|
|
52
|
+
alias on_until on_if
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def traverse_node(node, &block)
|
|
57
|
+
yield node if AST::Node::EQUALS_ASSIGNMENTS.include?(node.type)
|
|
58
|
+
|
|
59
|
+
node.each_child_node { |child| traverse_node(child, &block) }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def all_literals?(node)
|
|
63
|
+
case node.type
|
|
64
|
+
when :dstr, :xstr
|
|
65
|
+
false
|
|
66
|
+
when :array
|
|
67
|
+
node.values.all? { |value| all_literals?(value) }
|
|
68
|
+
when :hash
|
|
69
|
+
(node.values + node.keys).all? { |item| all_literals?(item) }
|
|
70
|
+
else
|
|
71
|
+
node.respond_to?(:literal?) && node.literal?
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def parallel_assignment_with_splat_operator?(node)
|
|
76
|
+
node.array_type? && node.values.first&.splat_type?
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def offense_range(asgn_node, rhs)
|
|
80
|
+
asgn_node.loc.operator.join(rhs.source_range.end)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -47,8 +47,10 @@ module RuboCop
|
|
|
47
47
|
|
|
48
48
|
def on_regexp(node)
|
|
49
49
|
each_unsafe_regexp_range(node) do |loc|
|
|
50
|
+
next unless (replacement = regexp_range(loc.source))
|
|
51
|
+
|
|
50
52
|
add_offense(loc) do |corrector|
|
|
51
|
-
corrector.replace(loc,
|
|
53
|
+
corrector.replace(loc, replacement)
|
|
52
54
|
end
|
|
53
55
|
end
|
|
54
56
|
end
|
|
@@ -99,10 +101,13 @@ module RuboCop
|
|
|
99
101
|
end
|
|
100
102
|
end
|
|
101
103
|
|
|
102
|
-
def
|
|
104
|
+
def regexp_range(source)
|
|
103
105
|
open, close = source.split('-')
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
return unless (open_range = range_for(open))
|
|
107
|
+
return unless (close_range = range_for(close))
|
|
108
|
+
|
|
109
|
+
first = [open, open_range.end]
|
|
110
|
+
second = [close_range.begin, close]
|
|
106
111
|
"#{first.uniq.join('-')}#{second.uniq.join('-')}"
|
|
107
112
|
end
|
|
108
113
|
end
|
|
@@ -102,7 +102,7 @@ module RuboCop
|
|
|
102
102
|
|
|
103
103
|
def on_def(node)
|
|
104
104
|
subject, = *node
|
|
105
|
-
return if node.defs_type? && subject.
|
|
105
|
+
return if node.defs_type? && subject.variable?
|
|
106
106
|
|
|
107
107
|
def_ancestor = node.each_ancestor(:def, :defs).first
|
|
108
108
|
return unless def_ancestor
|
|
@@ -34,35 +34,20 @@ module RuboCop
|
|
|
34
34
|
add_offense(void_next) if void_next
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
|
-
|
|
38
|
-
def on_numblock(node)
|
|
39
|
-
on_numblock_body_of_reduce(node) do |body|
|
|
40
|
-
void_next = body.each_node(:next).find do |n|
|
|
41
|
-
n.children.empty? && parent_numblock_node(n) == node
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
add_offense(void_next) if void_next
|
|
45
|
-
end
|
|
46
|
-
end
|
|
37
|
+
alias on_numblock on_block
|
|
47
38
|
|
|
48
39
|
private
|
|
49
40
|
|
|
50
41
|
# @!method on_block_body_of_reduce(node)
|
|
51
42
|
def_node_matcher :on_block_body_of_reduce, <<~PATTERN
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def_node_matcher :on_numblock_body_of_reduce, <<~PATTERN
|
|
57
|
-
(numblock (send _recv {:reduce :inject} !sym) _argscount $(begin ...))
|
|
43
|
+
{
|
|
44
|
+
(block (call _recv {:reduce :inject} !sym) _blockargs $(begin ...))
|
|
45
|
+
(numblock (call _recv {:reduce :inject} !sym) _argscount $(begin ...))
|
|
46
|
+
}
|
|
58
47
|
PATTERN
|
|
59
48
|
|
|
60
49
|
def parent_block_node(node)
|
|
61
|
-
node.each_ancestor(:block).first
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def parent_numblock_node(node)
|
|
65
|
-
node.each_ancestor(:numblock).first
|
|
50
|
+
node.each_ancestor(:block, :numblock).first
|
|
66
51
|
end
|
|
67
52
|
end
|
|
68
53
|
end
|
|
@@ -94,7 +94,7 @@ module RuboCop
|
|
|
94
94
|
parent_node = node.parent
|
|
95
95
|
|
|
96
96
|
add_offense(parent_node) do |corrector|
|
|
97
|
-
if parent_node.
|
|
97
|
+
if parent_node.last_argument&.block_pass_type?
|
|
98
98
|
correct_block_pass(corrector, parent_node)
|
|
99
99
|
else
|
|
100
100
|
correct_block(corrector, parent_node)
|
|
@@ -116,7 +116,7 @@ module RuboCop
|
|
|
116
116
|
|
|
117
117
|
def correct_block_pass(corrector, node)
|
|
118
118
|
if unsorted_dir_glob_pass?(node)
|
|
119
|
-
block_arg = node.
|
|
119
|
+
block_arg = node.last_argument
|
|
120
120
|
|
|
121
121
|
corrector.remove(last_arg_range(node))
|
|
122
122
|
corrector.insert_after(node, ".sort.each(#{block_arg.source})")
|
|
@@ -130,9 +130,7 @@ module RuboCop
|
|
|
130
130
|
# @return [Parser::Source::Range]
|
|
131
131
|
#
|
|
132
132
|
def last_arg_range(node)
|
|
133
|
-
node.arguments.
|
|
134
|
-
begin_pos: node.arguments[-2].source_range.end_pos
|
|
135
|
-
)
|
|
133
|
+
node.last_argument.source_range.join(node.arguments[-2].source_range.end)
|
|
136
134
|
end
|
|
137
135
|
|
|
138
136
|
def unsorted_dir_loop?(node)
|
|
@@ -9,7 +9,7 @@ module RuboCop
|
|
|
9
9
|
#
|
|
10
10
|
# Conversion with `Integer`, `Float`, etc. will raise an `ArgumentError`
|
|
11
11
|
# if given input that is not numeric (eg. an empty string), whereas
|
|
12
|
-
# `to_i`, etc. will try to convert regardless of input (
|
|
12
|
+
# `to_i`, etc. will try to convert regardless of input (``''.to_i => 0``).
|
|
13
13
|
# As such, this cop is disabled by default because it's not necessarily
|
|
14
14
|
# always correct to raise if a value is not numeric.
|
|
15
15
|
#
|
|
@@ -91,19 +91,24 @@ module RuboCop
|
|
|
91
91
|
|
|
92
92
|
# @!method to_method(node)
|
|
93
93
|
def_node_matcher :to_method, <<~PATTERN
|
|
94
|
-
(
|
|
94
|
+
(call $_ ${#{METHODS}})
|
|
95
95
|
PATTERN
|
|
96
96
|
|
|
97
97
|
# @!method to_method_symbol(node)
|
|
98
98
|
def_node_matcher :to_method_symbol, <<~PATTERN
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
(call _ $_ ${
|
|
100
|
+
{
|
|
101
|
+
(sym ${#{METHODS}})
|
|
102
|
+
(block_pass (sym ${#{METHODS}}))
|
|
103
|
+
}
|
|
104
|
+
} ...)
|
|
101
105
|
PATTERN
|
|
102
106
|
|
|
103
107
|
def on_send(node)
|
|
104
108
|
handle_conversion_method(node)
|
|
105
109
|
handle_as_symbol(node)
|
|
106
110
|
end
|
|
111
|
+
alias on_csend on_send
|
|
107
112
|
|
|
108
113
|
private
|
|
109
114
|
|