rubocop 1.43.0 → 1.50.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +108 -40
- data/lib/rubocop/cli/command/auto_generate_config.rb +7 -0
- data/lib/rubocop/cli/command/execute_runner.rb +7 -2
- data/lib/rubocop/cli.rb +54 -8
- data/lib/rubocop/comment_config.rb +19 -0
- data/lib/rubocop/config.rb +3 -3
- data/lib/rubocop/config_loader.rb +20 -23
- data/lib/rubocop/config_loader_resolver.rb +3 -4
- data/lib/rubocop/cop/autocorrect_logic.rb +29 -13
- data/lib/rubocop/cop/base.rb +28 -10
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/commissioner.rb +8 -2
- data/lib/rubocop/cop/cop.rb +25 -5
- data/lib/rubocop/cop/corrector.rb +11 -3
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +2 -7
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/gemspec/dependency_version.rb +1 -1
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +1 -1
- data/lib/rubocop/cop/gemspec/development_dependencies.rb +107 -0
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +5 -5
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +3 -3
- data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/location_expression.rb +37 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb +42 -0
- data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +11 -3
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +66 -0
- data/lib/rubocop/cop/internal_affairs.rb +3 -0
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/block_end_newline.rb +7 -15
- data/lib/rubocop/cop/layout/class_structure.rb +8 -19
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +2 -6
- data/lib/rubocop/cop/layout/empty_comment.rb +3 -3
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -0
- data/lib/rubocop/cop/layout/end_alignment.rb +9 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +6 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +8 -3
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +25 -34
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +7 -19
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +42 -52
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +38 -55
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +8 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +8 -11
- data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +1 -3
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +11 -7
- data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +8 -27
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +7 -26
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +4 -21
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +6 -30
- data/lib/rubocop/cop/layout/redundant_line_break.rb +6 -7
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +11 -13
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_parens.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +4 -4
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +5 -4
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +4 -0
- data/lib/rubocop/cop/lint/constant_resolution.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +11 -27
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +62 -112
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +122 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -2
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +1 -3
- data/lib/rubocop/cop/lint/else_layout.rb +3 -7
- data/lib/rubocop/cop/lint/empty_block.rb +1 -1
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +4 -2
- data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +14 -7
- data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +15 -17
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +46 -4
- data/lib/rubocop/cop/lint/missing_super.rb +31 -2
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +4 -9
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +2 -0
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +6 -10
- data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +11 -5
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +5 -5
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +12 -2
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +35 -15
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -1
- data/lib/rubocop/cop/lint/refinement_import_methods.rb +2 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +3 -3
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +1 -1
- data/lib/rubocop/cop/lint/script_permission.rb +1 -1
- data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/syntax.rb +4 -0
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +13 -3
- data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -3
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +10 -7
- data/lib/rubocop/cop/lint/useless_method_definition.rb +12 -4
- data/lib/rubocop/cop/lint/useless_rescue.rb +20 -2
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +9 -1
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +24 -11
- data/lib/rubocop/cop/metrics/block_length.rb +1 -1
- data/lib/rubocop/cop/metrics/block_nesting.rb +2 -2
- data/lib/rubocop/cop/metrics/class_length.rb +1 -0
- data/lib/rubocop/cop/metrics/collection_literal_length.rb +76 -0
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +2 -5
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +3 -3
- data/lib/rubocop/cop/migration/department_name.rb +1 -1
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/allowed_methods.rb +3 -1
- data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -1
- data/lib/rubocop/cop/mixin/code_length.rb +1 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +8 -6
- data/lib/rubocop/cop/mixin/documentation_comment.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +56 -25
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +3 -3
- data/lib/rubocop/cop/mixin/line_length_help.rb +3 -1
- data/lib/rubocop/cop/mixin/min_branches_count.rb +40 -0
- data/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb +0 -3
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +1 -6
- data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -3
- data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -3
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -2
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +4 -0
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +1 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +23 -4
- data/lib/rubocop/cop/naming/method_name.rb +3 -3
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
- data/lib/rubocop/cop/registry.rb +15 -8
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -11
- data/lib/rubocop/cop/style/accessor_grouping.rb +39 -17
- data/lib/rubocop/cop/style/arguments_forwarding.rb +4 -3
- data/lib/rubocop/cop/style/array_intersect.rb +1 -1
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +17 -2
- data/lib/rubocop/cop/style/case_like_if.rb +20 -3
- data/lib/rubocop/cop/style/class_and_module_children.rb +4 -11
- data/lib/rubocop/cop/style/class_equality_comparison.rb +42 -9
- data/lib/rubocop/cop/style/collection_compact.rb +4 -1
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
- data/lib/rubocop/cop/style/comparable_clamp.rb +125 -0
- data/lib/rubocop/cop/style/concat_array_literals.rb +10 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +6 -12
- data/lib/rubocop/cop/style/copyright.rb +1 -1
- data/lib/rubocop/cop/style/data_inheritance.rb +75 -0
- data/lib/rubocop/cop/style/dir_empty.rb +60 -0
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +2 -2
- data/lib/rubocop/cop/style/documentation.rb +11 -5
- data/lib/rubocop/cop/style/documentation_method.rb +10 -4
- data/lib/rubocop/cop/style/double_negation.rb +2 -2
- data/lib/rubocop/cop/style/each_with_object.rb +1 -1
- data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +4 -4
- data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
- data/lib/rubocop/cop/style/file_empty.rb +71 -0
- data/lib/rubocop/cop/style/file_read.rb +1 -1
- data/lib/rubocop/cop/style/file_write.rb +1 -1
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +1 -1
- data/lib/rubocop/cop/style/hash_except.rb +4 -4
- data/lib/rubocop/cop/style/hash_like_case.rb +3 -9
- data/lib/rubocop/cop/style/hash_syntax.rb +5 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +108 -15
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
- data/lib/rubocop/cop/style/infinite_loop.rb +2 -5
- data/lib/rubocop/cop/style/inverse_methods.rb +5 -5
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +114 -0
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +2 -2
- data/lib/rubocop/cop/style/map_to_hash.rb +4 -1
- data/lib/rubocop/cop/style/map_to_set.rb +4 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +14 -12
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +44 -37
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -0
- data/lib/rubocop/cop/style/min_max.rb +3 -3
- data/lib/rubocop/cop/style/min_max_comparison.rb +11 -1
- data/lib/rubocop/cop/style/mixin_grouping.rb +4 -4
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +0 -4
- data/lib/rubocop/cop/style/multiline_memoization.rb +2 -2
- data/lib/rubocop/cop/style/multiline_method_signature.rb +7 -4
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +18 -3
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +13 -12
- data/lib/rubocop/cop/style/nil_lambda.rb +2 -2
- data/lib/rubocop/cop/style/numbered_parameters_limit.rb +11 -3
- data/lib/rubocop/cop/style/one_line_conditional.rb +3 -6
- data/lib/rubocop/cop/style/operator_method_call.rb +2 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +29 -19
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -3
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +18 -3
- data/lib/rubocop/cop/style/redundant_conditional.rb +0 -4
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +16 -10
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +6 -4
- data/lib/rubocop/cop/style/redundant_heredoc_delimiter_quotes.rb +58 -0
- data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +179 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +7 -8
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +11 -4
- data/lib/rubocop/cop/style/redundant_sort.rb +3 -3
- data/lib/rubocop/cop/style/redundant_string_escape.rb +3 -4
- data/lib/rubocop/cop/style/require_order.rb +3 -12
- data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -2
- data/lib/rubocop/cop/style/self_assignment.rb +2 -2
- data/lib/rubocop/cop/style/semicolon.rb +24 -2
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +3 -3
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/trailing_body_on_class.rb +1 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_logical_operators.rb +1 -0
- data/lib/rubocop/cop/style/unpack_first.rb +3 -3
- data/lib/rubocop/cop/style/word_array.rb +18 -6
- data/lib/rubocop/cop/style/yoda_condition.rb +13 -6
- data/lib/rubocop/cop/style/yoda_expression.rb +11 -2
- data/lib/rubocop/cop/style/zero_length_predicate.rb +9 -5
- data/lib/rubocop/cop/team.rb +30 -22
- data/lib/rubocop/cop/util.rb +13 -4
- data/lib/rubocop/cop/variable_force/scope.rb +3 -3
- data/lib/rubocop/cop/variable_force/variable.rb +5 -3
- data/lib/rubocop/cop/variable_force/variable_table.rb +3 -1
- data/lib/rubocop/cop/variable_force.rb +1 -1
- data/lib/rubocop/cops_documentation_generator.rb +10 -3
- data/lib/rubocop/directive_comment.rb +3 -3
- data/lib/rubocop/ext/comment.rb +18 -0
- data/lib/rubocop/ext/regexp_node.rb +1 -1
- data/lib/rubocop/ext/regexp_parser.rb +1 -1
- data/lib/rubocop/formatter/junit_formatter.rb +4 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
- data/lib/rubocop/formatter.rb +0 -1
- data/lib/rubocop/options.rb +26 -2
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +6 -4
- data/lib/rubocop/rspec/shared_contexts.rb +4 -0
- data/lib/rubocop/rspec/support.rb +1 -0
- data/lib/rubocop/runner.rb +40 -4
- data/lib/rubocop/server/cache.rb +11 -4
- data/lib/rubocop/server/cli.rb +37 -18
- data/lib/rubocop/server/client_command/exec.rb +1 -1
- data/lib/rubocop/server/client_command/start.rb +6 -1
- data/lib/rubocop/server/core.rb +24 -9
- data/lib/rubocop/server/helper.rb +1 -1
- data/lib/rubocop/server/server_command/exec.rb +1 -1
- data/lib/rubocop/target_ruby.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +12 -0
- metadata +21 -26
@@ -9,7 +9,7 @@ module RuboCop
|
|
9
9
|
# NOTE: This cop does not move the first argument, if you want that to
|
10
10
|
# be on a separate line, see `Layout/FirstMethodParameterLineBreak`.
|
11
11
|
#
|
12
|
-
# @example
|
12
|
+
# @example
|
13
13
|
#
|
14
14
|
# # bad
|
15
15
|
# def foo(a, b,
|
@@ -17,12 +17,6 @@ module RuboCop
|
|
17
17
|
# )
|
18
18
|
# end
|
19
19
|
#
|
20
|
-
# # bad
|
21
|
-
# def foo(a, b = {
|
22
|
-
# foo: "bar",
|
23
|
-
# })
|
24
|
-
# end
|
25
|
-
#
|
26
20
|
# # good
|
27
21
|
# def foo(
|
28
22
|
# a,
|
@@ -44,40 +38,22 @@ module RuboCop
|
|
44
38
|
# def foo(a, b, c)
|
45
39
|
# end
|
46
40
|
#
|
47
|
-
# @example AllowMultilineFinalElement:
|
41
|
+
# @example AllowMultilineFinalElement: false (default)
|
48
42
|
#
|
49
43
|
# # bad
|
50
|
-
# def foo(a, b,
|
51
|
-
# c
|
52
|
-
# )
|
53
|
-
# end
|
54
|
-
#
|
55
|
-
# # good
|
56
44
|
# def foo(a, b = {
|
57
45
|
# foo: "bar",
|
58
46
|
# })
|
59
47
|
# end
|
60
48
|
#
|
61
|
-
#
|
62
|
-
# def foo(
|
63
|
-
# a,
|
64
|
-
# b,
|
65
|
-
# c
|
66
|
-
# )
|
67
|
-
# end
|
49
|
+
# @example AllowMultilineFinalElement: true
|
68
50
|
#
|
69
51
|
# # good
|
70
|
-
# def foo(
|
71
|
-
#
|
72
|
-
#
|
73
|
-
# foo: "bar",
|
74
|
-
# }
|
75
|
-
# )
|
52
|
+
# def foo(a, b = {
|
53
|
+
# foo: "bar",
|
54
|
+
# })
|
76
55
|
# end
|
77
56
|
#
|
78
|
-
# # good
|
79
|
-
# def foo(a, b, c)
|
80
|
-
# end
|
81
57
|
class MultilineMethodParameterLineBreaks < Base
|
82
58
|
include MultilineElementLineBreaks
|
83
59
|
extend AutoCorrector
|
@@ -50,9 +50,9 @@ module RuboCop
|
|
50
50
|
|
51
51
|
def on_send(node)
|
52
52
|
# Include "the whole expression".
|
53
|
-
node = node.parent while
|
54
|
-
|
55
|
-
node.parent
|
53
|
+
node = node.parent while node.parent&.send_type? ||
|
54
|
+
convertible_block?(node) ||
|
55
|
+
node.parent.is_a?(RuboCop::AST::BinaryOperatorNode)
|
56
56
|
|
57
57
|
return unless offense?(node) && !part_of_ignored_node?(node)
|
58
58
|
|
@@ -69,15 +69,14 @@ module RuboCop
|
|
69
69
|
|
70
70
|
def register_offense(node)
|
71
71
|
add_offense(node) do |corrector|
|
72
|
-
corrector.replace(node
|
72
|
+
corrector.replace(node, to_single_line(node.source).strip)
|
73
73
|
end
|
74
74
|
ignore_node(node)
|
75
75
|
end
|
76
76
|
|
77
77
|
def offense?(node)
|
78
|
-
|
79
|
-
|
80
|
-
node.multiline? && !too_long?(node) && suitable_as_single_line?(node)
|
78
|
+
node.multiline? && !too_long?(node) && suitable_as_single_line?(node) &&
|
79
|
+
!configured_to_not_be_inspected?(node)
|
81
80
|
end
|
82
81
|
|
83
82
|
def configured_to_not_be_inspected?(node)
|
@@ -102,7 +102,7 @@ module RuboCop
|
|
102
102
|
node.loc.name
|
103
103
|
when :masgn
|
104
104
|
mlhs_node, = *node
|
105
|
-
mlhs_node.
|
105
|
+
mlhs_node.source_range
|
106
106
|
else
|
107
107
|
# It is a wrapper with access modifier.
|
108
108
|
node.child_nodes.first.loc.name
|
@@ -196,7 +196,7 @@ module RuboCop
|
|
196
196
|
if begin_end_alignment_style == 'start_of_line'
|
197
197
|
start_line_range(alignment_node)
|
198
198
|
else
|
199
|
-
alignment_node.
|
199
|
+
alignment_node.source_range
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
@@ -177,7 +177,7 @@ module RuboCop
|
|
177
177
|
end
|
178
178
|
|
179
179
|
def autocorrect(corrector, range)
|
180
|
-
if
|
180
|
+
if range.source.include?('**') && !space_around_exponent_operator?
|
181
181
|
corrector.replace(range, '**')
|
182
182
|
elsif range.source.end_with?("\n")
|
183
183
|
corrector.replace(range, " #{range.source.strip}\n")
|
@@ -34,6 +34,7 @@ module RuboCop
|
|
34
34
|
|
35
35
|
def on_send(node)
|
36
36
|
return unless regular_method_call_with_arguments?(node)
|
37
|
+
return if node.parenthesized?
|
37
38
|
|
38
39
|
first_arg = node.first_argument.source_range
|
39
40
|
first_arg_with_space = range_with_surrounding_space(first_arg, side: :left)
|
@@ -52,7 +53,6 @@ module RuboCop
|
|
52
53
|
end
|
53
54
|
|
54
55
|
def expect_params_after_method_name?(node)
|
55
|
-
return false if node.parenthesized?
|
56
56
|
return true if no_space_between_method_name_and_first_argument?(node)
|
57
57
|
|
58
58
|
first_arg = node.first_argument
|
@@ -78,8 +78,11 @@ module RuboCop
|
|
78
78
|
def on_array(node)
|
79
79
|
return unless node.square_brackets?
|
80
80
|
|
81
|
-
left, right = array_brackets(node)
|
82
|
-
|
81
|
+
tokens, left, right = array_brackets(node)
|
82
|
+
|
83
|
+
if empty_brackets?(left, right, tokens: tokens)
|
84
|
+
return empty_offenses(node, left, right, EMPTY_MSG)
|
85
|
+
end
|
83
86
|
|
84
87
|
start_ok = next_to_newline?(node, left)
|
85
88
|
end_ok = node.single_line? ? false : end_has_own_line?(right)
|
@@ -90,9 +93,9 @@ module RuboCop
|
|
90
93
|
private
|
91
94
|
|
92
95
|
def autocorrect(corrector, node)
|
93
|
-
left, right = array_brackets(node)
|
96
|
+
tokens, left, right = array_brackets(node)
|
94
97
|
|
95
|
-
if empty_brackets?(left, right)
|
98
|
+
if empty_brackets?(left, right, tokens: tokens)
|
96
99
|
SpaceCorrector.empty_corrections(processed_source, corrector, empty_config, left, right)
|
97
100
|
elsif style == :no_space
|
98
101
|
SpaceCorrector.remove_space(processed_source, corrector, left, right)
|
@@ -104,15 +107,12 @@ module RuboCop
|
|
104
107
|
end
|
105
108
|
|
106
109
|
def array_brackets(node)
|
107
|
-
|
108
|
-
end
|
110
|
+
tokens = processed_source.tokens_within(node)
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
end
|
112
|
+
left = tokens.find(&:left_array_bracket?)
|
113
|
+
right = tokens.reverse_each.find(&:right_bracket?)
|
113
114
|
|
114
|
-
|
115
|
-
processed_source.tokens_within(node).reverse.find(&:right_bracket?)
|
115
|
+
[tokens, left, right]
|
116
116
|
end
|
117
117
|
|
118
118
|
def empty_config
|
@@ -178,8 +178,6 @@ module RuboCop
|
|
178
178
|
def multi_dimensional_array?(node, token, side: :right)
|
179
179
|
offset = side == :right ? -1 : +1
|
180
180
|
i = index_for(node, token) + offset
|
181
|
-
# TODO: change this type check once
|
182
|
-
# https://github.com/rubocop/rubocop-ast/pull/240 is merged
|
183
181
|
i += offset while processed_source.tokens_within(node)[i].new_line?
|
184
182
|
if side == :right
|
185
183
|
processed_source.tokens_within(node)[i].right_bracket?
|
@@ -146,7 +146,7 @@ module RuboCop
|
|
146
146
|
if single_line && /\S$/.match?(inner)
|
147
147
|
no_space(right_brace.begin_pos, right_brace.end_pos, 'Space missing inside }.')
|
148
148
|
else
|
149
|
-
column = node.
|
149
|
+
column = node.source_range.column
|
150
150
|
return if multiline_block?(left_brace, right_brace) &&
|
151
151
|
aligned_braces?(inner, right_brace, column)
|
152
152
|
|
@@ -91,7 +91,7 @@ module RuboCop
|
|
91
91
|
if !left_parens?(token1, token2) && !right_parens?(token1, token2)
|
92
92
|
correct_missing_space(token1, token2)
|
93
93
|
else
|
94
|
-
|
94
|
+
correct_extraneous_space_between_consecutive_parens(token1, token2)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -112,7 +112,7 @@ module RuboCop
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
def
|
115
|
+
def correct_extraneous_space_between_consecutive_parens(token1, token2)
|
116
116
|
return if range_between(token1.end_pos, token2.begin_pos).source != ' '
|
117
117
|
|
118
118
|
range = range_between(token1.end_pos, token2.begin_pos)
|
@@ -74,7 +74,7 @@ module RuboCop
|
|
74
74
|
|
75
75
|
right_token = closing_bracket(tokens, left_token)
|
76
76
|
|
77
|
-
if empty_brackets?(left_token, right_token)
|
77
|
+
if empty_brackets?(left_token, right_token, tokens: tokens)
|
78
78
|
return empty_offenses(node, left_token, right_token, EMPTY_MSG)
|
79
79
|
end
|
80
80
|
|
@@ -90,9 +90,9 @@ module RuboCop
|
|
90
90
|
private
|
91
91
|
|
92
92
|
def autocorrect(corrector, node)
|
93
|
-
left, right = reference_brackets(node)
|
93
|
+
tokens, left, right = reference_brackets(node)
|
94
94
|
|
95
|
-
if empty_brackets?(left, right)
|
95
|
+
if empty_brackets?(left, right, tokens: tokens)
|
96
96
|
SpaceCorrector.empty_corrections(processed_source, corrector, empty_config, left, right)
|
97
97
|
elsif style == :no_space
|
98
98
|
SpaceCorrector.remove_space(processed_source, corrector, left, right)
|
@@ -104,7 +104,7 @@ module RuboCop
|
|
104
104
|
def reference_brackets(node)
|
105
105
|
tokens = processed_source.tokens_within(node)
|
106
106
|
left = left_ref_bracket(node, tokens)
|
107
|
-
[left, closing_bracket(tokens, left)]
|
107
|
+
[tokens, left, closing_bracket(tokens, left)]
|
108
108
|
end
|
109
109
|
|
110
110
|
def left_ref_bracket(node, tokens)
|
@@ -31,13 +31,14 @@ module RuboCop
|
|
31
31
|
def on_interpolation(begin_node)
|
32
32
|
return if begin_node.multiline?
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
tokens = processed_source.tokens_within(begin_node)
|
35
|
+
left, right = delimiters(begin_node)
|
36
|
+
return if empty_brackets?(left, right, tokens: tokens)
|
36
37
|
|
37
38
|
if style == :no_space
|
38
|
-
no_space_offenses(begin_node,
|
39
|
+
no_space_offenses(begin_node, left, right, NO_SPACE_MSG)
|
39
40
|
else
|
40
|
-
space_offenses(begin_node,
|
41
|
+
space_offenses(begin_node, left, right, SPACE_MSG)
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
@@ -38,6 +38,10 @@ module RuboCop
|
|
38
38
|
'a whitespace to the right of the `%<operator>s` if it ' \
|
39
39
|
'should be %<possible>s.'
|
40
40
|
|
41
|
+
def self.autocorrect_incompatible_with
|
42
|
+
[Naming::BlockForwarding]
|
43
|
+
end
|
44
|
+
|
41
45
|
def on_new_investigation
|
42
46
|
processed_source.diagnostics.each do |diagnostic|
|
43
47
|
next unless diagnostic.reason == :ambiguous_prefix
|
@@ -70,6 +70,9 @@ module RuboCop
|
|
70
70
|
def on_send(node)
|
71
71
|
return unless debugger_method?(node)
|
72
72
|
|
73
|
+
# Basically, debugger methods are not used as a method argument without arguments.
|
74
|
+
return if node.arguments.empty? && node.each_ancestor(:send, :csend).any?
|
75
|
+
|
73
76
|
add_offense(node)
|
74
77
|
end
|
75
78
|
|
@@ -82,44 +85,25 @@ module RuboCop
|
|
82
85
|
def debugger_methods
|
83
86
|
@debugger_methods ||= begin
|
84
87
|
config = cop_config.fetch('DebuggerMethods', [])
|
85
|
-
|
86
|
-
values.map do |v|
|
87
|
-
next unless v
|
88
|
-
|
89
|
-
*receiver, method_name = v.split('.')
|
90
|
-
{
|
91
|
-
receiver: receiver.empty? ? nil : receiver.map(&:to_sym),
|
92
|
-
method_name: method_name.to_sym
|
93
|
-
}
|
94
|
-
end.compact
|
88
|
+
config.is_a?(Array) ? config : config.values.flatten
|
95
89
|
end
|
96
90
|
end
|
97
91
|
|
98
92
|
def debugger_method?(send_node)
|
99
|
-
|
100
|
-
|
101
|
-
debugger_methods.any? do |method|
|
102
|
-
next unless method[:method_name] == method_name
|
93
|
+
return if send_node.parent&.send_type? && send_node.parent.receiver == send_node
|
103
94
|
|
104
|
-
|
105
|
-
send_node.receiver.nil?
|
106
|
-
else
|
107
|
-
method[:receiver] == receiver_chain(send_node)
|
108
|
-
end
|
109
|
-
end
|
95
|
+
debugger_methods.include?(chained_method_name(send_node))
|
110
96
|
end
|
111
97
|
|
112
|
-
def
|
113
|
-
|
98
|
+
def chained_method_name(send_node)
|
99
|
+
chained_method_name = send_node.method_name.to_s
|
114
100
|
receiver = send_node.receiver
|
115
|
-
|
116
101
|
while receiver
|
117
|
-
name = receiver.send_type? ? receiver.method_name : receiver.const_name
|
118
|
-
|
102
|
+
name = receiver.send_type? ? receiver.method_name : receiver.const_name
|
103
|
+
chained_method_name = "#{name}.#{chained_method_name}"
|
119
104
|
receiver = receiver.receiver
|
120
105
|
end
|
121
|
-
|
122
|
-
receivers
|
106
|
+
chained_method_name
|
123
107
|
end
|
124
108
|
end
|
125
109
|
end
|
@@ -11,6 +11,8 @@ module RuboCop
|
|
11
11
|
# File.exists?(some_path)
|
12
12
|
# Dir.exists?(some_path)
|
13
13
|
# iterator?
|
14
|
+
# attr :name, true
|
15
|
+
# attr :name, false
|
14
16
|
# ENV.freeze # Calling `Env.freeze` raises `TypeError` since Ruby 2.7.
|
15
17
|
# ENV.clone
|
16
18
|
# ENV.dup # Calling `Env.dup` raises `TypeError` since Ruby 3.1.
|
@@ -21,6 +23,8 @@ module RuboCop
|
|
21
23
|
# File.exist?(some_path)
|
22
24
|
# Dir.exist?(some_path)
|
23
25
|
# block_given?
|
26
|
+
# attr_accessor :name
|
27
|
+
# attr_reader :name
|
24
28
|
# ENV # `ENV.freeze` cannot prohibit changes to environment variables.
|
25
29
|
# ENV.to_h
|
26
30
|
# ENV.to_h # `ENV.dup` cannot dup `ENV`, use `ENV.to_h` to get a copy of `ENV` as a hash.
|
@@ -29,138 +33,84 @@ module RuboCop
|
|
29
33
|
class DeprecatedClassMethods < Base
|
30
34
|
extend AutoCorrector
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
MSG = '`%<current>s` is deprecated in favor of `%<prefer>s`.'
|
37
|
+
RESTRICT_ON_SEND = %i[
|
38
|
+
attr clone dup exists? freeze gethostbyaddr gethostbyname iterator?
|
39
|
+
].freeze
|
40
|
+
|
41
|
+
PREFERRED_METHODS = {
|
42
|
+
clone: 'to_h',
|
43
|
+
dup: 'to_h',
|
44
|
+
exists?: 'exist?',
|
45
|
+
gethostbyaddr: 'Addrinfo#getnameinfo',
|
46
|
+
gethostbyname: 'Addrinfo#getaddrinfo',
|
47
|
+
iterator?: 'block_given?'
|
48
|
+
}.freeze
|
37
49
|
|
38
|
-
|
50
|
+
DIR_ENV_FILE_CONSTANTS = %i[Dir ENV File].freeze
|
39
51
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
s(:const, nil, class_constant),
|
51
|
-
s(:const, s(:cbase), class_constant)
|
52
|
-
]
|
53
|
-
else
|
54
|
-
[nil]
|
55
|
-
end
|
56
|
-
end
|
52
|
+
# @!method deprecated_class_method?(node)
|
53
|
+
def_node_matcher :deprecated_class_method?, <<~PATTERN
|
54
|
+
{
|
55
|
+
(send (const {cbase nil?} {:ENV}) {:clone :dup :freeze})
|
56
|
+
(send (const {cbase nil?} {:File :Dir}) :exists? _)
|
57
|
+
(send (const {cbase nil?} :Socket) {:gethostbyaddr :gethostbyname} ...)
|
58
|
+
(send nil? :attr _ boolean)
|
59
|
+
(send nil? :iterator?)
|
60
|
+
}
|
61
|
+
PATTERN
|
57
62
|
|
58
|
-
|
59
|
-
|
60
|
-
end
|
63
|
+
def on_send(node)
|
64
|
+
return unless deprecated_class_method?(node)
|
61
65
|
|
62
|
-
|
63
|
-
|
64
|
-
|
66
|
+
offense_range = offense_range(node)
|
67
|
+
prefer = preferred_method(node)
|
68
|
+
message = format(MSG, current: offense_range.source, prefer: prefer)
|
65
69
|
|
66
|
-
|
70
|
+
add_offense(offense_range, message: message) do |corrector|
|
71
|
+
next if socket_const?(node.receiver)
|
67
72
|
|
68
|
-
|
69
|
-
|
73
|
+
if node.method?(:freeze)
|
74
|
+
corrector.replace(node, 'ENV')
|
75
|
+
else
|
76
|
+
corrector.replace(offense_range, prefer)
|
77
|
+
end
|
70
78
|
end
|
71
79
|
end
|
72
80
|
|
73
|
-
|
74
|
-
# This class exists to add abstraction and clean naming
|
75
|
-
# to the replacements for deprecated objects
|
76
|
-
class Replacement
|
77
|
-
attr_reader :method, :class_constant
|
78
|
-
|
79
|
-
def initialize(method, class_constant: nil, instance_method: false)
|
80
|
-
@method = method
|
81
|
-
@class_constant = class_constant
|
82
|
-
@instance_method = instance_method
|
83
|
-
end
|
84
|
-
|
85
|
-
def to_s
|
86
|
-
[class_constant, method].compact.join(delimiter)
|
87
|
-
end
|
88
|
-
|
89
|
-
private
|
90
|
-
|
91
|
-
def delimiter
|
92
|
-
instance_method? ? INSTANCE_METHOD_DELIMITER : CLASS_METHOD_DELIMITER
|
93
|
-
end
|
81
|
+
private
|
94
82
|
|
95
|
-
|
96
|
-
|
83
|
+
def offense_range(node)
|
84
|
+
if socket_const?(node.receiver) || dir_env_file_const?(node.receiver)
|
85
|
+
node.source_range.begin.join(node.loc.selector.end)
|
86
|
+
elsif node.method?(:attr)
|
87
|
+
node
|
88
|
+
else
|
89
|
+
node.loc.selector
|
97
90
|
end
|
98
91
|
end
|
99
92
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
Replacement.new(:exist?, class_constant: :File),
|
105
|
-
|
106
|
-
DeprecatedClassMethod.new(:exists?, class_constant: :Dir) =>
|
107
|
-
Replacement.new(:exist?, class_constant: :Dir),
|
108
|
-
|
109
|
-
DeprecatedClassMethod.new(:iterator?) => Replacement.new(:block_given?),
|
110
|
-
|
111
|
-
DeprecatedClassMethod.new(:freeze, class_constant: :ENV) =>
|
112
|
-
Replacement.new(nil, class_constant: :ENV),
|
93
|
+
def preferred_method(node)
|
94
|
+
if node.method?(:attr)
|
95
|
+
boolean_argument = node.arguments[1].source
|
96
|
+
preferred_attr_method = boolean_argument == 'true' ? 'attr_accessor' : 'attr_reader'
|
113
97
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
DeprecatedClassMethod.new(:dup, class_constant: :ENV) =>
|
118
|
-
Replacement.new(:to_h, class_constant: :ENV),
|
119
|
-
|
120
|
-
DeprecatedClassMethod.new(:gethostbyaddr, class_constant: :Socket, correctable: false) =>
|
121
|
-
Replacement.new(:getnameinfo, class_constant: :Addrinfo, instance_method: true),
|
122
|
-
|
123
|
-
DeprecatedClassMethod.new(:gethostbyname, class_constant: :Socket, correctable: false) =>
|
124
|
-
Replacement.new(:getaddrinfo, class_constant: :Addrinfo, instance_method: true)
|
125
|
-
}.freeze
|
98
|
+
"#{preferred_attr_method} #{node.first_argument.source}"
|
99
|
+
elsif dir_env_file_const?(node.receiver)
|
100
|
+
prefer = PREFERRED_METHODS[node.method_name]
|
126
101
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
INSTANCE_METHOD_DELIMITER = '#'
|
131
|
-
|
132
|
-
def on_send(node)
|
133
|
-
check(node) do |deprecated|
|
134
|
-
prefer = replacement(deprecated)
|
135
|
-
message = format(MSG, current: deprecated, prefer: prefer)
|
136
|
-
current_method = node.loc.selector
|
137
|
-
|
138
|
-
add_offense(current_method, message: message) do |corrector|
|
139
|
-
next unless deprecated.correctable?
|
140
|
-
|
141
|
-
if (preferred_method = prefer.method)
|
142
|
-
corrector.replace(current_method, preferred_method)
|
143
|
-
else
|
144
|
-
corrector.remove(node.loc.dot)
|
145
|
-
corrector.remove(current_method)
|
146
|
-
end
|
147
|
-
end
|
102
|
+
prefer ? "#{node.receiver.source}.#{prefer}" : 'ENV'
|
103
|
+
else
|
104
|
+
PREFERRED_METHODS[node.method_name]
|
148
105
|
end
|
149
106
|
end
|
150
107
|
|
151
|
-
|
152
|
-
|
153
|
-
def check(node)
|
154
|
-
DEPRECATED_METHODS_OBJECT.each_key do |deprecated|
|
155
|
-
next unless deprecated.class_nodes.include?(node.receiver)
|
156
|
-
next unless node.method?(deprecated.method)
|
157
|
-
|
158
|
-
yield deprecated
|
159
|
-
end
|
108
|
+
def socket_const?(node)
|
109
|
+
node&.short_name == :Socket
|
160
110
|
end
|
161
111
|
|
162
|
-
def
|
163
|
-
|
112
|
+
def dir_env_file_const?(node)
|
113
|
+
DIR_ENV_FILE_CONSTANTS.include?(node&.short_name)
|
164
114
|
end
|
165
115
|
end
|
166
116
|
end
|