rubocop 1.46.0 → 1.52.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/config/default.yml +83 -11
- 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 +6 -6
- data/lib/rubocop/comment_config.rb +2 -0
- data/lib/rubocop/config.rb +7 -3
- data/lib/rubocop/config_loader.rb +8 -8
- data/lib/rubocop/config_obsoletion.rb +2 -2
- data/lib/rubocop/cop/autocorrect_logic.rb +29 -13
- data/lib/rubocop/cop/base.rb +6 -2
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/cop.rb +2 -2
- data/lib/rubocop/cop/corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +3 -3
- 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 +1 -1
- 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 +1 -1
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +37 -13
- 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 +3 -3
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb +1 -1
- 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 +2 -0
- data/lib/rubocop/cop/layout/block_end_newline.rb +7 -21
- data/lib/rubocop/cop/layout/class_structure.rb +6 -3
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +1 -2
- 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 +5 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +6 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +7 -2
- 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 +4 -4
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
- 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/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_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_block_braces.rb +3 -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/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +13 -1
- data/lib/rubocop/cop/lint/constant_resolution.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
- 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 +1 -1
- 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/erb_new_arguments.rb +3 -4
- data/lib/rubocop/cop/lint/identity_comparison.rb +0 -1
- data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +5 -3
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/inherit_exception.rb +9 -0
- data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +46 -4
- data/lib/rubocop/cop/lint/missing_super.rb +34 -2
- data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +2 -2
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +2 -0
- data/lib/rubocop/cop/lint/ordered_magic_comments.rb +0 -1
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +2 -2
- 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 +4 -4
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +5 -5
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -1
- 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/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/send_with_mixin_argument.rb +1 -2
- data/lib/rubocop/cop/lint/shadowed_exception.rb +6 -12
- data/lib/rubocop/cop/lint/syntax.rb +4 -0
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +7 -1
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +23 -9
- data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -3
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +9 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +59 -1
- data/lib/rubocop/cop/lint/useless_method_definition.rb +10 -2
- data/lib/rubocop/cop/lint/useless_rescue.rb +4 -1
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +69 -9
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
- 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/utils/abc_size_calculator.rb +1 -2
- 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/allowed_receivers.rb +34 -0
- 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 +9 -5
- 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 +4 -2
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +3 -3
- data/lib/rubocop/cop/mixin/min_branches_count.rb +40 -0
- 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/space_after_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -3
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.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/memoized_instance_variable_name.rb +22 -7
- 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 +12 -4
- data/lib/rubocop/cop/naming/variable_name.rb +6 -1
- data/lib/rubocop/cop/registry.rb +3 -1
- data/lib/rubocop/cop/style/accessor_grouping.rb +32 -7
- data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -3
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +11 -1
- data/lib/rubocop/cop/style/begin_block.rb +1 -2
- 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 +11 -2
- data/lib/rubocop/cop/style/case_like_if.rb +20 -3
- data/lib/rubocop/cop/style/class_and_module_children.rb +2 -2
- data/lib/rubocop/cop/style/class_equality_comparison.rb +51 -40
- data/lib/rubocop/cop/style/collection_compact.rb +20 -7
- data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
- data/lib/rubocop/cop/style/combinable_loops.rb +26 -6
- 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/concat_array_literals.rb +10 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +8 -8
- data/lib/rubocop/cop/style/copyright.rb +6 -3
- data/lib/rubocop/cop/style/data_inheritance.rb +75 -0
- data/lib/rubocop/cop/style/dir.rb +1 -1
- data/lib/rubocop/cop/style/dir_empty.rb +54 -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/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 +8 -8
- data/lib/rubocop/cop/style/exact_regexp_match.rb +68 -0
- 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 +3 -3
- 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 +3 -1
- data/lib/rubocop/cop/style/hash_each_methods.rb +1 -22
- data/lib/rubocop/cop/style/hash_except.rb +23 -12
- 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/hash_transform_keys.rb +2 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
- data/lib/rubocop/cop/style/if_inside_else.rb +6 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +111 -15
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +5 -5
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +9 -5
- 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 +4 -9
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +44 -37
- data/lib/rubocop/cop/style/min_max.rb +3 -3
- data/lib/rubocop/cop/style/mixin_grouping.rb +4 -4
- data/lib/rubocop/cop/style/multiline_method_signature.rb +7 -4
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -1
- data/lib/rubocop/cop/style/multiple_comparison.rb +14 -0
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +12 -7
- data/lib/rubocop/cop/style/nil_lambda.rb +2 -2
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/parallel_assignment.rb +26 -18
- 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_array_constructor.rb +77 -0
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -2
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +2 -2
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +6 -4
- data/lib/rubocop/cop/style/redundant_filter_chain.rb +101 -0
- data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +183 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_constructor.rb +46 -0
- 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/regexp_literal.rb +11 -2
- data/lib/rubocop/cop/style/require_order.rb +12 -8
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -3
- 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/select_by_regexp.rb +15 -5
- data/lib/rubocop/cop/style/semicolon.rb +12 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +6 -4
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -4
- 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/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/yoda_condition.rb +1 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +9 -5
- data/lib/rubocop/cop/team.rb +2 -2
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/variable_force/assignment.rb +33 -1
- data/lib/rubocop/cop/variable_force/variable.rb +5 -3
- data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
- data/lib/rubocop/cop/variable_force.rb +1 -0
- 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/options.rb +4 -1
- data/lib/rubocop/result_cache.rb +2 -2
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/support.rb +1 -0
- data/lib/rubocop/server/cache.rb +1 -1
- data/lib/rubocop/server/client_command/exec.rb +2 -1
- data/lib/rubocop/server/core.rb +1 -1
- data/lib/rubocop/server/helper.rb +1 -1
- data/lib/rubocop/server/server_command/exec.rb +1 -1
- data/lib/rubocop/target_ruby.rb +3 -2
- data/lib/rubocop/version.rb +10 -6
- data/lib/rubocop.rb +13 -0
- metadata +23 -8
@@ -6,49 +6,40 @@ module RuboCop
|
|
6
6
|
# Checks for a line break before the first element in a
|
7
7
|
# multi-line array.
|
8
8
|
#
|
9
|
-
# @example
|
9
|
+
# @example
|
10
10
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
11
|
+
# # bad
|
12
|
+
# [ :a,
|
13
|
+
# :b]
|
14
14
|
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
15
|
+
# # good
|
16
|
+
# [
|
17
|
+
# :a,
|
18
|
+
# :b]
|
19
19
|
#
|
20
|
-
#
|
21
|
-
#
|
20
|
+
# # good
|
21
|
+
# [:a, :b]
|
22
22
|
#
|
23
|
-
#
|
24
|
-
# [
|
25
|
-
# :a,
|
26
|
-
# :b]
|
23
|
+
# @example AllowMultilineFinalElement: false (default)
|
27
24
|
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
# }]
|
25
|
+
# # bad
|
26
|
+
# [ :a, {
|
27
|
+
# :b => :c
|
28
|
+
# }]
|
33
29
|
#
|
34
|
-
#
|
30
|
+
# # good
|
31
|
+
# [
|
32
|
+
# :a, {
|
33
|
+
# :b => :c
|
34
|
+
# }]
|
35
35
|
#
|
36
|
-
#
|
37
|
-
# [ :a,
|
38
|
-
# :b]
|
39
|
-
#
|
40
|
-
# # good
|
41
|
-
# [ :a, {
|
42
|
-
# :b => :c
|
43
|
-
# }]
|
36
|
+
# @example AllowMultilineFinalElement: true
|
44
37
|
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
38
|
+
# # good
|
39
|
+
# [:a, {
|
40
|
+
# :b => :c
|
41
|
+
# }]
|
49
42
|
#
|
50
|
-
# # good
|
51
|
-
# [:a, :b]
|
52
43
|
class FirstArrayElementLineBreak < Base
|
53
44
|
include FirstElementLineBreak
|
54
45
|
extend AutoCorrector
|
@@ -6,17 +6,12 @@ module RuboCop
|
|
6
6
|
# Checks for a line break before the first element in a
|
7
7
|
# multi-line hash.
|
8
8
|
#
|
9
|
-
# @example
|
9
|
+
# @example
|
10
10
|
#
|
11
11
|
# # bad
|
12
12
|
# { a: 1,
|
13
13
|
# b: 2}
|
14
14
|
#
|
15
|
-
# # bad
|
16
|
-
# { a: 1, b: {
|
17
|
-
# c: 3
|
18
|
-
# }}
|
19
|
-
#
|
20
15
|
# # good
|
21
16
|
# {
|
22
17
|
# a: 1,
|
@@ -28,11 +23,14 @@ module RuboCop
|
|
28
23
|
# c: 3
|
29
24
|
# }}
|
30
25
|
#
|
31
|
-
# @example AllowMultilineFinalElement:
|
26
|
+
# @example AllowMultilineFinalElement: false (default)
|
32
27
|
#
|
33
28
|
# # bad
|
34
|
-
# { a: 1,
|
35
|
-
#
|
29
|
+
# { a: 1, b: {
|
30
|
+
# c: 3
|
31
|
+
# }}
|
32
|
+
#
|
33
|
+
# @example AllowMultilineFinalElement: true
|
36
34
|
#
|
37
35
|
# # bad
|
38
36
|
# { a: 1,
|
@@ -45,16 +43,6 @@ module RuboCop
|
|
45
43
|
# c: 3
|
46
44
|
# }}
|
47
45
|
#
|
48
|
-
# # good
|
49
|
-
# {
|
50
|
-
# a: 1,
|
51
|
-
# b: 2 }
|
52
|
-
#
|
53
|
-
# # good
|
54
|
-
# {
|
55
|
-
# a: 1, b: {
|
56
|
-
# c: 3
|
57
|
-
# }}
|
58
46
|
class FirstHashElementLineBreak < Base
|
59
47
|
include FirstElementLineBreak
|
60
48
|
extend AutoCorrector
|
@@ -6,73 +6,63 @@ module RuboCop
|
|
6
6
|
# Checks for a line break before the first argument in a
|
7
7
|
# multi-line method call.
|
8
8
|
#
|
9
|
-
# @example
|
10
|
-
#
|
11
|
-
# # bad
|
12
|
-
# method(foo, bar,
|
13
|
-
# baz)
|
14
|
-
#
|
15
|
-
# # bad
|
16
|
-
# method(foo, bar, {
|
17
|
-
# baz: "a",
|
18
|
-
# qux: "b",
|
19
|
-
# })
|
9
|
+
# @example
|
20
10
|
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# baz)
|
11
|
+
# # bad
|
12
|
+
# method(foo, bar,
|
13
|
+
# baz)
|
25
14
|
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# qux: "b",
|
31
|
-
# })
|
15
|
+
# # good
|
16
|
+
# method(
|
17
|
+
# foo, bar,
|
18
|
+
# baz)
|
32
19
|
#
|
33
20
|
# # ignored
|
34
21
|
# method foo, bar,
|
35
22
|
# baz
|
36
23
|
#
|
37
|
-
# @example AllowMultilineFinalElement:
|
24
|
+
# @example AllowMultilineFinalElement: false (default)
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# method(foo, bar, {
|
28
|
+
# baz: "a",
|
29
|
+
# qux: "b",
|
30
|
+
# })
|
38
31
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
32
|
+
# # good
|
33
|
+
# method(
|
34
|
+
# foo, bar, {
|
35
|
+
# baz: "a",
|
36
|
+
# qux: "b",
|
37
|
+
# })
|
42
38
|
#
|
43
|
-
#
|
44
|
-
# method(foo,
|
45
|
-
# bar,
|
46
|
-
# {
|
47
|
-
# baz: "a",
|
48
|
-
# qux: "b",
|
49
|
-
# }
|
50
|
-
# )
|
39
|
+
# @example AllowMultilineFinalElement: true
|
51
40
|
#
|
52
|
-
#
|
53
|
-
#
|
41
|
+
# # bad
|
42
|
+
# method(foo,
|
43
|
+
# bar,
|
44
|
+
# {
|
54
45
|
# baz: "a",
|
55
46
|
# qux: "b",
|
56
|
-
# }
|
47
|
+
# }
|
48
|
+
# )
|
57
49
|
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
50
|
+
# # good
|
51
|
+
# method(foo, bar, {
|
52
|
+
# baz: "a",
|
53
|
+
# qux: "b",
|
54
|
+
# })
|
62
55
|
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
56
|
+
# # good
|
57
|
+
# method(
|
58
|
+
# foo,
|
59
|
+
# bar,
|
60
|
+
# {
|
61
|
+
# baz: "a",
|
62
|
+
# qux: "b",
|
63
|
+
# }
|
64
|
+
# )
|
72
65
|
#
|
73
|
-
# # ignored
|
74
|
-
# method foo, bar,
|
75
|
-
# baz
|
76
66
|
class FirstMethodArgumentLineBreak < Base
|
77
67
|
include FirstElementLineBreak
|
78
68
|
extend AutoCorrector
|
@@ -6,69 +6,52 @@ module RuboCop
|
|
6
6
|
# Checks for a line break before the first parameter in a
|
7
7
|
# multi-line method parameter definition.
|
8
8
|
#
|
9
|
-
# @example
|
10
|
-
#
|
11
|
-
# # bad
|
12
|
-
# def method(foo, bar,
|
13
|
-
# baz)
|
14
|
-
# do_something
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# # bad
|
18
|
-
# def method(foo, bar, baz = {
|
19
|
-
# :a => "b",
|
20
|
-
# })
|
21
|
-
# do_something
|
22
|
-
# end
|
9
|
+
# @example
|
23
10
|
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
# end
|
11
|
+
# # bad
|
12
|
+
# def method(foo, bar,
|
13
|
+
# baz)
|
14
|
+
# do_something
|
15
|
+
# end
|
30
16
|
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# foo, bar,
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# end
|
17
|
+
# # good
|
18
|
+
# def method(
|
19
|
+
# foo, bar,
|
20
|
+
# baz)
|
21
|
+
# do_something
|
22
|
+
# end
|
38
23
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
24
|
+
# # ignored
|
25
|
+
# def method foo,
|
26
|
+
# bar
|
27
|
+
# do_something
|
28
|
+
# end
|
44
29
|
#
|
45
|
-
# @example AllowMultilineFinalElement:
|
30
|
+
# @example AllowMultilineFinalElement: false (default)
|
46
31
|
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
32
|
+
# # bad
|
33
|
+
# def method(foo, bar, baz = {
|
34
|
+
# :a => "b",
|
35
|
+
# })
|
36
|
+
# do_something
|
37
|
+
# end
|
52
38
|
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
39
|
+
# # good
|
40
|
+
# def method(
|
41
|
+
# foo, bar, baz = {
|
42
|
+
# :a => "b",
|
43
|
+
# })
|
44
|
+
# do_something
|
45
|
+
# end
|
59
46
|
#
|
60
|
-
#
|
61
|
-
# def method(
|
62
|
-
# foo, bar,
|
63
|
-
# baz)
|
64
|
-
# do_something
|
65
|
-
# end
|
47
|
+
# @example AllowMultilineFinalElement: true
|
66
48
|
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
49
|
+
# # good
|
50
|
+
# def method(foo, bar, baz = {
|
51
|
+
# :a => "b",
|
52
|
+
# })
|
53
|
+
# do_something
|
54
|
+
# end
|
72
55
|
#
|
73
56
|
class FirstMethodParameterLineBreak < Base
|
74
57
|
include FirstElementLineBreak
|
@@ -67,7 +67,7 @@ module RuboCop
|
|
67
67
|
|
68
68
|
outermost_send = outermost_send_on_same_line(heredoc_arg)
|
69
69
|
return unless outermost_send
|
70
|
-
return if
|
70
|
+
return if end_keyword_before_closing_parenthesis?(node)
|
71
71
|
return if subsequent_closing_parentheses_in_same_line?(outermost_send)
|
72
72
|
return if exist_argument_between_heredoc_end_and_closing_parentheses?(node)
|
73
73
|
|
@@ -159,7 +159,7 @@ module RuboCop
|
|
159
159
|
|
160
160
|
# Closing parenthesis helpers.
|
161
161
|
|
162
|
-
def
|
162
|
+
def end_keyword_before_closing_parenthesis?(parenthesized_send_node)
|
163
163
|
parenthesized_send_node.ancestors.any? do |ancestor|
|
164
164
|
ancestor.loc.respond_to?(:end) && ancestor.loc.end&.source == 'end'
|
165
165
|
end
|
@@ -228,9 +228,9 @@ module RuboCop
|
|
228
228
|
end
|
229
229
|
|
230
230
|
def find_most_bottom_of_heredoc_end(arguments)
|
231
|
-
arguments.
|
231
|
+
arguments.filter_map do |argument|
|
232
232
|
argument.loc.heredoc_end.end_pos if argument.loc.respond_to?(:heredoc_end)
|
233
|
-
end.
|
233
|
+
end.max
|
234
234
|
end
|
235
235
|
|
236
236
|
# Internal trailing comma helpers.
|
@@ -115,7 +115,7 @@ module RuboCop
|
|
115
115
|
end
|
116
116
|
|
117
117
|
def adjust_minus(corrector, node)
|
118
|
-
heredoc_beginning = node.
|
118
|
+
heredoc_beginning = node.source
|
119
119
|
corrected = heredoc_beginning.sub(/<<-?/, '<<~')
|
120
120
|
corrector.replace(node, corrected)
|
121
121
|
end
|
@@ -139,7 +139,7 @@ module RuboCop
|
|
139
139
|
end
|
140
140
|
|
141
141
|
def base_indent_level(node)
|
142
|
-
base_line_num = node.
|
142
|
+
base_line_num = node.source_range.line
|
143
143
|
base_line = processed_source.lines[base_line_num - 1]
|
144
144
|
indent_level(base_line)
|
145
145
|
end
|
@@ -51,12 +51,11 @@ module RuboCop
|
|
51
51
|
private_constant :LINE_1_ENDING, :LINE_2_BEGINNING,
|
52
52
|
:LEADING_STYLE_OFFENSE, :TRAILING_STYLE_OFFENSE
|
53
53
|
|
54
|
-
# rubocop:disable Metrics/AbcSize
|
55
54
|
def on_dstr(node)
|
56
55
|
# Quick check if we possibly have line continuations.
|
57
56
|
return unless node.source.include?('\\')
|
58
57
|
|
59
|
-
end_of_first_line = node.
|
58
|
+
end_of_first_line = node.source_range.begin_pos - node.source_range.column
|
60
59
|
|
61
60
|
raw_lines(node).each_cons(2) do |raw_line_one, raw_line_two|
|
62
61
|
end_of_first_line += raw_line_one.length
|
@@ -70,7 +69,6 @@ module RuboCop
|
|
70
69
|
end
|
71
70
|
end
|
72
71
|
end
|
73
|
-
# rubocop:enable Metrics/AbcSize
|
74
72
|
|
75
73
|
private
|
76
74
|
|
@@ -6,7 +6,7 @@ module RuboCop
|
|
6
6
|
# Ensures that each item in a multi-line array
|
7
7
|
# starts on a separate line.
|
8
8
|
#
|
9
|
-
# @example
|
9
|
+
# @example
|
10
10
|
#
|
11
11
|
# # bad
|
12
12
|
# [
|
@@ -14,11 +14,6 @@ module RuboCop
|
|
14
14
|
# c
|
15
15
|
# ]
|
16
16
|
#
|
17
|
-
# # bad
|
18
|
-
# [ a, b, foo(
|
19
|
-
# bar
|
20
|
-
# )]
|
21
|
-
#
|
22
17
|
# # good
|
23
18
|
# [
|
24
19
|
# a,
|
@@ -35,34 +30,20 @@ module RuboCop
|
|
35
30
|
# )
|
36
31
|
# ]
|
37
32
|
#
|
38
|
-
# @example AllowMultilineFinalElement:
|
33
|
+
# @example AllowMultilineFinalElement: false (default)
|
39
34
|
#
|
40
35
|
# # bad
|
41
|
-
# [
|
42
|
-
# a, b,
|
43
|
-
# c
|
44
|
-
# ]
|
45
|
-
#
|
46
|
-
# # good
|
47
|
-
# [ a, b, foo(
|
36
|
+
# [a, b, foo(
|
48
37
|
# bar
|
49
38
|
# )]
|
50
39
|
#
|
51
|
-
#
|
52
|
-
# [
|
53
|
-
# a,
|
54
|
-
# b,
|
55
|
-
# c
|
56
|
-
# ]
|
40
|
+
# @example AllowMultilineFinalElement: true
|
57
41
|
#
|
58
42
|
# # good
|
59
|
-
# [
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
# bar
|
64
|
-
# )
|
65
|
-
# ]
|
43
|
+
# [a, b, foo(
|
44
|
+
# bar
|
45
|
+
# )]
|
46
|
+
#
|
66
47
|
class MultilineArrayLineBreaks < Base
|
67
48
|
include MultilineElementLineBreaks
|
68
49
|
extend AutoCorrector
|
@@ -6,7 +6,7 @@ module RuboCop
|
|
6
6
|
# Ensures that each key in a multi-line hash
|
7
7
|
# starts on a separate line.
|
8
8
|
#
|
9
|
-
# @example
|
9
|
+
# @example
|
10
10
|
#
|
11
11
|
# # bad
|
12
12
|
# {
|
@@ -14,11 +14,6 @@ module RuboCop
|
|
14
14
|
# c: 3
|
15
15
|
# }
|
16
16
|
#
|
17
|
-
# # bad
|
18
|
-
# { a: 1, b: {
|
19
|
-
# c: 3,
|
20
|
-
# }}
|
21
|
-
#
|
22
17
|
# # good
|
23
18
|
# {
|
24
19
|
# a: 1,
|
@@ -34,34 +29,20 @@ module RuboCop
|
|
34
29
|
# }
|
35
30
|
# }
|
36
31
|
#
|
37
|
-
# @example AllowMultilineFinalElement:
|
32
|
+
# @example AllowMultilineFinalElement: false (default)
|
38
33
|
#
|
39
34
|
# # bad
|
40
|
-
# {
|
41
|
-
# a: 1, b: 2,
|
42
|
-
# c: 3
|
43
|
-
# }
|
44
|
-
#
|
45
|
-
# # good
|
46
35
|
# { a: 1, b: {
|
47
36
|
# c: 3,
|
48
37
|
# }}
|
49
38
|
#
|
50
|
-
#
|
51
|
-
# {
|
52
|
-
# a: 1,
|
53
|
-
# b: 2,
|
54
|
-
# c: 3
|
55
|
-
# }
|
56
|
-
#
|
39
|
+
# @example AllowMultilineFinalElement: true
|
57
40
|
#
|
58
41
|
# # good
|
59
|
-
# {
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
# }
|
64
|
-
# }
|
42
|
+
# { a: 1, b: {
|
43
|
+
# c: 3,
|
44
|
+
# }}
|
45
|
+
#
|
65
46
|
class MultilineHashKeyLineBreaks < Base
|
66
47
|
include MultilineElementLineBreaks
|
67
48
|
extend AutoCorrector
|
@@ -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/FirstMethodArgumentLineBreak`.
|
11
11
|
#
|
12
|
-
# @example
|
12
|
+
# @example
|
13
13
|
#
|
14
14
|
# # bad
|
15
15
|
# foo(a, b,
|
@@ -31,6 +31,8 @@ module RuboCop
|
|
31
31
|
# # good
|
32
32
|
# foo(a, b, c)
|
33
33
|
#
|
34
|
+
# @example AllowMultilineFinalElement: false (default)
|
35
|
+
#
|
34
36
|
# # good
|
35
37
|
# foo(
|
36
38
|
# a,
|
@@ -42,26 +44,6 @@ module RuboCop
|
|
42
44
|
#
|
43
45
|
# @example AllowMultilineFinalElement: true
|
44
46
|
#
|
45
|
-
# # bad
|
46
|
-
# foo(a, b,
|
47
|
-
# c
|
48
|
-
# )
|
49
|
-
#
|
50
|
-
# # good
|
51
|
-
# foo(a, b, {
|
52
|
-
# foo: "bar",
|
53
|
-
# })
|
54
|
-
#
|
55
|
-
# # good
|
56
|
-
# foo(
|
57
|
-
# a,
|
58
|
-
# b,
|
59
|
-
# c
|
60
|
-
# )
|
61
|
-
#
|
62
|
-
# # good
|
63
|
-
# foo(a, b, c)
|
64
|
-
#
|
65
47
|
# # good
|
66
48
|
# foo(
|
67
49
|
# a,
|
@@ -70,6 +52,7 @@ module RuboCop
|
|
70
52
|
# foo: "bar",
|
71
53
|
# }
|
72
54
|
# )
|
55
|
+
#
|
73
56
|
class MultilineMethodArgumentLineBreaks < Base
|
74
57
|
include MultilineElementLineBreaks
|
75
58
|
extend AutoCorrector
|
@@ -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
|