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
|
@@ -65,8 +65,12 @@ module RuboCop
|
|
|
65
65
|
inner.begin_pos >= outer.begin_pos && inner.end_pos <= outer.end_pos
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
# @deprecated Use processed_source.
|
|
68
|
+
# @deprecated Use processed_source.line_with_comment?(line)
|
|
69
69
|
def end_of_line_comment(line)
|
|
70
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
|
71
|
+
`end_of_line_comment` is deprecated. Use `processed_source.line_with_comment?` instead.
|
|
72
|
+
WARNING
|
|
73
|
+
|
|
70
74
|
processed_source.line_with_comment?(line)
|
|
71
75
|
end
|
|
72
76
|
|
|
@@ -15,7 +15,13 @@ module RuboCop
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
# @deprecated Use allowed_method? instead
|
|
18
|
-
|
|
18
|
+
def ignored_method?
|
|
19
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
|
20
|
+
`ignored_method?` is deprecated. Use `allowed_method?` instead.
|
|
21
|
+
WARNING
|
|
22
|
+
|
|
23
|
+
allowed_method?
|
|
24
|
+
end
|
|
19
25
|
|
|
20
26
|
# @api public
|
|
21
27
|
def allowed_methods
|
|
@@ -18,14 +18,26 @@ module RuboCop
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
# @deprecated Use allowed_line? instead
|
|
21
|
-
|
|
21
|
+
def ignored_line?
|
|
22
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
|
23
|
+
`ignored_line?` is deprecated. Use `allowed_line?` instead.
|
|
24
|
+
WARNING
|
|
25
|
+
|
|
26
|
+
allowed_line?
|
|
27
|
+
end
|
|
22
28
|
|
|
23
29
|
def matches_allowed_pattern?(line)
|
|
24
30
|
allowed_patterns.any? { |pattern| Regexp.new(pattern).match?(line) }
|
|
25
31
|
end
|
|
26
32
|
|
|
27
|
-
# @deprecated Use matches_allowed_pattern
|
|
28
|
-
|
|
33
|
+
# @deprecated Use matches_allowed_pattern? instead
|
|
34
|
+
def matches_ignored_pattern?
|
|
35
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
|
36
|
+
`matches_ignored_pattern?` is deprecated. Use `matches_allowed_pattern?` instead.
|
|
37
|
+
WARNING
|
|
38
|
+
|
|
39
|
+
matches_allowed_pattern?
|
|
40
|
+
end
|
|
29
41
|
|
|
30
42
|
def allowed_patterns
|
|
31
43
|
# Since there could be a pattern specified in the default config, merge the two
|
|
@@ -218,7 +218,7 @@ module RuboCop
|
|
|
218
218
|
|
|
219
219
|
# @api private
|
|
220
220
|
def already_on_multiple_lines?(node)
|
|
221
|
-
return node.first_line != node.
|
|
221
|
+
return node.first_line != node.last_argument.last_line if node.def_type?
|
|
222
222
|
|
|
223
223
|
!node.single_line?
|
|
224
224
|
end
|
|
@@ -36,7 +36,7 @@ module RuboCop
|
|
|
36
36
|
length = calculator.calculate
|
|
37
37
|
return if length <= max_length
|
|
38
38
|
|
|
39
|
-
location = node
|
|
39
|
+
location = location(node)
|
|
40
40
|
|
|
41
41
|
add_offense(location, message: message(length, max_length)) { self.max = length }
|
|
42
42
|
end
|
|
@@ -54,6 +54,17 @@ module RuboCop
|
|
|
54
54
|
foldable_types: count_as_one
|
|
55
55
|
)
|
|
56
56
|
end
|
|
57
|
+
|
|
58
|
+
def location(node)
|
|
59
|
+
return node.loc.name if node.casgn_type?
|
|
60
|
+
|
|
61
|
+
if LSP.enabled?
|
|
62
|
+
end_range = node.loc.respond_to?(:name) ? node.loc.name : node.loc.begin
|
|
63
|
+
node.source_range.begin.join(end_range)
|
|
64
|
+
else
|
|
65
|
+
node.source_range
|
|
66
|
+
end
|
|
67
|
+
end
|
|
57
68
|
end
|
|
58
69
|
end
|
|
59
70
|
end
|
|
@@ -62,25 +62,29 @@ module RuboCop
|
|
|
62
62
|
# Returns the end line of a node, which might be a comment and not part of the AST
|
|
63
63
|
# End line is considered either the line at which another node starts, or
|
|
64
64
|
# the line at which the parent node ends.
|
|
65
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
65
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
66
66
|
def find_end_line(node)
|
|
67
|
-
if node.if_type?
|
|
68
|
-
node.
|
|
69
|
-
|
|
70
|
-
node.
|
|
71
|
-
|
|
72
|
-
node.
|
|
67
|
+
if node.if_type?
|
|
68
|
+
if node.else?
|
|
69
|
+
node.loc.else.line
|
|
70
|
+
elsif node.ternary?
|
|
71
|
+
node.else_branch.loc.line
|
|
72
|
+
elsif node.elsif?
|
|
73
|
+
node.each_ancestor(:if).find(&:if?).loc.end.line
|
|
74
|
+
end
|
|
73
75
|
elsif node.block_type? || node.numblock_type?
|
|
74
76
|
node.loc.end.line
|
|
75
77
|
elsif (next_sibling = node.right_sibling) && next_sibling.is_a?(AST::Node)
|
|
76
78
|
next_sibling.loc.line
|
|
77
79
|
elsif (parent = node.parent)
|
|
78
|
-
parent.loc.respond_to?(:end) && parent.loc.end
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
if parent.loc.respond_to?(:end) && parent.loc.end
|
|
81
|
+
parent.loc.end.line
|
|
82
|
+
else
|
|
83
|
+
parent.loc.line
|
|
84
|
+
end
|
|
85
|
+
end || node.loc.end.line
|
|
82
86
|
end
|
|
83
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
87
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
84
88
|
end
|
|
85
89
|
end
|
|
86
90
|
end
|
|
@@ -4,11 +4,15 @@ module RuboCop
|
|
|
4
4
|
module Cop
|
|
5
5
|
# Handles `Max` configuration parameters, especially setting them to an
|
|
6
6
|
# appropriate value with --auto-gen-config.
|
|
7
|
-
# @deprecated Use `exclude_limit ParameterName
|
|
7
|
+
# @deprecated Use `exclude_limit <ParameterName>` instead.
|
|
8
8
|
module ConfigurableMax
|
|
9
9
|
private
|
|
10
10
|
|
|
11
11
|
def max=(value)
|
|
12
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
|
13
|
+
`max=` is deprecated. Use `exclude_limit <ParameterName>` instead.
|
|
14
|
+
WARNING
|
|
15
|
+
|
|
12
16
|
cfg = config_to_allow_offenses
|
|
13
17
|
cfg[:exclude_limit] ||= {}
|
|
14
18
|
current_max = cfg[:exclude_limit][max_parameter_name]
|
|
@@ -48,29 +48,33 @@ module RuboCop
|
|
|
48
48
|
|
|
49
49
|
def register_offense(node, message, replacement) # rubocop:disable Metrics/AbcSize
|
|
50
50
|
add_offense(node.value, message: message) do |corrector|
|
|
51
|
-
if (def_node = def_node_that_require_parentheses(node))
|
|
52
|
-
last_argument = def_node.last_argument
|
|
53
|
-
if last_argument.nil? || !last_argument.hash_type?
|
|
54
|
-
next corrector.replace(node, replacement)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
white_spaces = range_between(def_node.selector.end_pos,
|
|
58
|
-
def_node.first_argument.source_range.begin_pos)
|
|
59
|
-
corrector.replace(white_spaces, '(')
|
|
60
|
-
corrector.insert_after(last_argument, ')') if node == last_argument.pairs.last
|
|
61
|
-
end
|
|
62
51
|
corrector.replace(node, replacement)
|
|
52
|
+
|
|
53
|
+
next unless (def_node = def_node_that_require_parentheses(node))
|
|
54
|
+
|
|
55
|
+
last_argument = def_node.last_argument
|
|
56
|
+
if last_argument.nil? || !last_argument.hash_type?
|
|
57
|
+
next corrector.replace(node, replacement)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
white_spaces = range_between(def_node.selector.end_pos,
|
|
61
|
+
def_node.first_argument.source_range.begin_pos)
|
|
62
|
+
next if node.parent.braces?
|
|
63
|
+
|
|
64
|
+
corrector.replace(white_spaces, '(')
|
|
65
|
+
corrector.insert_after(last_argument, ')') if node == last_argument.pairs.last
|
|
63
66
|
end
|
|
64
67
|
end
|
|
65
68
|
|
|
66
69
|
def ignore_mixed_hash_shorthand_syntax?(hash_node)
|
|
67
|
-
target_ruby_version <= 3.0 ||
|
|
70
|
+
target_ruby_version <= 3.0 ||
|
|
71
|
+
!%w[consistent either_consistent].include?(enforced_shorthand_syntax) ||
|
|
68
72
|
!hash_node.hash_type?
|
|
69
73
|
end
|
|
70
74
|
|
|
71
75
|
def ignore_hash_shorthand_syntax?(pair_node)
|
|
72
76
|
target_ruby_version <= 3.0 || enforced_shorthand_syntax == 'either' ||
|
|
73
|
-
enforced_shorthand_syntax
|
|
77
|
+
%w[consistent either_consistent].include?(enforced_shorthand_syntax) ||
|
|
74
78
|
!pair_node.parent.hash_type?
|
|
75
79
|
end
|
|
76
80
|
|
|
@@ -169,6 +173,11 @@ module RuboCop
|
|
|
169
173
|
hash_value_type_breakdown[:value_needed]&.any?
|
|
170
174
|
end
|
|
171
175
|
|
|
176
|
+
def ignore_explicit_omissible_hash_shorthand_syntax?(hash_value_type_breakdown)
|
|
177
|
+
hash_value_type_breakdown.keys == [:value_omittable] &&
|
|
178
|
+
enforced_shorthand_syntax == 'either_consistent'
|
|
179
|
+
end
|
|
180
|
+
|
|
172
181
|
def each_omitted_value_pair(hash_value_type_breakdown, &block)
|
|
173
182
|
hash_value_type_breakdown[:value_omitted]&.each(&block)
|
|
174
183
|
end
|
|
@@ -195,6 +204,7 @@ module RuboCop
|
|
|
195
204
|
|
|
196
205
|
def no_mixed_shorthand_syntax_check(hash_value_type_breakdown)
|
|
197
206
|
return if hash_with_values_that_cant_be_omitted?(hash_value_type_breakdown)
|
|
207
|
+
return if ignore_explicit_omissible_hash_shorthand_syntax?(hash_value_type_breakdown)
|
|
198
208
|
|
|
199
209
|
each_omittable_value_pair(hash_value_type_breakdown) do |pair_node|
|
|
200
210
|
hash_key_source = pair_node.key.source
|
|
@@ -49,13 +49,13 @@ module RuboCop
|
|
|
49
49
|
|
|
50
50
|
return unless complexity > max
|
|
51
51
|
|
|
52
|
-
msg = format(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
msg = format(
|
|
53
|
+
self.class::MSG,
|
|
54
|
+
method: method_name, complexity: complexity, abc_vector: abc_vector, max: max
|
|
55
|
+
)
|
|
56
|
+
location = location(node)
|
|
57
57
|
|
|
58
|
-
add_offense(
|
|
58
|
+
add_offense(location, message: msg) { self.max = complexity.ceil }
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def complexity(body)
|
|
@@ -69,6 +69,15 @@ module RuboCop
|
|
|
69
69
|
end
|
|
70
70
|
score
|
|
71
71
|
end
|
|
72
|
+
|
|
73
|
+
def location(node)
|
|
74
|
+
if LSP.enabled?
|
|
75
|
+
end_range = node.loc.respond_to?(:name) ? node.loc.name : node.loc.begin
|
|
76
|
+
node.source_range.begin.join(end_range)
|
|
77
|
+
else
|
|
78
|
+
node.source_range
|
|
79
|
+
end
|
|
80
|
+
end
|
|
72
81
|
end
|
|
73
82
|
end
|
|
74
83
|
end
|
|
@@ -189,7 +189,7 @@ module RuboCop
|
|
|
189
189
|
case node.type
|
|
190
190
|
when :casgn then _scope, _lhs, rhs = *node
|
|
191
191
|
when :op_asgn then _lhs, _op, rhs = *node
|
|
192
|
-
when :send
|
|
192
|
+
when :send, :csend then rhs = node.last_argument
|
|
193
193
|
else _lhs, rhs = *node
|
|
194
194
|
end
|
|
195
195
|
rhs
|
|
@@ -18,6 +18,10 @@ module RuboCop
|
|
|
18
18
|
|
|
19
19
|
# @deprecated Use ResbodyNode#exceptions instead
|
|
20
20
|
def rescued_exceptions(resbody)
|
|
21
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
|
22
|
+
`rescued_exceptions` is deprecated. Use `ResbodyNode#exceptions` instead.
|
|
23
|
+
WARNING
|
|
24
|
+
|
|
21
25
|
rescue_group, = *resbody
|
|
22
26
|
if rescue_group
|
|
23
27
|
rescue_group.values
|
|
@@ -14,7 +14,7 @@ module RuboCop
|
|
|
14
14
|
def_node_matcher :empty_condition?, '(begin)'
|
|
15
15
|
|
|
16
16
|
# @!method setter_method?(node)
|
|
17
|
-
def_node_matcher :setter_method?, '[(
|
|
17
|
+
def_node_matcher :setter_method?, '[(call ...) setter_method?]'
|
|
18
18
|
|
|
19
19
|
# @!method safe_assignment?(node)
|
|
20
20
|
def_node_matcher :safe_assignment?, '(begin {equals_asgn? #setter_method?})'
|
|
@@ -48,23 +48,27 @@ module RuboCop
|
|
|
48
48
|
MSG = 'Use %<style>s block forwarding.'
|
|
49
49
|
|
|
50
50
|
def self.autocorrect_incompatible_with
|
|
51
|
-
[Lint::AmbiguousOperator]
|
|
51
|
+
[Lint::AmbiguousOperator, Style::ArgumentsForwarding]
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def on_def(node)
|
|
55
55
|
return if node.arguments.empty?
|
|
56
56
|
|
|
57
|
-
last_argument = node.
|
|
57
|
+
last_argument = node.last_argument
|
|
58
58
|
return if expected_block_forwarding_style?(node, last_argument)
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
forwarded_args = node.each_descendant(:block_pass).with_object([]) do |block_pass, result|
|
|
61
|
+
return nil if invalidates_syntax?(block_pass)
|
|
62
|
+
next unless block_argument_name_matched?(block_pass, last_argument)
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
last_argument.source != block_pass_node.source
|
|
64
|
+
result << block_pass
|
|
65
|
+
end
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
forwarded_args.each do |forwarded_arg|
|
|
68
|
+
register_offense(forwarded_arg, node)
|
|
67
69
|
end
|
|
70
|
+
|
|
71
|
+
register_offense(last_argument, node)
|
|
68
72
|
end
|
|
69
73
|
alias on_defs on_def
|
|
70
74
|
|
|
@@ -80,6 +84,29 @@ module RuboCop
|
|
|
80
84
|
end
|
|
81
85
|
end
|
|
82
86
|
|
|
87
|
+
def block_argument_name_matched?(block_pass_node, last_argument)
|
|
88
|
+
return false if block_pass_node.children.first&.sym_type?
|
|
89
|
+
|
|
90
|
+
last_argument.source == block_pass_node.source
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Prevents the following syntax error:
|
|
94
|
+
#
|
|
95
|
+
# # foo.rb
|
|
96
|
+
# def foo(&)
|
|
97
|
+
# block_method do
|
|
98
|
+
# bar(&)
|
|
99
|
+
# end
|
|
100
|
+
# end
|
|
101
|
+
#
|
|
102
|
+
# $ ruby -vc foo.rb
|
|
103
|
+
# ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
|
|
104
|
+
# foo.rb: foo.rb:4: anonymous block parameter is also used within block (SyntaxError)
|
|
105
|
+
#
|
|
106
|
+
def invalidates_syntax?(block_pass_node)
|
|
107
|
+
block_pass_node.each_ancestor(:block, :numblock).any?
|
|
108
|
+
end
|
|
109
|
+
|
|
83
110
|
def use_kwarg_in_method_definition?(node)
|
|
84
111
|
node.arguments.each_descendant(:kwarg, :kwoptarg).any?
|
|
85
112
|
end
|
|
@@ -61,8 +61,7 @@ module RuboCop
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def allowed_method_call_on_rhs?(node)
|
|
64
|
-
node&.send_type? &&
|
|
65
|
-
(node.receiver.nil? || !literal_receiver?(node))
|
|
64
|
+
node&.send_type? && (node.receiver.nil? || !literal_receiver?(node))
|
|
66
65
|
end
|
|
67
66
|
|
|
68
67
|
# @!method literal_receiver?(node)
|
|
@@ -57,7 +57,7 @@ module RuboCop
|
|
|
57
57
|
file_path = processed_source.file_path
|
|
58
58
|
return if config.file_to_exclude?(file_path) || config.allowed_camel_case_file?(file_path)
|
|
59
59
|
|
|
60
|
-
for_bad_filename(file_path)
|
|
60
|
+
for_bad_filename(file_path)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
private
|
|
@@ -71,7 +71,7 @@ module RuboCop
|
|
|
71
71
|
msg = other_message(basename) unless bad_filename_allowed?
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
add_global_offense(msg) if msg
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def perform_class_and_module_naming_checks(file_path, basename)
|
|
@@ -207,8 +207,7 @@ module RuboCop
|
|
|
207
207
|
message = create_multiple_word_message_for_file(words)
|
|
208
208
|
end
|
|
209
209
|
|
|
210
|
-
|
|
211
|
-
add_offense(range, message: message)
|
|
210
|
+
add_global_offense(message)
|
|
212
211
|
end
|
|
213
212
|
|
|
214
213
|
def create_single_word_message_for_file(word)
|
|
@@ -203,7 +203,7 @@ module RuboCop
|
|
|
203
203
|
|
|
204
204
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
205
205
|
def on_defined?(node)
|
|
206
|
-
arg = node.
|
|
206
|
+
arg = node.first_argument
|
|
207
207
|
return false unless arg.ivar_type?
|
|
208
208
|
|
|
209
209
|
method_node, method_name = find_definition(node)
|
|
@@ -99,7 +99,7 @@ module RuboCop
|
|
|
99
99
|
!(method_name.start_with?(prefix) && # cheap check to avoid allocating Regexp
|
|
100
100
|
method_name.match?(/^#{prefix}[^0-9]/)) ||
|
|
101
101
|
method_name == expected_name(method_name, prefix) ||
|
|
102
|
-
method_name.end_with?('=') ||
|
|
102
|
+
method_name.end_with?('=') ||
|
|
103
103
|
allowed_method?(method_name)
|
|
104
104
|
end
|
|
105
105
|
|
|
@@ -109,7 +109,7 @@ module RuboCop
|
|
|
109
109
|
else
|
|
110
110
|
method_name.dup
|
|
111
111
|
end
|
|
112
|
-
new_name << '?' unless method_name.end_with?('?')
|
|
112
|
+
new_name << '?' unless method_name.end_with?('?')
|
|
113
113
|
new_name
|
|
114
114
|
end
|
|
115
115
|
|
data/lib/rubocop/cop/registry.rb
CHANGED
|
@@ -300,7 +300,7 @@ module RuboCop
|
|
|
300
300
|
unless given_badge.match?(real_badge)
|
|
301
301
|
path = PathUtil.smart_path(source_path)
|
|
302
302
|
warn "#{path}: #{given_badge} has the wrong namespace - " \
|
|
303
|
-
"
|
|
303
|
+
"replace it with #{given_badge.with_department(real_badge.department)}"
|
|
304
304
|
end
|
|
305
305
|
|
|
306
306
|
real_badge.to_s
|
|
@@ -30,8 +30,8 @@ module RuboCop
|
|
|
30
30
|
class CompoundHash < Base
|
|
31
31
|
COMBINATOR_IN_HASH_MSG = 'Use `[...].hash` instead of combining hash values manually.'
|
|
32
32
|
MONUPLE_HASH_MSG =
|
|
33
|
-
'Delegate hash directly without wrapping in an array when only using a single value'
|
|
34
|
-
REDUNDANT_HASH_MSG = 'Calling .hash on elements of a hashed array is redundant'
|
|
33
|
+
'Delegate hash directly without wrapping in an array when only using a single value.'
|
|
34
|
+
REDUNDANT_HASH_MSG = 'Calling .hash on elements of a hashed array is redundant.'
|
|
35
35
|
|
|
36
36
|
# @!method hash_method_definition?(node)
|
|
37
37
|
def_node_matcher :hash_method_definition?, <<~PATTERN
|
|
@@ -23,6 +23,7 @@ module RuboCop
|
|
|
23
23
|
# # bad
|
|
24
24
|
# open(something)
|
|
25
25
|
# open("| #{something}")
|
|
26
|
+
# open("| foo")
|
|
26
27
|
# URI.open(something)
|
|
27
28
|
#
|
|
28
29
|
# # good
|
|
@@ -32,7 +33,6 @@ module RuboCop
|
|
|
32
33
|
#
|
|
33
34
|
# # good (literal strings)
|
|
34
35
|
# open("foo.text")
|
|
35
|
-
# open("| foo")
|
|
36
36
|
# URI.open("http://example.com")
|
|
37
37
|
class Open < Base
|
|
38
38
|
MSG = 'The use of `%<receiver>sopen` is a serious security risk.'
|
|
@@ -40,7 +40,7 @@ module RuboCop
|
|
|
40
40
|
|
|
41
41
|
# @!method open?(node)
|
|
42
42
|
def_node_matcher :open?, <<~PATTERN
|
|
43
|
-
(send ${nil? (const {nil? cbase} :URI)} :open
|
|
43
|
+
(send ${nil? (const {nil? cbase} :URI)} :open $_ ...)
|
|
44
44
|
PATTERN
|
|
45
45
|
|
|
46
46
|
def on_send(node)
|
|
@@ -8,6 +8,17 @@ module RuboCop
|
|
|
8
8
|
# EnforcedStyle config covers only method definitions.
|
|
9
9
|
# Applications of visibility methods to symbols can be controlled
|
|
10
10
|
# using AllowModifiersOnSymbols config.
|
|
11
|
+
# Also, the visibility of `attr*` methods can be controlled using
|
|
12
|
+
# AllowModifiersOnAttrs config.
|
|
13
|
+
#
|
|
14
|
+
# In Ruby 3.0, `attr*` methods now return an array of defined method names
|
|
15
|
+
# as symbols. So we can write the modifier and `attr*` in inline style.
|
|
16
|
+
# AllowModifiersOnAttrs config allows `attr*` methods to be written in
|
|
17
|
+
# inline style without modifying applications that have been maintained
|
|
18
|
+
# for a long time in group style. Furthermore, developers who are not very
|
|
19
|
+
# familiar with Ruby may know that the modifier applies to `def`, but they
|
|
20
|
+
# may not know that it also applies to `attr*` methods. It would be easier
|
|
21
|
+
# to understand if we could write `attr*` methods in inline style.
|
|
11
22
|
#
|
|
12
23
|
# @safety
|
|
13
24
|
# Autocorrection is not safe, because the visibility of dynamically
|
|
@@ -67,6 +78,34 @@ module RuboCop
|
|
|
67
78
|
# private :bar, :baz
|
|
68
79
|
#
|
|
69
80
|
# end
|
|
81
|
+
#
|
|
82
|
+
# @example AllowModifiersOnAttrs: true (default)
|
|
83
|
+
# # good
|
|
84
|
+
# class Foo
|
|
85
|
+
#
|
|
86
|
+
# public attr_reader :bar
|
|
87
|
+
# protected attr_writer :baz
|
|
88
|
+
# private attr_accessor :qux
|
|
89
|
+
# private attr :quux
|
|
90
|
+
#
|
|
91
|
+
# def public_method; end
|
|
92
|
+
#
|
|
93
|
+
# private
|
|
94
|
+
#
|
|
95
|
+
# def private_method; end
|
|
96
|
+
#
|
|
97
|
+
# end
|
|
98
|
+
#
|
|
99
|
+
# @example AllowModifiersOnAttrs: false
|
|
100
|
+
# # bad
|
|
101
|
+
# class Foo
|
|
102
|
+
#
|
|
103
|
+
# public attr_reader :bar
|
|
104
|
+
# protected attr_writer :baz
|
|
105
|
+
# private attr_accessor :qux
|
|
106
|
+
# private attr :quux
|
|
107
|
+
#
|
|
108
|
+
# end
|
|
70
109
|
class AccessModifierDeclarations < Base
|
|
71
110
|
extend AutoCorrector
|
|
72
111
|
|
|
@@ -92,10 +131,17 @@ module RuboCop
|
|
|
92
131
|
(send nil? {:private :protected :public :module_function} (sym _))
|
|
93
132
|
PATTERN
|
|
94
133
|
|
|
134
|
+
# @!method access_modifier_with_attr?(node)
|
|
135
|
+
def_node_matcher :access_modifier_with_attr?, <<~PATTERN
|
|
136
|
+
(send nil? {:private :protected :public :module_function}
|
|
137
|
+
(send nil? {:attr :attr_reader :attr_writer :attr_accessor} _))
|
|
138
|
+
PATTERN
|
|
139
|
+
|
|
95
140
|
def on_send(node)
|
|
96
141
|
return unless node.access_modifier?
|
|
97
142
|
return if ALLOWED_NODE_TYPES.include?(node.parent&.type)
|
|
98
143
|
return if allow_modifiers_on_symbols?(node)
|
|
144
|
+
return if allow_modifiers_on_attrs?(node)
|
|
99
145
|
|
|
100
146
|
if offense?(node)
|
|
101
147
|
add_offense(node.loc.selector) do |corrector|
|
|
@@ -128,6 +174,10 @@ module RuboCop
|
|
|
128
174
|
cop_config['AllowModifiersOnSymbols'] && access_modifier_with_symbol?(node)
|
|
129
175
|
end
|
|
130
176
|
|
|
177
|
+
def allow_modifiers_on_attrs?(node)
|
|
178
|
+
cop_config['AllowModifiersOnAttrs'] && access_modifier_with_attr?(node)
|
|
179
|
+
end
|
|
180
|
+
|
|
131
181
|
def offense?(node)
|
|
132
182
|
(group_style? && access_modifier_is_inlined?(node) &&
|
|
133
183
|
!right_siblings_same_inline_method?(node)) ||
|
|
@@ -168,12 +218,12 @@ module RuboCop
|
|
|
168
218
|
|
|
169
219
|
def find_corresponding_def_node(node)
|
|
170
220
|
if access_modifier_with_symbol?(node)
|
|
171
|
-
method_name = node.
|
|
221
|
+
method_name = node.first_argument.value
|
|
172
222
|
node.parent.each_child_node(:def).find do |child|
|
|
173
223
|
child.method?(method_name)
|
|
174
224
|
end
|
|
175
225
|
else
|
|
176
|
-
node.
|
|
226
|
+
node.first_argument
|
|
177
227
|
end
|
|
178
228
|
end
|
|
179
229
|
|
|
@@ -41,6 +41,7 @@ module RuboCop
|
|
|
41
41
|
def on_send(node)
|
|
42
42
|
return unless node.command?(:alias_method)
|
|
43
43
|
return unless style == :prefer_alias && alias_keyword_possible?(node)
|
|
44
|
+
return unless node.arguments.count == 2
|
|
44
45
|
|
|
45
46
|
msg = format(MSG_ALIAS_METHOD, current: lexical_scope_type(node))
|
|
46
47
|
add_offense(node.loc.selector, message: msg) do |corrector|
|