rubocop 1.72.1 → 1.81.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +22 -18
- data/config/default.yml +240 -65
- data/config/internal_affairs.yml +20 -0
- data/config/obsoletion.yml +8 -3
- data/exe/rubocop +1 -8
- data/lib/rubocop/cli/command/auto_generate_config.rb +2 -2
- data/lib/rubocop/cli.rb +19 -4
- data/lib/rubocop/config.rb +35 -6
- data/lib/rubocop/config_loader.rb +8 -40
- data/lib/rubocop/config_loader_resolver.rb +9 -7
- data/lib/rubocop/config_obsoletion/extracted_cop.rb +4 -3
- data/lib/rubocop/config_obsoletion/renamed_cop.rb +18 -3
- data/lib/rubocop/config_obsoletion.rb +46 -2
- data/lib/rubocop/config_store.rb +5 -0
- data/lib/rubocop/config_validator.rb +7 -6
- data/lib/rubocop/cop/autocorrect_logic.rb +22 -14
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +7 -4
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -2
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +5 -2
- data/lib/rubocop/cop/gemspec/attribute_assignment.rb +91 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +37 -15
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/gemspec/require_mfa.rb +15 -1
- data/lib/rubocop/cop/internal_affairs/example_description.rb +9 -5
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +4 -4
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +6 -2
- data/lib/rubocop/cop/internal_affairs/node_type_group.rb +92 -0
- data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +6 -5
- data/lib/rubocop/cop/internal_affairs/undefined_config.rb +6 -1
- data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +1 -1
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/block_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/block_end_newline.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +36 -1
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -5
- data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +32 -14
- data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +101 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +34 -4
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +8 -29
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +1 -0
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/hash_alignment.rb +4 -7
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -0
- data/lib/rubocop/cop/layout/leading_comment_space.rb +13 -1
- data/lib/rubocop/cop/layout/line_length.rb +43 -10
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +9 -5
- data/lib/rubocop/cop/layout/redundant_line_break.rb +9 -5
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +11 -5
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +10 -0
- data/lib/rubocop/cop/layout/space_around_keyword.rb +6 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +12 -1
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -0
- data/lib/rubocop/cop/layout/space_before_brackets.rb +5 -38
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +12 -3
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -0
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +3 -0
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_range.rb +5 -0
- data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +2 -3
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -5
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +3 -2
- data/lib/rubocop/cop/lint/cop_directive_syntax.rb +13 -7
- data/lib/rubocop/cop/lint/debugger.rb +2 -4
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +5 -2
- data/lib/rubocop/cop/lint/duplicate_methods.rb +111 -23
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +14 -64
- data/lib/rubocop/cop/lint/empty_interpolation.rb +14 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +0 -6
- data/lib/rubocop/cop/lint/float_comparison.rb +32 -10
- data/lib/rubocop/cop/lint/identity_comparison.rb +19 -15
- data/lib/rubocop/cop/lint/literal_as_condition.rb +124 -10
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +17 -8
- data/lib/rubocop/cop/lint/mixed_case_range.rb +2 -2
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -3
- data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +1 -0
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
- data/lib/rubocop/cop/lint/raise_exception.rb +29 -10
- data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +0 -21
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +101 -2
- data/lib/rubocop/cop/lint/redundant_type_conversion.rb +43 -13
- data/lib/rubocop/cop/lint/redundant_with_index.rb +3 -0
- data/lib/rubocop/cop/lint/redundant_with_object.rb +3 -0
- data/lib/rubocop/cop/lint/require_range_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -4
- data/lib/rubocop/cop/lint/rescue_type.rb +1 -1
- data/lib/rubocop/cop/lint/return_in_void_context.rb +9 -11
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +4 -4
- data/lib/rubocop/cop/lint/self_assignment.rb +31 -5
- data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +13 -1
- data/lib/rubocop/cop/lint/shared_mutable_default.rb +12 -1
- data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
- data/lib/rubocop/cop/lint/unexpected_block_arity.rb +2 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_loop.rb +5 -5
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +30 -4
- data/lib/rubocop/cop/lint/useless_assignment.rb +2 -0
- data/lib/rubocop/cop/lint/useless_constant_scoping.rb +9 -12
- data/lib/rubocop/cop/lint/useless_default_value_argument.rb +90 -0
- data/lib/rubocop/cop/lint/useless_numeric_operation.rb +1 -0
- data/lib/rubocop/cop/lint/useless_or.rb +98 -0
- data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +3 -3
- data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +121 -0
- data/lib/rubocop/cop/lint/void.rb +16 -2
- data/lib/rubocop/cop/message_annotator.rb +7 -3
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/block_length.rb +1 -0
- data/lib/rubocop/cop/metrics/method_length.rb +1 -0
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +4 -4
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -3
- data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +2 -2
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
- data/lib/rubocop/cop/mixin/forbidden_identifiers.rb +20 -0
- data/lib/rubocop/cop/mixin/forbidden_pattern.rb +16 -0
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -2
- data/lib/rubocop/cop/mixin/gemspec_help.rb +22 -0
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +15 -14
- data/lib/rubocop/cop/mixin/hash_subset.rb +19 -4
- data/lib/rubocop/cop/mixin/line_length_help.rb +24 -8
- data/lib/rubocop/cop/mixin/method_complexity.rb +1 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +12 -0
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +1 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +18 -2
- data/lib/rubocop/cop/naming/block_forwarding.rb +3 -3
- data/lib/rubocop/cop/naming/file_name.rb +2 -2
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +187 -15
- data/lib/rubocop/cop/naming/predicate_method.rb +319 -0
- data/lib/rubocop/cop/naming/{predicate_name.rb → predicate_prefix.rb} +4 -4
- data/lib/rubocop/cop/naming/variable_name.rb +51 -6
- data/lib/rubocop/cop/registry.rb +9 -6
- data/lib/rubocop/cop/security/eval.rb +2 -1
- data/lib/rubocop/cop/security/json_load.rb +33 -11
- data/lib/rubocop/cop/security/open.rb +1 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +32 -10
- data/lib/rubocop/cop/style/accessor_grouping.rb +32 -6
- data/lib/rubocop/cop/style/arguments_forwarding.rb +21 -24
- data/lib/rubocop/cop/style/array_intersect.rb +113 -38
- data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -0
- data/lib/rubocop/cop/style/bitwise_predicate.rb +8 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +3 -2
- data/lib/rubocop/cop/style/case_like_if.rb +1 -1
- data/lib/rubocop/cop/style/class_and_module_children.rb +48 -10
- data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -1
- data/lib/rubocop/cop/style/collection_methods.rb +1 -0
- data/lib/rubocop/cop/style/collection_querying.rb +167 -0
- data/lib/rubocop/cop/style/combinable_loops.rb +1 -0
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +12 -5
- data/lib/rubocop/cop/style/comparable_between.rb +78 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +26 -8
- data/lib/rubocop/cop/style/constant_visibility.rb +14 -9
- data/lib/rubocop/cop/style/data_inheritance.rb +7 -0
- data/lib/rubocop/cop/style/def_with_parentheses.rb +18 -5
- data/lib/rubocop/cop/style/dig_chain.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +3 -3
- data/lib/rubocop/cop/style/empty_literal.rb +4 -0
- data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +100 -0
- data/lib/rubocop/cop/style/endless_method.rb +176 -18
- data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -7
- data/lib/rubocop/cop/style/explicit_block_argument.rb +3 -3
- data/lib/rubocop/cop/style/exponential_notation.rb +5 -4
- data/lib/rubocop/cop/style/fetch_env_var.rb +32 -6
- data/lib/rubocop/cop/style/float_division.rb +15 -1
- data/lib/rubocop/cop/style/for.rb +1 -0
- data/lib/rubocop/cop/style/format_string_token.rb +38 -11
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -2
- data/lib/rubocop/cop/style/global_std_stream.rb +3 -0
- data/lib/rubocop/cop/style/guard_clause.rb +2 -1
- data/lib/rubocop/cop/style/hash_conversion.rb +16 -8
- data/lib/rubocop/cop/style/hash_each_methods.rb +3 -2
- data/lib/rubocop/cop/style/hash_fetch_chain.rb +104 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -1
- 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/identical_conditional_branches.rb +3 -3
- data/lib/rubocop/cop/style/if_inside_else.rb +10 -13
- data/lib/rubocop/cop/style/if_unless_modifier.rb +35 -8
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +4 -7
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +10 -6
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +2 -2
- data/lib/rubocop/cop/style/ip_addresses.rb +2 -2
- data/lib/rubocop/cop/style/it_assignment.rb +69 -12
- data/lib/rubocop/cop/style/it_block_parameter.rb +121 -0
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +13 -7
- data/lib/rubocop/cop/style/lambda.rb +1 -0
- data/lib/rubocop/cop/style/lambda_call.rb +7 -2
- data/lib/rubocop/cop/style/line_end_concatenation.rb +10 -4
- data/lib/rubocop/cop/style/map_into_array.rb +4 -1
- data/lib/rubocop/cop/style/map_to_hash.rb +12 -3
- data/lib/rubocop/cop/style/map_to_set.rb +1 -3
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +9 -8
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +16 -0
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -1
- data/lib/rubocop/cop/style/min_max_comparison.rb +13 -5
- data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -1
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -0
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -9
- data/lib/rubocop/cop/style/next.rb +44 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +9 -7
- data/lib/rubocop/cop/style/object_then.rb +1 -0
- data/lib/rubocop/cop/style/one_line_conditional.rb +17 -9
- data/lib/rubocop/cop/style/parallel_assignment.rb +32 -20
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -0
- data/lib/rubocop/cop/style/raise_args.rb +8 -8
- data/lib/rubocop/cop/style/redundant_array_flatten.rb +50 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +35 -0
- data/lib/rubocop/cop/style/redundant_condition.rb +57 -0
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +14 -4
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -9
- data/lib/rubocop/cop/style/redundant_format.rb +79 -18
- data/lib/rubocop/cop/style/redundant_freeze.rb +2 -2
- data/lib/rubocop/cop/style/redundant_interpolation.rb +12 -3
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +1 -4
- data/lib/rubocop/cop/style/redundant_parentheses.rb +73 -18
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +4 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -0
- data/lib/rubocop/cop/style/redundant_self.rb +9 -5
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/redundant_sort_by.rb +17 -1
- data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
- data/lib/rubocop/cop/style/rescue_modifier.rb +3 -0
- data/lib/rubocop/cop/style/return_nil.rb +2 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +61 -14
- data/lib/rubocop/cop/style/select_by_regexp.rb +4 -1
- data/lib/rubocop/cop/style/semicolon.rb +23 -7
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +3 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +10 -7
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +75 -101
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/string_concatenation.rb +18 -15
- data/lib/rubocop/cop/style/struct_inheritance.rb +8 -1
- data/lib/rubocop/cop/style/super_arguments.rb +1 -2
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +3 -1
- data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -0
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +52 -1
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +47 -6
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +48 -6
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_else.rb +10 -9
- data/lib/rubocop/cop/team.rb +1 -1
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/utils/format_string.rb +15 -2
- data/lib/rubocop/cop/variable_force/assignment.rb +7 -3
- data/lib/rubocop/cop/variable_force/scope.rb +1 -1
- data/lib/rubocop/cop/variable_force/variable.rb +3 -8
- data/lib/rubocop/cop/variable_force.rb +26 -9
- data/lib/rubocop/cops_documentation_generator.rb +23 -7
- data/lib/rubocop/directive_comment.rb +1 -1
- data/lib/rubocop/ext/regexp_node.rb +0 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +19 -5
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/html_formatter.rb +1 -1
- data/lib/rubocop/formatter/markdown_formatter.rb +1 -0
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
- data/lib/rubocop/formatter/pacman_formatter.rb +2 -1
- data/lib/rubocop/lsp/diagnostic.rb +25 -24
- data/lib/rubocop/lsp/routes.rb +65 -9
- data/lib/rubocop/lsp/runtime.rb +5 -5
- data/lib/rubocop/lsp/server.rb +2 -2
- data/lib/rubocop/lsp/stdin_runner.rb +3 -17
- data/lib/rubocop/magic_comment.rb +8 -0
- data/lib/rubocop/pending_cops_reporter.rb +56 -0
- data/lib/rubocop/plugin/configuration_integrator.rb +2 -0
- data/lib/rubocop/plugin/load_error.rb +1 -1
- data/lib/rubocop/plugin.rb +9 -2
- data/lib/rubocop/result_cache.rb +14 -12
- data/lib/rubocop/rspec/cop_helper.rb +6 -1
- data/lib/rubocop/rspec/expect_offense.rb +9 -3
- data/lib/rubocop/rspec/shared_contexts.rb +34 -0
- data/lib/rubocop/rspec/support.rb +3 -0
- data/lib/rubocop/runner.rb +10 -4
- data/lib/rubocop/server/cache.rb +17 -12
- data/lib/rubocop/server/client_command/base.rb +10 -0
- data/lib/rubocop/server/client_command/exec.rb +2 -1
- data/lib/rubocop/server/client_command/start.rb +11 -1
- data/lib/rubocop/target_finder.rb +13 -9
- data/lib/rubocop/target_ruby.rb +11 -2
- data/lib/rubocop/version.rb +14 -7
- data/lib/rubocop.rb +17 -2
- data/lib/ruby_lsp/rubocop/addon.rb +25 -10
- data/lib/ruby_lsp/rubocop/runtime_adapter.rb +57 -5
- metadata +24 -8
- data/lib/rubocop/cop/utils/regexp_ranges.rb +0 -113
|
@@ -92,7 +92,7 @@ module RuboCop
|
|
|
92
92
|
case parent.type
|
|
93
93
|
when :def, :defs then base_for_method_definition(parent)
|
|
94
94
|
when :kwbegin then parent.loc.begin
|
|
95
|
-
when :block, :numblock
|
|
95
|
+
when :block, :numblock, :itblock
|
|
96
96
|
assignment_node = assignment_node(parent)
|
|
97
97
|
if same_line?(parent, assignment_node)
|
|
98
98
|
assignment_node.source_range
|
|
@@ -76,28 +76,40 @@ module RuboCop
|
|
|
76
76
|
# # good
|
|
77
77
|
# class ErrorA < BaseError; end
|
|
78
78
|
# class ErrorB < BaseError; end
|
|
79
|
-
# class ErrorC < BaseError; end
|
|
80
79
|
#
|
|
81
80
|
# # good
|
|
82
81
|
# class ErrorA < BaseError; end
|
|
83
82
|
#
|
|
84
83
|
# class ErrorB < BaseError; end
|
|
85
84
|
#
|
|
86
|
-
#
|
|
85
|
+
# # good - DefLikeMacros: [memoize]
|
|
86
|
+
# memoize :attribute_a
|
|
87
|
+
# memoize :attribute_b
|
|
88
|
+
#
|
|
89
|
+
# # good
|
|
90
|
+
# memoize :attribute_a
|
|
91
|
+
#
|
|
92
|
+
# memoize :attribute_b
|
|
87
93
|
#
|
|
88
94
|
# @example AllowAdjacentOneLineDefs: false
|
|
89
95
|
#
|
|
90
96
|
# # bad
|
|
91
97
|
# class ErrorA < BaseError; end
|
|
92
98
|
# class ErrorB < BaseError; end
|
|
93
|
-
# class ErrorC < BaseError; end
|
|
94
99
|
#
|
|
95
100
|
# # good
|
|
96
101
|
# class ErrorA < BaseError; end
|
|
97
102
|
#
|
|
98
103
|
# class ErrorB < BaseError; end
|
|
99
104
|
#
|
|
100
|
-
#
|
|
105
|
+
# # bad - DefLikeMacros: [memoize]
|
|
106
|
+
# memoize :attribute_a
|
|
107
|
+
# memoize :attribute_b
|
|
108
|
+
#
|
|
109
|
+
# # good
|
|
110
|
+
# memoize :attribute_a
|
|
111
|
+
#
|
|
112
|
+
# memoize :attribute_b
|
|
101
113
|
#
|
|
102
114
|
class EmptyLineBetweenDefs < Base
|
|
103
115
|
include RangeHelp
|
|
@@ -158,6 +170,8 @@ module RuboCop
|
|
|
158
170
|
def def_location(correction_node)
|
|
159
171
|
if correction_node.any_block_type?
|
|
160
172
|
correction_node.source_range.join(correction_node.children.first.source_range)
|
|
173
|
+
elsif correction_node.send_type?
|
|
174
|
+
correction_node.source_range
|
|
161
175
|
else
|
|
162
176
|
correction_node.loc.keyword.join(correction_node.loc.name)
|
|
163
177
|
end
|
|
@@ -175,12 +189,18 @@ module RuboCop
|
|
|
175
189
|
end
|
|
176
190
|
|
|
177
191
|
def macro_candidate?(node)
|
|
178
|
-
|
|
179
|
-
|
|
192
|
+
macro_candidate = if node.any_block_type?
|
|
193
|
+
node.send_node
|
|
194
|
+
elsif node.send_type?
|
|
195
|
+
node
|
|
196
|
+
end
|
|
197
|
+
return false unless macro_candidate
|
|
198
|
+
|
|
199
|
+
macro_candidate.macro? && empty_line_between_macros.include?(macro_candidate.method_name)
|
|
180
200
|
end
|
|
181
201
|
|
|
182
202
|
def method_candidate?(node)
|
|
183
|
-
cop_config['EmptyLineBetweenMethodDefs'] && node.
|
|
203
|
+
cop_config['EmptyLineBetweenMethodDefs'] && node.any_def_type?
|
|
184
204
|
end
|
|
185
205
|
|
|
186
206
|
def class_candidate?(node)
|
|
@@ -240,7 +260,9 @@ module RuboCop
|
|
|
240
260
|
end
|
|
241
261
|
|
|
242
262
|
def def_start(node)
|
|
243
|
-
|
|
263
|
+
node = node.send_node if node.any_block_type?
|
|
264
|
+
|
|
265
|
+
if node.send_type?
|
|
244
266
|
node.source_range.line
|
|
245
267
|
else
|
|
246
268
|
node.loc.keyword.line
|
|
@@ -252,11 +274,7 @@ module RuboCop
|
|
|
252
274
|
end
|
|
253
275
|
|
|
254
276
|
def end_loc(node)
|
|
255
|
-
|
|
256
|
-
node.source_range.end
|
|
257
|
-
else
|
|
258
|
-
node.loc.end
|
|
259
|
-
end
|
|
277
|
+
node.source_range.end
|
|
260
278
|
end
|
|
261
279
|
|
|
262
280
|
def autocorrect_remove_lines(corrector, newline_pos, count)
|
|
@@ -277,7 +295,7 @@ module RuboCop
|
|
|
277
295
|
case node.type
|
|
278
296
|
when :def, :defs
|
|
279
297
|
:method
|
|
280
|
-
when :numblock
|
|
298
|
+
when :numblock, :itblock
|
|
281
299
|
:block
|
|
282
300
|
else
|
|
283
301
|
node.type
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Layout
|
|
6
|
+
# Checks for an empty line after a module inclusion method (`extend`,
|
|
7
|
+
# `include` and `prepend`), or a group of them.
|
|
8
|
+
#
|
|
9
|
+
# @example
|
|
10
|
+
# # bad
|
|
11
|
+
# class Foo
|
|
12
|
+
# include Bar
|
|
13
|
+
# attr_reader :baz
|
|
14
|
+
# end
|
|
15
|
+
#
|
|
16
|
+
# # good
|
|
17
|
+
# class Foo
|
|
18
|
+
# include Bar
|
|
19
|
+
#
|
|
20
|
+
# attr_reader :baz
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
23
|
+
# # also good - multiple module inclusions grouped together
|
|
24
|
+
# class Foo
|
|
25
|
+
# extend Bar
|
|
26
|
+
# include Baz
|
|
27
|
+
# prepend Qux
|
|
28
|
+
# end
|
|
29
|
+
#
|
|
30
|
+
class EmptyLinesAfterModuleInclusion < Base
|
|
31
|
+
include RangeHelp
|
|
32
|
+
extend AutoCorrector
|
|
33
|
+
|
|
34
|
+
MSG = 'Add an empty line after module inclusion.'
|
|
35
|
+
|
|
36
|
+
MODULE_INCLUSION_METHODS = %i[include extend prepend].freeze
|
|
37
|
+
|
|
38
|
+
RESTRICT_ON_SEND = MODULE_INCLUSION_METHODS
|
|
39
|
+
|
|
40
|
+
def on_send(node)
|
|
41
|
+
return if node.receiver || node.arguments.empty?
|
|
42
|
+
return if node.parent&.type?(:send, :any_block)
|
|
43
|
+
|
|
44
|
+
return if next_line_empty_or_enable_directive_comment?(node.last_line)
|
|
45
|
+
|
|
46
|
+
next_line_node = next_line_node(node)
|
|
47
|
+
return unless require_empty_line?(next_line_node)
|
|
48
|
+
|
|
49
|
+
add_offense(node) { |corrector| autocorrect(corrector, node) }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def autocorrect(corrector, node)
|
|
55
|
+
node_range = range_by_whole_lines(node.source_range)
|
|
56
|
+
|
|
57
|
+
next_line = node_range.last_line + 1
|
|
58
|
+
if enable_directive_comment?(next_line)
|
|
59
|
+
node_range = processed_source.comment_at_line(next_line)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
corrector.insert_after(node_range, "\n")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def next_line_empty_or_enable_directive_comment?(line)
|
|
66
|
+
line_empty?(line) || (enable_directive_comment?(line + 1) && line_empty?(line + 1))
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def enable_directive_comment?(line)
|
|
70
|
+
return false unless (comment = processed_source.comment_at_line(line))
|
|
71
|
+
|
|
72
|
+
DirectiveComment.new(comment).enabled?
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def line_empty?(line)
|
|
76
|
+
processed_source[line].nil? || processed_source[line].blank?
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def require_empty_line?(node)
|
|
80
|
+
return false unless node
|
|
81
|
+
|
|
82
|
+
!allowed_method?(node)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def allowed_method?(node)
|
|
86
|
+
node = node.body if node.respond_to?(:modifier_form?) && node.modifier_form?
|
|
87
|
+
|
|
88
|
+
return false unless node.send_type?
|
|
89
|
+
|
|
90
|
+
MODULE_INCLUSION_METHODS.include?(node.method_name)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def next_line_node(node)
|
|
94
|
+
return if node.parent.if_type?
|
|
95
|
+
|
|
96
|
+
node.right_sibling
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -83,6 +83,7 @@ module RuboCop
|
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
alias on_numblock on_block
|
|
86
|
+
alias on_itblock on_block
|
|
86
87
|
|
|
87
88
|
def on_send(node)
|
|
88
89
|
return unless node.bare_access_modifier? && !node.block_literal?
|
|
@@ -93,7 +94,7 @@ module RuboCop
|
|
|
93
94
|
add_offense(node, message: message) do |corrector|
|
|
94
95
|
line = range_by_whole_lines(node.source_range)
|
|
95
96
|
|
|
96
|
-
corrector.insert_before(line, "\n")
|
|
97
|
+
corrector.insert_before(line, "\n") if should_insert_line_before?(node)
|
|
97
98
|
|
|
98
99
|
correct_next_line_if_denied_style(corrector, node, line)
|
|
99
100
|
end
|
|
@@ -115,18 +116,20 @@ module RuboCop
|
|
|
115
116
|
def allowed_only_before_style?(node)
|
|
116
117
|
if node.special_modifier?
|
|
117
118
|
return true if processed_source[node.last_line] == 'end'
|
|
118
|
-
return false if
|
|
119
|
+
return false if next_line_empty_and_exists?(node.last_line)
|
|
119
120
|
end
|
|
120
121
|
|
|
121
122
|
previous_line_empty?(node.first_line)
|
|
122
123
|
end
|
|
123
124
|
|
|
124
125
|
def correct_next_line_if_denied_style(corrector, node, line)
|
|
126
|
+
return unless should_insert_line_after?(node)
|
|
127
|
+
|
|
125
128
|
case style
|
|
126
129
|
when :around
|
|
127
130
|
corrector.insert_after(line, "\n") unless next_line_empty?(node.last_line)
|
|
128
131
|
when :only_before
|
|
129
|
-
if
|
|
132
|
+
if next_line_empty_and_exists?(node.last_line)
|
|
130
133
|
range = next_empty_line_range(node)
|
|
131
134
|
|
|
132
135
|
corrector.remove(range)
|
|
@@ -135,7 +138,7 @@ module RuboCop
|
|
|
135
138
|
end
|
|
136
139
|
|
|
137
140
|
def previous_line_ignoring_comments(processed_source, send_line)
|
|
138
|
-
processed_source[0..send_line - 2].reverse.find { |line| !comment_line?(line) }
|
|
141
|
+
processed_source[0..(send_line - 2)].reverse.find { |line| !comment_line?(line) }
|
|
139
142
|
end
|
|
140
143
|
|
|
141
144
|
def previous_line_empty?(send_line)
|
|
@@ -151,6 +154,10 @@ module RuboCop
|
|
|
151
154
|
body_end?(last_send_line) || next_line.blank?
|
|
152
155
|
end
|
|
153
156
|
|
|
157
|
+
def next_line_empty_and_exists?(last_send_line)
|
|
158
|
+
next_line_empty?(last_send_line) && last_send_line.next != processed_source.lines.size
|
|
159
|
+
end
|
|
160
|
+
|
|
154
161
|
def empty_lines_around?(node)
|
|
155
162
|
previous_line_empty?(node.first_line) && next_line_empty?(node.last_line)
|
|
156
163
|
end
|
|
@@ -205,6 +212,29 @@ module RuboCop
|
|
|
205
212
|
format(MSG_BEFORE_FOR_ONLY_BEFORE, modifier: modifier)
|
|
206
213
|
end
|
|
207
214
|
end
|
|
215
|
+
|
|
216
|
+
def should_insert_line_before?(node)
|
|
217
|
+
return false if previous_line_empty?(node.first_line)
|
|
218
|
+
return true unless inside_block?(node) && no_empty_lines_around_block_body?
|
|
219
|
+
return true unless node.parent.begin_type?
|
|
220
|
+
|
|
221
|
+
node.parent.children.first != node
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def should_insert_line_after?(node)
|
|
225
|
+
return true unless inside_block?(node) && no_empty_lines_around_block_body?
|
|
226
|
+
|
|
227
|
+
node.parent.children.last != node
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def inside_block?(node)
|
|
231
|
+
node.parent.block_type? || (node.parent.begin_type? && node.parent.parent&.block_type?)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def no_empty_lines_around_block_body?
|
|
235
|
+
config.for_enabled_cop('Layout/EmptyLinesAroundBlockBody')['EnforcedStyle'] ==
|
|
236
|
+
'no_empty_lines'
|
|
237
|
+
end
|
|
208
238
|
end
|
|
209
239
|
end
|
|
210
240
|
end
|
|
@@ -62,40 +62,19 @@ module RuboCop
|
|
|
62
62
|
node.receiver && node.receiver.loc.last_line != node.loc.selector&.line
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
def
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
lines.map { |_, line| line }
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def extra_lines(node)
|
|
72
|
-
empty_lines(node).each do |line|
|
|
73
|
-
range = source_range(processed_source.buffer, line, 0)
|
|
74
|
-
yield(range)
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def processed_lines(node)
|
|
79
|
-
line_numbers(node).each_with_object([]) do |num, array|
|
|
80
|
-
array << [processed_source.lines[num - 1], num]
|
|
65
|
+
def extra_lines(node, &block)
|
|
66
|
+
node.arguments.each do |arg|
|
|
67
|
+
empty_range_for_starting_point(arg.source_range.begin, &block)
|
|
81
68
|
end
|
|
82
|
-
end
|
|
83
69
|
|
|
84
|
-
|
|
85
|
-
inner_lines = []
|
|
86
|
-
line_nums = node.arguments.each_with_object([]) do |arg_node, lines|
|
|
87
|
-
lines << outer_lines(arg_node)
|
|
88
|
-
inner_lines << inner_lines(arg_node) if arg_node.multiline?
|
|
89
|
-
end
|
|
90
|
-
line_nums.flatten.uniq - inner_lines.flatten - outer_lines(node)
|
|
70
|
+
empty_range_for_starting_point(node.loc.end.begin, &block) if node.loc.end
|
|
91
71
|
end
|
|
92
72
|
|
|
93
|
-
def
|
|
94
|
-
|
|
95
|
-
|
|
73
|
+
def empty_range_for_starting_point(start)
|
|
74
|
+
range = range_with_surrounding_space(start, whitespace: true, side: :left)
|
|
75
|
+
return unless range.last_line - range.first_line > 1
|
|
96
76
|
|
|
97
|
-
|
|
98
|
-
[node.first_line - 1, node.last_line + 1]
|
|
77
|
+
yield range.source_buffer.line_range(range.last_line - 1).adjust(end_pos: 1)
|
|
99
78
|
end
|
|
100
79
|
end
|
|
101
80
|
end
|
|
@@ -155,7 +155,7 @@ module RuboCop
|
|
|
155
155
|
def on_send(node)
|
|
156
156
|
return unless should_check?(node)
|
|
157
157
|
return if same_line?(node, node.first_argument)
|
|
158
|
-
return if
|
|
158
|
+
return if enforce_first_argument_with_fixed_indentation? &&
|
|
159
159
|
!enable_layout_first_method_argument_line_break?
|
|
160
160
|
|
|
161
161
|
indent = base_indentation(node) + configured_indentation_width
|
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
|
19
19
|
# * ignore_implicit (without curly braces)
|
|
20
20
|
#
|
|
21
21
|
# Alternatively you can specify multiple allowed styles. That's done by
|
|
22
|
-
# passing a list of styles to
|
|
22
|
+
# passing a list of styles to EnforcedHashRocketStyle and EnforcedColonStyle.
|
|
23
23
|
#
|
|
24
24
|
# @example EnforcedHashRocketStyle: key (default)
|
|
25
25
|
# # bad
|
|
@@ -193,7 +193,6 @@ module RuboCop
|
|
|
193
193
|
SEPARATOR_ALIGNMENT_STYLES = %w[EnforcedColonStyle EnforcedHashRocketStyle].freeze
|
|
194
194
|
|
|
195
195
|
def on_send(node)
|
|
196
|
-
return if double_splat?(node)
|
|
197
196
|
return unless node.arguments?
|
|
198
197
|
|
|
199
198
|
last_argument = node.last_argument
|
|
@@ -233,6 +232,8 @@ module RuboCop
|
|
|
233
232
|
end
|
|
234
233
|
|
|
235
234
|
def argument_before_hash(hash_node)
|
|
235
|
+
return hash_node.children.first.children.first if hash_node.children.first.kwsplat_type?
|
|
236
|
+
|
|
236
237
|
hash_node.left_sibling.respond_to?(:loc) ? hash_node.left_sibling : nil
|
|
237
238
|
end
|
|
238
239
|
|
|
@@ -241,16 +242,12 @@ module RuboCop
|
|
|
241
242
|
self.column_deltas = Hash.new { |hash, key| hash[key] = {} }
|
|
242
243
|
end
|
|
243
244
|
|
|
244
|
-
def double_splat?(node)
|
|
245
|
-
node.children.last.is_a?(Symbol)
|
|
246
|
-
end
|
|
247
|
-
|
|
248
245
|
def check_pairs(node)
|
|
249
246
|
first_pair = node.pairs.first
|
|
250
247
|
reset!
|
|
251
248
|
|
|
252
249
|
alignment_for(first_pair).each do |alignment|
|
|
253
|
-
delta = alignment.deltas_for_first_pair(first_pair
|
|
250
|
+
delta = alignment.deltas_for_first_pair(first_pair)
|
|
254
251
|
check_delta delta, node: first_pair, alignment: alignment
|
|
255
252
|
end
|
|
256
253
|
|
|
@@ -58,6 +58,12 @@ module RuboCop
|
|
|
58
58
|
# attr_reader :name #: String
|
|
59
59
|
# attr_reader :age #: Integer?
|
|
60
60
|
#
|
|
61
|
+
# #: (
|
|
62
|
+
# #| Integer,
|
|
63
|
+
# #| String
|
|
64
|
+
# #| ) -> void
|
|
65
|
+
# def foo; end
|
|
66
|
+
#
|
|
61
67
|
# @example AllowRBSInlineAnnotation: true
|
|
62
68
|
#
|
|
63
69
|
# # good
|
|
@@ -67,6 +73,12 @@ module RuboCop
|
|
|
67
73
|
# attr_reader :name #: String
|
|
68
74
|
# attr_reader :age #: Integer?
|
|
69
75
|
#
|
|
76
|
+
# #: (
|
|
77
|
+
# #| Integer,
|
|
78
|
+
# #| String
|
|
79
|
+
# #| ) -> void
|
|
80
|
+
# def foo; end
|
|
81
|
+
#
|
|
70
82
|
# @example AllowSteepAnnotation: false (default)
|
|
71
83
|
#
|
|
72
84
|
# # bad
|
|
@@ -175,7 +187,7 @@ module RuboCop
|
|
|
175
187
|
end
|
|
176
188
|
|
|
177
189
|
def rbs_inline_annotation?(comment)
|
|
178
|
-
allow_rbs_inline_annotation? && comment.text.start_with?(/#:|#\[.+\]
|
|
190
|
+
allow_rbs_inline_annotation? && comment.text.start_with?(/#:|#\[.+\]|#\|/)
|
|
179
191
|
end
|
|
180
192
|
|
|
181
193
|
def allow_steep_annotation?
|
|
@@ -75,6 +75,7 @@ module RuboCop
|
|
|
75
75
|
check_for_breakable_block(node)
|
|
76
76
|
end
|
|
77
77
|
alias on_numblock on_block
|
|
78
|
+
alias on_itblock on_block
|
|
78
79
|
|
|
79
80
|
def on_str(node)
|
|
80
81
|
check_for_breakable_str(node)
|
|
@@ -92,6 +93,7 @@ module RuboCop
|
|
|
92
93
|
alias on_send on_potential_breakable_node
|
|
93
94
|
alias on_csend on_potential_breakable_node
|
|
94
95
|
alias on_def on_potential_breakable_node
|
|
96
|
+
alias on_defs on_potential_breakable_node
|
|
95
97
|
|
|
96
98
|
def on_new_investigation
|
|
97
99
|
return unless processed_source.raw_source.include?(';')
|
|
@@ -132,6 +134,7 @@ module RuboCop
|
|
|
132
134
|
|
|
133
135
|
def check_for_breakable_block(block_node)
|
|
134
136
|
return unless block_node.single_line?
|
|
137
|
+
return if receiver_contains_heredoc?(block_node)
|
|
135
138
|
|
|
136
139
|
line_index = block_node.loc.line - 1
|
|
137
140
|
range = breakable_block_range(block_node)
|
|
@@ -209,7 +212,7 @@ module RuboCop
|
|
|
209
212
|
# are not bisected.
|
|
210
213
|
# If the string contains spaces, use them to determine a place for a clean break;
|
|
211
214
|
# otherwise, the string will be broken at the line length limit.
|
|
212
|
-
def breakable_string_range(node)
|
|
215
|
+
def breakable_string_range(node)
|
|
213
216
|
source_range = node.source_range
|
|
214
217
|
relevant_substr = largest_possible_string(node)
|
|
215
218
|
|
|
@@ -221,13 +224,13 @@ module RuboCop
|
|
|
221
224
|
adjustment = max - source_range.last_column - 3
|
|
222
225
|
return if adjustment.abs > source_range.size
|
|
223
226
|
|
|
224
|
-
source_range.adjust(end_pos:
|
|
227
|
+
source_range.adjust(end_pos: adjustment)
|
|
225
228
|
end
|
|
226
229
|
end
|
|
227
230
|
|
|
228
231
|
def breakable_dstr_begin_position(node)
|
|
229
232
|
source_range = node.source_range
|
|
230
|
-
source_range.begin_pos if source_range.
|
|
233
|
+
source_range.begin_pos if source_range.column < max && source_range.last_column >= max
|
|
231
234
|
end
|
|
232
235
|
|
|
233
236
|
def breakable_range_by_line_index
|
|
@@ -256,7 +259,7 @@ module RuboCop
|
|
|
256
259
|
if ignore_cop_directives? && directive_on_source_line?(line_index)
|
|
257
260
|
return check_directive_line(line, line_index)
|
|
258
261
|
end
|
|
259
|
-
return
|
|
262
|
+
return check_line_for_exemptions(line, line_index) if allow_uri? || allow_qualified_name?
|
|
260
263
|
|
|
261
264
|
register_offense(excess_range(nil, line, line_index), line, line_index)
|
|
262
265
|
end
|
|
@@ -319,7 +322,7 @@ module RuboCop
|
|
|
319
322
|
def extract_heredocs(ast)
|
|
320
323
|
return [] unless ast
|
|
321
324
|
|
|
322
|
-
ast.each_node(:
|
|
325
|
+
ast.each_node(:any_str).select(&:heredoc?).map do |node|
|
|
323
326
|
body = node.location.heredoc_body
|
|
324
327
|
delimiter = node.location.heredoc_end.source.strip
|
|
325
328
|
[body.first_line...body.last_line, delimiter]
|
|
@@ -339,6 +342,13 @@ module RuboCop
|
|
|
339
342
|
heredocs.any? { |range, _delimiter| range.cover?(line_number) }
|
|
340
343
|
end
|
|
341
344
|
|
|
345
|
+
def receiver_contains_heredoc?(node)
|
|
346
|
+
return false unless (receiver = node.receiver)
|
|
347
|
+
return true if receiver.any_str_type? && receiver.heredoc?
|
|
348
|
+
|
|
349
|
+
receiver.each_descendant(:any_str).any?(&:heredoc?)
|
|
350
|
+
end
|
|
351
|
+
|
|
342
352
|
def check_directive_line(line, line_index)
|
|
343
353
|
length_without_directive = line_length_without_directive(line)
|
|
344
354
|
return if length_without_directive <= max
|
|
@@ -356,11 +366,32 @@ module RuboCop
|
|
|
356
366
|
)
|
|
357
367
|
end
|
|
358
368
|
|
|
359
|
-
def
|
|
360
|
-
uri_range
|
|
361
|
-
|
|
369
|
+
def check_line_for_exemptions(line, line_index)
|
|
370
|
+
uri_range = range_if_applicable(line, :uri)
|
|
371
|
+
qualified_name_range = range_if_applicable(line, :qualified_name)
|
|
372
|
+
|
|
373
|
+
return if allowed_combination?(line, uri_range, qualified_name_range)
|
|
374
|
+
|
|
375
|
+
range = uri_range || qualified_name_range
|
|
376
|
+
register_offense(excess_range(range, line, line_index), line, line_index)
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
def range_if_applicable(line, type)
|
|
380
|
+
return unless type == :uri ? allow_uri? : allow_qualified_name?
|
|
381
|
+
|
|
382
|
+
find_excessive_range(line, type)
|
|
383
|
+
end
|
|
362
384
|
|
|
363
|
-
|
|
385
|
+
def allowed_combination?(line, uri_range, qualified_name_range)
|
|
386
|
+
if uri_range && qualified_name_range
|
|
387
|
+
allowed_position?(line, uri_range) && allowed_position?(line, qualified_name_range)
|
|
388
|
+
elsif uri_range
|
|
389
|
+
allowed_position?(line, uri_range)
|
|
390
|
+
elsif qualified_name_range
|
|
391
|
+
allowed_position?(line, qualified_name_range)
|
|
392
|
+
else
|
|
393
|
+
false
|
|
394
|
+
end
|
|
364
395
|
end
|
|
365
396
|
|
|
366
397
|
def breakable_dstr?(node)
|
|
@@ -370,7 +401,9 @@ module RuboCop
|
|
|
370
401
|
|
|
371
402
|
def string_delimiter(node)
|
|
372
403
|
delimiter = node.loc.begin
|
|
373
|
-
|
|
404
|
+
if node.parent&.dstr_type? && node.parent.loc.respond_to?(:begin)
|
|
405
|
+
delimiter ||= node.parent.loc.begin
|
|
406
|
+
end
|
|
374
407
|
delimiter = delimiter&.source
|
|
375
408
|
|
|
376
409
|
delimiter if %w[' "].include?(delimiter)
|
|
@@ -10,6 +10,8 @@ module RuboCop
|
|
|
10
10
|
# condition, an explicit `return` statement, etc. In other contexts, the second operand should
|
|
11
11
|
# be indented regardless of enforced style.
|
|
12
12
|
#
|
|
13
|
+
# In both styles, operators should be aligned when an assignment begins on the next line.
|
|
14
|
+
#
|
|
13
15
|
# @example EnforcedStyle: aligned (default)
|
|
14
16
|
# # bad
|
|
15
17
|
# if a +
|
|
@@ -100,10 +102,12 @@ module RuboCop
|
|
|
100
102
|
return true if begins_its_line?(assignment_rhs.source_range)
|
|
101
103
|
end
|
|
102
104
|
|
|
103
|
-
given_style == :aligned
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
return false unless given_style == :aligned
|
|
106
|
+
return true if kw_node_with_special_indentation(node) || assignment_node
|
|
107
|
+
|
|
108
|
+
node = argument_in_method_call(node, :with_or_without_parentheses)
|
|
109
|
+
|
|
110
|
+
node.respond_to?(:def_modifier?) && !node.def_modifier?
|
|
107
111
|
end
|
|
108
112
|
|
|
109
113
|
def message(node, lhs, rhs)
|
|
@@ -118,7 +122,7 @@ module RuboCop
|
|
|
118
122
|
end
|
|
119
123
|
|
|
120
124
|
def right_hand_side(send_node)
|
|
121
|
-
send_node.first_argument
|
|
125
|
+
send_node.first_argument&.source_range
|
|
122
126
|
end
|
|
123
127
|
end
|
|
124
128
|
end
|