rubocop 1.57.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/LICENSE.txt +1 -1
- data/README.md +92 -89
- data/assets/output.css.erb +159 -0
- data/assets/output.html.erb +1 -160
- data/config/default.yml +540 -86
- data/config/internal_affairs.yml +31 -0
- data/config/obsoletion.yml +8 -3
- data/exe/rubocop +1 -7
- data/lib/rubocop/cached_data.rb +21 -5
- data/lib/rubocop/cli/command/auto_generate_config.rb +30 -17
- data/lib/rubocop/cli/command/execute_runner.rb +4 -4
- data/lib/rubocop/cli/command/lsp.rb +4 -4
- data/lib/rubocop/cli/command/show_cops.rb +24 -2
- data/lib/rubocop/cli/command/show_docs_url.rb +2 -2
- data/lib/rubocop/cli/command/suggest_extensions.rb +7 -1
- data/lib/rubocop/cli/command/version.rb +2 -2
- data/lib/rubocop/cli.rb +28 -4
- data/lib/rubocop/comment_config.rb +3 -3
- data/lib/rubocop/config.rb +92 -22
- data/lib/rubocop/config_finder.rb +12 -2
- data/lib/rubocop/config_loader.rb +71 -58
- data/lib/rubocop/config_loader_resolver.rb +49 -17
- 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 +56 -9
- data/lib/rubocop/config_store.rb +5 -0
- data/lib/rubocop/config_validator.rb +39 -20
- data/lib/rubocop/cop/autocorrect_logic.rb +57 -27
- data/lib/rubocop/cop/base.rb +79 -18
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -2
- data/lib/rubocop/cop/bundler/gem_comment.rb +2 -2
- data/lib/rubocop/cop/bundler/gem_filename.rb +0 -1
- data/lib/rubocop/cop/bundler/gem_version.rb +4 -5
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +0 -1
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
- data/lib/rubocop/cop/cop.rb +30 -4
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +8 -16
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +4 -8
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +13 -16
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -0
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +6 -3
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +10 -0
- data/lib/rubocop/cop/documentation.rb +32 -5
- data/lib/rubocop/cop/exclude_limit.rb +1 -1
- data/lib/rubocop/cop/force.rb +12 -0
- data/lib/rubocop/cop/gemspec/add_runtime_dependency.rb +38 -0
- data/lib/rubocop/cop/gemspec/attribute_assignment.rb +91 -0
- data/lib/rubocop/cop/gemspec/dependency_version.rb +3 -5
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +3 -4
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +39 -17
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/gemspec/require_mfa.rb +15 -1
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +5 -3
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +3 -3
- data/lib/rubocop/cop/generator.rb +6 -0
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +0 -4
- data/lib/rubocop/cop/internal_affairs/cop_enabled.rb +85 -0
- data/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb +2 -1
- data/lib/rubocop/cop/internal_affairs/example_description.rb +13 -8
- data/lib/rubocop/cop/internal_affairs/location_exists.rb +116 -0
- data/lib/rubocop/cop/internal_affairs/location_expression.rb +2 -1
- data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +3 -4
- data/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +8 -6
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +19 -20
- data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +54 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +124 -30
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +63 -0
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +131 -0
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +233 -0
- data/lib/rubocop/cop/internal_affairs/node_type_group.rb +92 -0
- data/lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb +126 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +4 -3
- data/lib/rubocop/cop/internal_affairs/numblock_handler.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +90 -0
- data/lib/rubocop/cop/internal_affairs/operator_keyword.rb +48 -0
- data/lib/rubocop/cop/internal_affairs/plugin.rb +33 -0
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +6 -5
- data/lib/rubocop/cop/internal_affairs/redundant_expect_offense_arguments.rb +34 -0
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +6 -21
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +11 -2
- data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +5 -4
- data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +0 -2
- data/lib/rubocop/cop/internal_affairs/undefined_config.rb +23 -2
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +0 -5
- data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +1 -1
- data/lib/rubocop/cop/internal_affairs.rb +9 -0
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +6 -2
- data/lib/rubocop/cop/layout/argument_alignment.rb +3 -10
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/assignment_indentation.rb +3 -2
- data/lib/rubocop/cop/layout/begin_end_alignment.rb +0 -1
- data/lib/rubocop/cop/layout/block_alignment.rb +32 -13
- data/lib/rubocop/cop/layout/block_end_newline.rb +1 -0
- data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +45 -10
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -5
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/condition_position.rb +0 -4
- data/lib/rubocop/cop/layout/def_end_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/empty_comment.rb +3 -1
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +4 -4
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +14 -7
- data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +36 -21
- data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +101 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +37 -7
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +8 -29
- data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +5 -6
- 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/empty_lines_around_exception_handling_keywords.rb +12 -8
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +23 -1
- data/lib/rubocop/cop/layout/end_alignment.rb +16 -4
- data/lib/rubocop/cop/layout/extra_spacing.rb +5 -11
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -11
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +19 -10
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +2 -7
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +8 -0
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/hash_alignment.rb +10 -11
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +4 -3
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/indentation_width.rb +13 -13
- data/lib/rubocop/cop/layout/leading_comment_space.rb +83 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +12 -3
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +7 -1
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/line_length.rb +177 -29
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +25 -0
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +2 -1
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +4 -4
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +11 -8
- data/lib/rubocop/cop/layout/parameter_alignment.rb +3 -4
- data/lib/rubocop/cop/layout/redundant_line_break.rb +32 -46
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +16 -9
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +6 -1
- data/lib/rubocop/cop/layout/space_after_colon.rb +2 -2
- data/lib/rubocop/cop/layout/space_after_comma.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +11 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +8 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +80 -37
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +20 -10
- data/lib/rubocop/cop/layout/space_before_brackets.rb +7 -40
- data/lib/rubocop/cop/layout/space_before_comma.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_semicolon.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +18 -3
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +5 -0
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +8 -1
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +3 -5
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +6 -4
- data/lib/rubocop/cop/legacy/corrector.rb +12 -2
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -3
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +0 -2
- data/lib/rubocop/cop/lint/ambiguous_range.rb +9 -1
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +0 -2
- data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +118 -0
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +7 -9
- data/lib/rubocop/cop/lint/big_decimal_new.rb +4 -7
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +11 -13
- data/lib/rubocop/cop/lint/boolean_symbol.rb +2 -4
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +4 -14
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +3 -3
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +4 -3
- data/lib/rubocop/cop/lint/constant_reassignment.rb +148 -0
- data/lib/rubocop/cop/lint/cop_directive_syntax.rb +90 -0
- data/lib/rubocop/cop/lint/debugger.rb +30 -10
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +2 -2
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +7 -13
- data/lib/rubocop/cop/lint/duplicate_branch.rb +39 -4
- data/lib/rubocop/cop/lint/duplicate_case_condition.rb +1 -5
- data/lib/rubocop/cop/lint/duplicate_hash_key.rb +0 -4
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +110 -32
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +6 -43
- data/lib/rubocop/cop/lint/duplicate_set_element.rb +87 -0
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +0 -4
- data/lib/rubocop/cop/lint/else_layout.rb +0 -2
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +29 -58
- data/lib/rubocop/cop/lint/empty_ensure.rb +2 -12
- data/lib/rubocop/cop/lint/empty_expression.rb +0 -2
- data/lib/rubocop/cop/lint/empty_file.rb +0 -2
- data/lib/rubocop/cop/lint/empty_interpolation.rb +14 -5
- data/lib/rubocop/cop/lint/empty_when.rb +1 -3
- data/lib/rubocop/cop/lint/ensure_return.rb +2 -10
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +24 -23
- data/lib/rubocop/cop/lint/float_comparison.rb +58 -15
- data/lib/rubocop/cop/lint/float_out_of_range.rb +2 -8
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +2 -12
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +2 -1
- data/lib/rubocop/cop/lint/hash_new_with_keyword_arguments_as_default.rb +55 -0
- data/lib/rubocop/cop/lint/identity_comparison.rb +19 -15
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +23 -12
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +0 -7
- data/lib/rubocop/cop/lint/interpolation_check.rb +9 -4
- data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +50 -0
- data/lib/rubocop/cop/lint/literal_as_condition.rb +126 -11
- data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +85 -0
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +49 -12
- data/lib/rubocop/cop/lint/loop.rb +6 -12
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +17 -8
- data/lib/rubocop/cop/lint/missing_super.rb +2 -2
- data/lib/rubocop/cop/lint/mixed_case_range.rb +14 -12
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +10 -12
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +6 -25
- data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +2 -7
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +12 -3
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +6 -8
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -3
- data/lib/rubocop/cop/lint/number_conversion.rb +9 -5
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +1 -2
- data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +94 -0
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +2 -3
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +3 -2
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +6 -11
- data/lib/rubocop/cop/lint/percent_string_array.rb +0 -4
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +0 -4
- data/lib/rubocop/cop/lint/raise_exception.rb +29 -10
- data/lib/rubocop/cop/lint/rand_one.rb +0 -4
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +4 -2
- data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +0 -21
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +164 -12
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +9 -8
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +2 -6
- data/lib/rubocop/cop/lint/redundant_type_conversion.rb +261 -0
- data/lib/rubocop/cop/lint/redundant_with_index.rb +9 -2
- data/lib/rubocop/cop/lint/redundant_with_object.rb +5 -2
- data/lib/rubocop/cop/lint/refinement_import_methods.rb +1 -1
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +0 -1
- data/lib/rubocop/cop/lint/require_parentheses.rb +0 -4
- data/lib/rubocop/cop/lint/require_range_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +2 -9
- data/lib/rubocop/cop/lint/rescue_type.rb +5 -11
- data/lib/rubocop/cop/lint/return_in_void_context.rb +9 -13
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +20 -9
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +109 -41
- data/lib/rubocop/cop/lint/script_permission.rb +3 -3
- data/lib/rubocop/cop/lint/self_assignment.rb +72 -10
- data/lib/rubocop/cop/lint/shadowed_argument.rb +8 -7
- data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +19 -11
- data/lib/rubocop/cop/lint/shared_mutable_default.rb +76 -0
- data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/suppressed_exception_in_number_conversion.rb +111 -0
- data/lib/rubocop/cop/lint/symbol_conversion.rb +8 -3
- data/lib/rubocop/cop/lint/syntax.rb +10 -4
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +2 -4
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -1
- data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +88 -0
- data/lib/rubocop/cop/lint/unexpected_block_arity.rb +3 -1
- data/lib/rubocop/cop/lint/unified_integer.rb +0 -4
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +4 -3
- data/lib/rubocop/cop/lint/unreachable_code.rb +56 -9
- data/lib/rubocop/cop/lint/unreachable_loop.rb +14 -8
- data/lib/rubocop/cop/lint/unused_method_argument.rb +18 -2
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
- data/lib/rubocop/cop/lint/uri_regexp.rb +25 -7
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +36 -10
- data/lib/rubocop/cop/lint/useless_assignment.rb +21 -16
- data/lib/rubocop/cop/lint/useless_constant_scoping.rb +71 -0
- data/lib/rubocop/cop/lint/useless_default_value_argument.rb +90 -0
- data/lib/rubocop/cop/lint/useless_defined.rb +55 -0
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +4 -4
- data/lib/rubocop/cop/lint/useless_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/useless_numeric_operation.rb +79 -0
- data/lib/rubocop/cop/lint/useless_or.rb +98 -0
- data/lib/rubocop/cop/lint/useless_rescue.rb +2 -2
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +5 -5
- data/lib/rubocop/cop/lint/useless_setter_call.rb +14 -29
- data/lib/rubocop/cop/lint/useless_times.rb +2 -2
- data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +121 -0
- data/lib/rubocop/cop/lint/void.rb +92 -18
- data/lib/rubocop/cop/message_annotator.rb +7 -3
- data/lib/rubocop/cop/metrics/abc_size.rb +4 -4
- data/lib/rubocop/cop/metrics/block_length.rb +7 -5
- data/lib/rubocop/cop/metrics/block_nesting.rb +20 -8
- data/lib/rubocop/cop/metrics/class_length.rb +21 -15
- data/lib/rubocop/cop/metrics/collection_literal_length.rb +7 -0
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +5 -2
- data/lib/rubocop/cop/metrics/method_length.rb +15 -6
- data/lib/rubocop/cop/metrics/module_length.rb +7 -6
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +8 -9
- data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +7 -7
- data/lib/rubocop/cop/mixin/alignment.rb +8 -4
- data/lib/rubocop/cop/mixin/allowed_methods.rb +7 -1
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +15 -3
- data/lib/rubocop/cop/mixin/annotation_comment.rb +0 -2
- data/lib/rubocop/cop/mixin/check_assignment.rb +4 -12
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +22 -12
- data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +49 -0
- data/lib/rubocop/cop/mixin/code_length.rb +12 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +23 -14
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -0
- data/lib/rubocop/cop/mixin/configurable_max.rb +5 -1
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/dig_help.rb +27 -0
- 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/endless_method_rewriter.rb +24 -0
- 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 +23 -12
- 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_shorthand_syntax.rb +45 -35
- data/lib/rubocop/cop/mixin/hash_subset.rb +203 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +74 -74
- data/lib/rubocop/cop/mixin/line_length_help.rb +34 -12
- data/lib/rubocop/cop/mixin/method_complexity.rb +17 -7
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +7 -9
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
- data/lib/rubocop/cop/mixin/percent_array.rb +1 -1
- data/lib/rubocop/cop/mixin/percent_literal.rb +1 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +68 -30
- data/lib/rubocop/cop/mixin/range_help.rb +15 -4
- data/lib/rubocop/cop/mixin/rescue_node.rb +4 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +11 -5
- data/lib/rubocop/cop/mixin/string_help.rb +2 -2
- data/lib/rubocop/cop/mixin/string_literals_help.rb +12 -0
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +17 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +21 -5
- data/lib/rubocop/cop/naming/accessor_method_name.rb +11 -6
- data/lib/rubocop/cop/naming/block_forwarding.rb +39 -8
- data/lib/rubocop/cop/naming/constant_name.rb +7 -9
- data/lib/rubocop/cop/naming/file_name.rb +4 -6
- data/lib/rubocop/cop/naming/inclusive_language.rb +13 -5
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +13 -14
- 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_prefix.rb +204 -0
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +14 -13
- data/lib/rubocop/cop/naming/variable_name.rb +50 -6
- data/lib/rubocop/cop/naming/variable_number.rb +2 -3
- data/lib/rubocop/cop/offense.rb +4 -5
- data/lib/rubocop/cop/registry.rb +9 -6
- data/lib/rubocop/cop/security/compound_hash.rb +4 -2
- 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 +3 -2
- data/lib/rubocop/cop/security/yaml_load.rb +3 -2
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +172 -32
- data/lib/rubocop/cop/style/accessor_grouping.rb +43 -9
- data/lib/rubocop/cop/style/alias.rb +2 -1
- data/lib/rubocop/cop/style/ambiguous_endless_method_definition.rb +79 -0
- data/lib/rubocop/cop/style/and_or.rb +1 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +228 -36
- data/lib/rubocop/cop/style/array_first_last.rb +80 -0
- data/lib/rubocop/cop/style/array_intersect.rb +115 -39
- data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -0
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +21 -14
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +2 -2
- data/lib/rubocop/cop/style/bitwise_predicate.rb +107 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +52 -21
- data/lib/rubocop/cop/style/case_like_if.rb +14 -17
- data/lib/rubocop/cop/style/class_and_module_children.rb +52 -11
- data/lib/rubocop/cop/style/class_check.rb +1 -0
- data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -1
- data/lib/rubocop/cop/style/class_vars.rb +3 -3
- data/lib/rubocop/cop/style/collection_compact.rb +25 -15
- data/lib/rubocop/cop/style/collection_methods.rb +2 -1
- data/lib/rubocop/cop/style/collection_querying.rb +167 -0
- data/lib/rubocop/cop/style/combinable_defined.rb +115 -0
- data/lib/rubocop/cop/style/combinable_loops.rb +22 -8
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +30 -4
- data/lib/rubocop/cop/style/comparable_between.rb +78 -0
- data/lib/rubocop/cop/style/concat_array_literals.rb +2 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +57 -40
- data/lib/rubocop/cop/style/constant_visibility.rb +16 -20
- data/lib/rubocop/cop/style/copyright.rb +31 -21
- data/lib/rubocop/cop/style/data_inheritance.rb +8 -1
- data/lib/rubocop/cop/style/date_time.rb +5 -4
- data/lib/rubocop/cop/style/def_with_parentheses.rb +18 -7
- data/lib/rubocop/cop/style/dig_chain.rb +89 -0
- data/lib/rubocop/cop/style/documentation.rb +25 -25
- data/lib/rubocop/cop/style/documentation_method.rb +20 -0
- data/lib/rubocop/cop/style/double_negation.rb +5 -5
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +11 -15
- data/lib/rubocop/cop/style/each_with_object.rb +3 -4
- data/lib/rubocop/cop/style/empty_else.rb +10 -7
- data/lib/rubocop/cop/style/empty_heredoc.rb +1 -14
- data/lib/rubocop/cop/style/empty_literal.rb +36 -23
- data/lib/rubocop/cop/style/empty_method.rb +1 -1
- data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +100 -0
- data/lib/rubocop/cop/style/endless_method.rb +163 -18
- data/lib/rubocop/cop/style/eval_with_location.rb +23 -31
- data/lib/rubocop/cop/style/exact_regexp_match.rb +6 -5
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -7
- data/lib/rubocop/cop/style/explicit_block_argument.rb +19 -6
- data/lib/rubocop/cop/style/exponential_notation.rb +6 -5
- data/lib/rubocop/cop/style/fetch_env_var.rb +34 -7
- data/lib/rubocop/cop/style/file_null.rb +89 -0
- data/lib/rubocop/cop/style/file_read.rb +2 -5
- data/lib/rubocop/cop/style/file_touch.rb +75 -0
- data/lib/rubocop/cop/style/file_write.rb +2 -5
- data/lib/rubocop/cop/style/float_division.rb +23 -5
- data/lib/rubocop/cop/style/for.rb +3 -1
- data/lib/rubocop/cop/style/format_string.rb +9 -9
- 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 +10 -1
- data/lib/rubocop/cop/style/global_vars.rb +1 -3
- data/lib/rubocop/cop/style/guard_clause.rb +20 -4
- data/lib/rubocop/cop/style/hash_conversion.rb +16 -9
- data/lib/rubocop/cop/style/hash_each_methods.rb +110 -12
- data/lib/rubocop/cop/style/hash_except.rb +38 -146
- data/lib/rubocop/cop/style/hash_fetch_chain.rb +104 -0
- data/lib/rubocop/cop/style/hash_slice.rb +80 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +35 -7
- 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 +37 -7
- data/lib/rubocop/cop/style/if_inside_else.rb +11 -15
- data/lib/rubocop/cop/style/if_unless_modifier.rb +36 -9
- 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 +8 -8
- data/lib/rubocop/cop/style/if_with_semicolon.rb +60 -6
- data/lib/rubocop/cop/style/in_pattern_then.rb +6 -2
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +22 -18
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +48 -6
- data/lib/rubocop/cop/style/ip_addresses.rb +2 -2
- data/lib/rubocop/cop/style/it_assignment.rb +93 -0
- data/lib/rubocop/cop/style/it_block_parameter.rb +121 -0
- data/lib/rubocop/cop/style/keyword_arguments_merging.rb +67 -0
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +14 -8
- data/lib/rubocop/cop/style/lambda.rb +2 -1
- data/lib/rubocop/cop/style/lambda_call.rb +10 -4
- data/lib/rubocop/cop/style/line_end_concatenation.rb +10 -4
- data/lib/rubocop/cop/style/magic_comment_format.rb +1 -1
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +82 -50
- data/lib/rubocop/cop/style/map_into_array.rb +236 -0
- data/lib/rubocop/cop/style/map_to_hash.rb +29 -10
- data/lib/rubocop/cop/style/map_to_set.rb +4 -5
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +52 -25
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +21 -5
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +30 -13
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +3 -4
- data/lib/rubocop/cop/style/method_def_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/min_max_comparison.rb +13 -5
- data/lib/rubocop/cop/style/missing_else.rb +2 -4
- data/lib/rubocop/cop/style/missing_respond_to_missing.rb +35 -5
- data/lib/rubocop/cop/style/multiline_block_chain.rb +3 -2
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -0
- data/lib/rubocop/cop/style/multiline_memoization.rb +2 -2
- data/lib/rubocop/cop/style/multiline_method_signature.rb +10 -9
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +5 -3
- data/lib/rubocop/cop/style/multiline_when_then.rb +0 -4
- data/lib/rubocop/cop/style/multiple_comparison.rb +53 -60
- data/lib/rubocop/cop/style/mutable_constant.rb +7 -8
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +7 -5
- data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -2
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +5 -4
- data/lib/rubocop/cop/style/next.rb +45 -1
- data/lib/rubocop/cop/style/nil_comparison.rb +11 -7
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +12 -4
- data/lib/rubocop/cop/style/object_then.rb +16 -14
- data/lib/rubocop/cop/style/one_line_conditional.rb +48 -15
- data/lib/rubocop/cop/style/open_struct_use.rb +5 -5
- data/lib/rubocop/cop/style/operator_method_call.rb +27 -9
- data/lib/rubocop/cop/style/or_assignment.rb +3 -6
- data/lib/rubocop/cop/style/parallel_assignment.rb +47 -45
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -0
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +2 -2
- data/lib/rubocop/cop/style/quoted_symbols.rb +2 -4
- data/lib/rubocop/cop/style/raise_args.rb +19 -14
- data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
- data/lib/rubocop/cop/style/redundant_argument.rb +29 -3
- data/lib/rubocop/cop/style/redundant_array_flatten.rb +50 -0
- data/lib/rubocop/cop/style/redundant_assignment.rb +11 -3
- data/lib/rubocop/cop/style/redundant_begin.rb +41 -2
- data/lib/rubocop/cop/style/redundant_condition.rb +97 -25
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +19 -7
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +17 -14
- data/lib/rubocop/cop/style/redundant_each.rb +7 -4
- data/lib/rubocop/cop/style/redundant_exception.rb +2 -2
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +4 -12
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -1
- data/lib/rubocop/cop/style/redundant_filter_chain.rb +5 -4
- data/lib/rubocop/cop/style/redundant_format.rb +283 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +4 -4
- data/lib/rubocop/cop/style/redundant_initialize.rb +12 -3
- data/lib/rubocop/cop/style/redundant_interpolation.rb +12 -3
- data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +46 -0
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +72 -19
- data/lib/rubocop/cop/style/redundant_parentheses.rb +149 -49
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +12 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +16 -24
- data/lib/rubocop/cop/style/redundant_return.rb +9 -3
- data/lib/rubocop/cop/style/redundant_self.rb +32 -20
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +20 -32
- data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +4 -4
- data/lib/rubocop/cop/style/redundant_sort.rb +10 -9
- data/lib/rubocop/cop/style/redundant_sort_by.rb +19 -3
- data/lib/rubocop/cop/style/redundant_string_escape.rb +3 -3
- data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
- data/lib/rubocop/cop/style/require_order.rb +2 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +18 -4
- data/lib/rubocop/cop/style/return_nil.rb +2 -2
- data/lib/rubocop/cop/style/return_nil_in_predicate_method_definition.rb +54 -12
- data/lib/rubocop/cop/style/safe_navigation.rb +163 -62
- data/lib/rubocop/cop/style/safe_navigation_chain_length.rb +52 -0
- data/lib/rubocop/cop/style/sample.rb +3 -4
- data/lib/rubocop/cop/style/select_by_regexp.rb +20 -13
- data/lib/rubocop/cop/style/self_assignment.rb +12 -18
- data/lib/rubocop/cop/style/semicolon.rb +33 -9
- data/lib/rubocop/cop/style/send.rb +4 -4
- data/lib/rubocop/cop/style/send_with_literal_method_name.rb +105 -0
- data/lib/rubocop/cop/style/signal_exception.rb +2 -3
- data/lib/rubocop/cop/style/single_argument_dig.rb +16 -8
- data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +18 -5
- data/lib/rubocop/cop/style/single_line_methods.rb +13 -11
- data/lib/rubocop/cop/style/slicing_with_range.rb +105 -10
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +79 -87
- data/lib/rubocop/cop/style/special_global_vars.rb +2 -3
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/string_chars.rb +1 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +21 -17
- data/lib/rubocop/cop/style/string_literals.rb +1 -1
- data/lib/rubocop/cop/style/string_methods.rb +1 -1
- data/lib/rubocop/cop/style/strip.rb +7 -4
- data/lib/rubocop/cop/style/struct_inheritance.rb +9 -2
- data/lib/rubocop/cop/style/super_arguments.rb +221 -0
- data/lib/rubocop/cop/style/super_with_args_parentheses.rb +35 -0
- data/lib/rubocop/cop/style/swap_values.rb +4 -15
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +78 -6
- data/lib/rubocop/cop/style/ternary_parentheses.rb +26 -5
- data/lib/rubocop/cop/style/top_level_method_definition.rb +2 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +56 -2
- 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/trailing_underscore_variable.rb +4 -4
- data/lib/rubocop/cop/style/trivial_accessors.rb +2 -2
- data/lib/rubocop/cop/style/unless_else.rb +10 -9
- data/lib/rubocop/cop/style/unpack_first.rb +11 -14
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -2
- data/lib/rubocop/cop/style/while_until_do.rb +0 -2
- data/lib/rubocop/cop/style/while_until_modifier.rb +0 -2
- data/lib/rubocop/cop/style/yoda_condition.rb +8 -4
- data/lib/rubocop/cop/style/yoda_expression.rb +2 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +32 -24
- data/lib/rubocop/cop/team.rb +28 -4
- data/lib/rubocop/cop/util.rb +19 -6
- data/lib/rubocop/cop/utils/format_string.rb +20 -5
- data/lib/rubocop/cop/variable_force/assignment.rb +24 -5
- data/lib/rubocop/cop/variable_force/branch.rb +1 -1
- data/lib/rubocop/cop/variable_force/scope.rb +1 -1
- data/lib/rubocop/cop/variable_force/variable.rb +14 -3
- data/lib/rubocop/cop/variable_force/variable_table.rb +5 -5
- data/lib/rubocop/cop/variable_force.rb +43 -20
- data/lib/rubocop/cops_documentation_generator.rb +135 -58
- data/lib/rubocop/core_ext/string.rb +2 -6
- data/lib/rubocop/directive_comment.rb +54 -18
- data/lib/rubocop/ext/regexp_node.rb +17 -35
- data/lib/rubocop/ext/regexp_parser.rb +4 -21
- data/lib/rubocop/file_finder.rb +9 -4
- data/lib/rubocop/formatter/clang_style_formatter.rb +3 -7
- data/lib/rubocop/formatter/disabled_config_formatter.rb +43 -14
- data/lib/rubocop/formatter/formatter_set.rb +8 -2
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/html_formatter.rb +38 -15
- data/lib/rubocop/formatter/json_formatter.rb +0 -1
- data/lib/rubocop/formatter/junit_formatter.rb +70 -23
- data/lib/rubocop/formatter/markdown_formatter.rb +1 -0
- data/lib/rubocop/formatter/offense_count_formatter.rb +13 -3
- data/lib/rubocop/formatter/pacman_formatter.rb +2 -1
- data/lib/rubocop/formatter/tap_formatter.rb +3 -7
- data/lib/rubocop/formatter.rb +1 -1
- data/lib/rubocop/lockfile.rb +58 -7
- data/lib/rubocop/lsp/diagnostic.rb +190 -0
- data/lib/rubocop/lsp/logger.rb +3 -3
- data/lib/rubocop/lsp/routes.rb +77 -40
- data/lib/rubocop/lsp/runtime.rb +20 -50
- data/lib/rubocop/lsp/server.rb +6 -4
- data/lib/rubocop/lsp/severity.rb +1 -1
- data/lib/rubocop/lsp/stdin_runner.rb +69 -0
- data/lib/rubocop/lsp.rb +36 -0
- data/lib/rubocop/magic_comment.rb +12 -4
- data/lib/rubocop/options.rb +43 -22
- data/lib/rubocop/path_util.rb +21 -10
- data/lib/rubocop/pending_cops_reporter.rb +56 -0
- data/lib/rubocop/plugin/configuration_integrator.rb +143 -0
- data/lib/rubocop/plugin/load_error.rb +26 -0
- data/lib/rubocop/plugin/loader.rb +100 -0
- data/lib/rubocop/plugin/not_supported_error.rb +29 -0
- data/lib/rubocop/plugin.rb +46 -0
- data/lib/rubocop/rake_task.rb +5 -2
- data/lib/rubocop/remote_config.rb +5 -1
- data/lib/rubocop/result_cache.rb +29 -34
- data/lib/rubocop/rspec/cop_helper.rb +20 -2
- data/lib/rubocop/rspec/expect_offense.rb +31 -12
- data/lib/rubocop/rspec/shared_contexts.rb +112 -18
- data/lib/rubocop/rspec/support.rb +7 -2
- data/lib/rubocop/runner.rb +40 -13
- data/lib/rubocop/server/cache.rb +63 -11
- data/lib/rubocop/server/cli.rb +2 -2
- data/lib/rubocop/server/client_command/base.rb +10 -0
- data/lib/rubocop/server/client_command/exec.rb +3 -3
- data/lib/rubocop/server/client_command/start.rb +11 -1
- data/lib/rubocop/server/core.rb +5 -0
- data/lib/rubocop/server/server_command/exec.rb +0 -1
- data/lib/rubocop/target_finder.rb +93 -82
- data/lib/rubocop/target_ruby.rb +111 -81
- data/lib/rubocop/version.rb +67 -9
- data/lib/rubocop/yaml_duplication_checker.rb +20 -26
- data/lib/rubocop.rb +61 -3
- data/lib/ruby_lsp/rubocop/addon.rb +90 -0
- data/lib/ruby_lsp/rubocop/runtime_adapter.rb +99 -0
- metadata +103 -51
- data/lib/rubocop/cop/naming/predicate_name.rb +0 -134
- data/lib/rubocop/cop/utils/regexp_ranges.rb +0 -113
- data/lib/rubocop/rspec/host_environment_simulation_helper.rb +0 -28
- /data/lib/rubocop/formatter/{git_hub_actions_formatter.rb → github_actions_formatter.rb} +0 -0
|
@@ -29,6 +29,8 @@ module RuboCop
|
|
|
29
29
|
# * never - forces use of explicit hash literal value
|
|
30
30
|
# * either - accepts both shorthand and explicit use of hash literal value
|
|
31
31
|
# * consistent - forces use of the 3.1 syntax only if all values can be omitted in the hash
|
|
32
|
+
# * either_consistent - accepts both shorthand and explicit use of hash literal value,
|
|
33
|
+
# but they must be consistent
|
|
32
34
|
#
|
|
33
35
|
# @example EnforcedStyle: ruby19 (default)
|
|
34
36
|
# # bad
|
|
@@ -66,7 +68,7 @@ module RuboCop
|
|
|
66
68
|
# {a: 1, b: 2}
|
|
67
69
|
# {:c => 3, 'd' => 4}
|
|
68
70
|
#
|
|
69
|
-
# @example EnforcedShorthandSyntax: always
|
|
71
|
+
# @example EnforcedShorthandSyntax: always
|
|
70
72
|
#
|
|
71
73
|
# # bad
|
|
72
74
|
# {foo: foo, bar: bar}
|
|
@@ -74,6 +76,9 @@ module RuboCop
|
|
|
74
76
|
# # good
|
|
75
77
|
# {foo:, bar:}
|
|
76
78
|
#
|
|
79
|
+
# # good - allowed to mix syntaxes
|
|
80
|
+
# {foo:, bar: baz}
|
|
81
|
+
#
|
|
77
82
|
# @example EnforcedShorthandSyntax: never
|
|
78
83
|
#
|
|
79
84
|
# # bad
|
|
@@ -82,7 +87,7 @@ module RuboCop
|
|
|
82
87
|
# # good
|
|
83
88
|
# {foo: foo, bar: bar}
|
|
84
89
|
#
|
|
85
|
-
# @example EnforcedShorthandSyntax: either
|
|
90
|
+
# @example EnforcedShorthandSyntax: either (default)
|
|
86
91
|
#
|
|
87
92
|
# # good
|
|
88
93
|
# {foo: foo, bar: bar}
|
|
@@ -110,6 +115,22 @@ module RuboCop
|
|
|
110
115
|
# # good - can't omit `baz`
|
|
111
116
|
# {foo: foo, bar: baz}
|
|
112
117
|
#
|
|
118
|
+
# @example EnforcedShorthandSyntax: either_consistent
|
|
119
|
+
#
|
|
120
|
+
# # good - `foo` and `bar` values can be omitted, but they are consistent, so it's accepted
|
|
121
|
+
# {foo: foo, bar: bar}
|
|
122
|
+
#
|
|
123
|
+
# # bad - `bar` value can be omitted
|
|
124
|
+
# {foo:, bar: bar}
|
|
125
|
+
#
|
|
126
|
+
# # bad - mixed syntaxes
|
|
127
|
+
# {foo:, bar: baz}
|
|
128
|
+
#
|
|
129
|
+
# # good
|
|
130
|
+
# {foo:, bar:}
|
|
131
|
+
#
|
|
132
|
+
# # good - can't omit `baz`
|
|
133
|
+
# {foo: foo, bar: baz}
|
|
113
134
|
class HashSyntax < Base
|
|
114
135
|
include ConfigurableEnforcedStyle
|
|
115
136
|
include HashShorthandSyntax
|
|
@@ -119,6 +140,7 @@ module RuboCop
|
|
|
119
140
|
MSG_19 = 'Use the new Ruby 1.9 hash syntax.'
|
|
120
141
|
MSG_NO_MIXED_KEYS = "Don't mix styles in the same hash."
|
|
121
142
|
MSG_HASH_ROCKETS = 'Use hash rockets syntax.'
|
|
143
|
+
NO_MIXED_KEYS_STYLES = %i[ruby19_no_mixed_keys no_mixed_keys].freeze
|
|
122
144
|
|
|
123
145
|
def on_hash(node)
|
|
124
146
|
pairs = node.pairs
|
|
@@ -178,7 +200,7 @@ module RuboCop
|
|
|
178
200
|
def autocorrect(corrector, node)
|
|
179
201
|
if style == :hash_rockets || force_hash_rockets?(node.parent.pairs)
|
|
180
202
|
autocorrect_hash_rockets(corrector, node)
|
|
181
|
-
elsif style
|
|
203
|
+
elsif NO_MIXED_KEYS_STYLES.include?(style)
|
|
182
204
|
autocorrect_no_mixed_keys(corrector, node)
|
|
183
205
|
else
|
|
184
206
|
autocorrect_ruby19(corrector, node)
|
|
@@ -190,11 +212,12 @@ module RuboCop
|
|
|
190
212
|
end
|
|
191
213
|
|
|
192
214
|
def word_symbol_pair?(pair)
|
|
193
|
-
return false unless pair.key.
|
|
215
|
+
return false unless pair.key.any_sym_type?
|
|
194
216
|
|
|
195
217
|
acceptable_19_syntax_symbol?(pair.key.source)
|
|
196
218
|
end
|
|
197
219
|
|
|
220
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
|
198
221
|
def acceptable_19_syntax_symbol?(sym_name)
|
|
199
222
|
sym_name.delete_prefix!(':')
|
|
200
223
|
|
|
@@ -209,9 +232,12 @@ module RuboCop
|
|
|
209
232
|
# Most hash keys can be matched against a simple regex.
|
|
210
233
|
return true if /\A[_a-z]\w*[?!]?\z/i.match?(sym_name)
|
|
211
234
|
|
|
212
|
-
|
|
213
|
-
|
|
235
|
+
return false if target_ruby_version <= 2.1
|
|
236
|
+
|
|
237
|
+
(sym_name.start_with?("'") && sym_name.end_with?("'")) ||
|
|
238
|
+
(sym_name.start_with?('"') && sym_name.end_with?('"'))
|
|
214
239
|
end
|
|
240
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
|
215
241
|
|
|
216
242
|
def check(pairs, delim, msg)
|
|
217
243
|
pairs.each do |pair|
|
|
@@ -250,7 +276,9 @@ module RuboCop
|
|
|
250
276
|
end
|
|
251
277
|
|
|
252
278
|
def argument_without_space?(node)
|
|
253
|
-
node.argument?
|
|
279
|
+
return false if !node.argument? || !node.parent.loc.selector
|
|
280
|
+
|
|
281
|
+
node.source_range.begin_pos == node.parent.loc.selector.end_pos
|
|
254
282
|
end
|
|
255
283
|
|
|
256
284
|
def autocorrect_hash_rockets(corrector, pair_node)
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
module Cop
|
|
5
5
|
module Style
|
|
6
|
-
# Looks for uses of
|
|
7
|
-
#
|
|
6
|
+
# Looks for uses of `+_.each_with_object({}) {...}+`,
|
|
7
|
+
# `+_.map {...}.to_h+`, and `+Hash[_.map {...}]+` that are actually just
|
|
8
8
|
# transforming the keys of a hash, and tries to use a simpler & faster
|
|
9
9
|
# call to `transform_keys` instead.
|
|
10
10
|
# It should only be enabled on Ruby version 2.5 or newer.
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
module Cop
|
|
5
5
|
module Style
|
|
6
|
-
# Looks for uses of
|
|
7
|
-
#
|
|
6
|
+
# Looks for uses of `+_.each_with_object({}) {...}+`,
|
|
7
|
+
# `+_.map {...}.to_h+`, and `+Hash[_.map {...}]+` that are actually just
|
|
8
8
|
# transforming the values of a hash, and tries to use a simpler & faster
|
|
9
9
|
# call to `transform_values` instead.
|
|
10
10
|
#
|
|
@@ -153,7 +153,18 @@ module RuboCop
|
|
|
153
153
|
return unless duplicated_expressions?(node, heads)
|
|
154
154
|
|
|
155
155
|
condition_variable = assignable_condition_value(node)
|
|
156
|
-
|
|
156
|
+
|
|
157
|
+
head = heads.first
|
|
158
|
+
if head.respond_to?(:assignment?) && head.assignment?
|
|
159
|
+
# The `send` node is used instead of the `indexasgn` node, so `name` cannot be used.
|
|
160
|
+
# https://github.com/rubocop/rubocop-ast/blob/v1.29.0/lib/rubocop/ast/node/indexasgn_node.rb
|
|
161
|
+
#
|
|
162
|
+
# FIXME: It would be better to update `RuboCop::AST::OpAsgnNode` or its subclasses to
|
|
163
|
+
# handle `self.foo ||= value` as a solution, instead of using `head.node_parts[0].to_s`.
|
|
164
|
+
assigned_value = head.send_type? ? head.receiver.source : head.node_parts[0].to_s
|
|
165
|
+
|
|
166
|
+
return if condition_variable == assigned_value
|
|
167
|
+
end
|
|
157
168
|
|
|
158
169
|
check_expressions(node, heads, :before_condition)
|
|
159
170
|
end
|
|
@@ -178,7 +189,7 @@ module RuboCop
|
|
|
178
189
|
end
|
|
179
190
|
end
|
|
180
191
|
|
|
181
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
192
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
182
193
|
def check_expressions(node, expressions, insert_position)
|
|
183
194
|
return if expressions.any?(&:nil?)
|
|
184
195
|
|
|
@@ -186,22 +197,41 @@ module RuboCop
|
|
|
186
197
|
|
|
187
198
|
expressions.each do |expression|
|
|
188
199
|
add_offense(expression) do |corrector|
|
|
189
|
-
next if node.if_type? && node.ternary?
|
|
200
|
+
next if node.if_type? && (node.ternary? || node.then?)
|
|
190
201
|
|
|
191
202
|
range = range_by_whole_lines(expression.source_range, include_final_newline: true)
|
|
192
203
|
corrector.remove(range)
|
|
193
204
|
next if inserted_expression
|
|
194
205
|
|
|
195
|
-
if
|
|
196
|
-
corrector
|
|
206
|
+
if node.parent&.assignment?
|
|
207
|
+
correct_assignment(corrector, node, expression, insert_position)
|
|
197
208
|
else
|
|
198
|
-
corrector
|
|
209
|
+
correct_no_assignment(corrector, node, expression, insert_position)
|
|
199
210
|
end
|
|
211
|
+
|
|
200
212
|
inserted_expression = true
|
|
201
213
|
end
|
|
202
214
|
end
|
|
203
215
|
end
|
|
204
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
216
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
217
|
+
|
|
218
|
+
def correct_assignment(corrector, node, expression, insert_position)
|
|
219
|
+
if insert_position == :after_condition
|
|
220
|
+
assignment = node.parent.source_range.with(end_pos: node.source_range.begin_pos)
|
|
221
|
+
corrector.remove(assignment)
|
|
222
|
+
corrector.insert_after(node, "\n#{assignment.source}#{expression.source}")
|
|
223
|
+
else
|
|
224
|
+
corrector.insert_before(node.parent, "#{expression.source}\n")
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def correct_no_assignment(corrector, node, expression, insert_position)
|
|
229
|
+
if insert_position == :after_condition
|
|
230
|
+
corrector.insert_after(node, "\n#{expression.source}")
|
|
231
|
+
else
|
|
232
|
+
corrector.insert_before(node, "#{expression.source}\n")
|
|
233
|
+
end
|
|
234
|
+
end
|
|
205
235
|
|
|
206
236
|
def last_child_of_parent?(node)
|
|
207
237
|
return true unless (parent = node.parent)
|
|
@@ -59,7 +59,6 @@ module RuboCop
|
|
|
59
59
|
# end
|
|
60
60
|
#
|
|
61
61
|
class IfInsideElse < Base
|
|
62
|
-
include IgnoredNode
|
|
63
62
|
include RangeHelp
|
|
64
63
|
extend AutoCorrector
|
|
65
64
|
|
|
@@ -71,7 +70,7 @@ module RuboCop
|
|
|
71
70
|
|
|
72
71
|
else_branch = node.else_branch
|
|
73
72
|
|
|
74
|
-
return unless else_branch&.if_type? && else_branch
|
|
73
|
+
return unless else_branch&.if_type? && else_branch.if?
|
|
75
74
|
return if allow_if_modifier_in_else_branch?(else_branch)
|
|
76
75
|
|
|
77
76
|
add_offense(else_branch.loc.keyword) do |corrector|
|
|
@@ -98,34 +97,31 @@ module RuboCop
|
|
|
98
97
|
else
|
|
99
98
|
correct_to_elsif_from_if_inside_else_form(corrector, node, node.condition)
|
|
100
99
|
end
|
|
101
|
-
|
|
102
|
-
corrector.remove(range_by_whole_lines(find_end_range(node), include_final_newline: true))
|
|
103
|
-
return unless (if_branch = node.if_branch)
|
|
104
|
-
|
|
105
|
-
range = range_by_whole_lines(if_branch.source_range, include_final_newline: true)
|
|
106
|
-
corrector.remove(range)
|
|
107
100
|
end
|
|
108
101
|
|
|
109
102
|
def correct_to_elsif_from_modifier_form(corrector, node)
|
|
110
|
-
corrector.replace(node.parent.loc.else,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
103
|
+
corrector.replace(node.parent.loc.else, "elsif #{node.condition.source}")
|
|
104
|
+
|
|
105
|
+
condition_range = range_between(
|
|
106
|
+
node.if_branch.source_range.end_pos, node.condition.source_range.end_pos
|
|
107
|
+
)
|
|
108
|
+
corrector.remove(condition_range)
|
|
115
109
|
end
|
|
116
110
|
|
|
117
|
-
def correct_to_elsif_from_if_inside_else_form(corrector, node, condition)
|
|
111
|
+
def correct_to_elsif_from_if_inside_else_form(corrector, node, condition) # rubocop:disable Metrics/AbcSize
|
|
118
112
|
corrector.replace(node.parent.loc.else, "elsif #{condition.source}")
|
|
119
113
|
|
|
120
114
|
if_condition_range = if_condition_range(node, condition)
|
|
121
115
|
|
|
122
116
|
if (if_branch = node.if_branch)
|
|
123
|
-
corrector.replace(if_condition_range, if_branch.source)
|
|
117
|
+
corrector.replace(if_condition_range, range_with_comments(if_branch).source)
|
|
118
|
+
corrector.remove(range_with_comments_and_lines(if_branch))
|
|
124
119
|
else
|
|
125
120
|
corrector.remove(range_by_whole_lines(if_condition_range, include_final_newline: true))
|
|
126
121
|
end
|
|
127
122
|
|
|
128
123
|
corrector.remove(condition)
|
|
124
|
+
corrector.remove(range_by_whole_lines(find_end_range(node), include_final_newline: true))
|
|
129
125
|
end
|
|
130
126
|
|
|
131
127
|
def then?(node)
|
|
@@ -23,6 +23,17 @@ module RuboCop
|
|
|
23
23
|
# end
|
|
24
24
|
# ----
|
|
25
25
|
#
|
|
26
|
+
# The code `def method_name = body if condition` is considered a bad case by
|
|
27
|
+
# `Style/AmbiguousEndlessMethodDefinition` cop. So, to respect the user's intention to use
|
|
28
|
+
# an endless method definition in the `if` body, the following code is allowed:
|
|
29
|
+
#
|
|
30
|
+
# [source,ruby]
|
|
31
|
+
# ----
|
|
32
|
+
# if condition
|
|
33
|
+
# def method_name = body
|
|
34
|
+
# end
|
|
35
|
+
# ----
|
|
36
|
+
#
|
|
26
37
|
# NOTE: It is allowed when `defined?` argument has an undefined value,
|
|
27
38
|
# because using the modifier form causes the following incompatibility:
|
|
28
39
|
#
|
|
@@ -77,10 +88,14 @@ module RuboCop
|
|
|
77
88
|
[Style::SoleNestedConditional]
|
|
78
89
|
end
|
|
79
90
|
|
|
91
|
+
# rubocop:disable Metrics/AbcSize
|
|
80
92
|
def on_if(node)
|
|
93
|
+
return if endless_method?(node.body)
|
|
94
|
+
|
|
81
95
|
condition = node.condition
|
|
82
96
|
return if defined_nodes(condition).any? { |n| defined_argument_is_undefined?(node, n) } ||
|
|
83
97
|
pattern_matching_nodes(condition).any?
|
|
98
|
+
|
|
84
99
|
return unless (msg = message(node))
|
|
85
100
|
|
|
86
101
|
add_offense(node.loc.keyword, message: format(msg, keyword: node.keyword)) do |corrector|
|
|
@@ -90,9 +105,14 @@ module RuboCop
|
|
|
90
105
|
ignore_node(node)
|
|
91
106
|
end
|
|
92
107
|
end
|
|
108
|
+
# rubocop:enable Metrics/AbcSize
|
|
93
109
|
|
|
94
110
|
private
|
|
95
111
|
|
|
112
|
+
def endless_method?(body)
|
|
113
|
+
body&.any_def_type? && body.endless?
|
|
114
|
+
end
|
|
115
|
+
|
|
96
116
|
def defined_nodes(condition)
|
|
97
117
|
if condition.defined_type?
|
|
98
118
|
[condition]
|
|
@@ -103,7 +123,7 @@ module RuboCop
|
|
|
103
123
|
|
|
104
124
|
def defined_argument_is_undefined?(if_node, defined_node)
|
|
105
125
|
defined_argument = defined_node.first_argument
|
|
106
|
-
return false unless defined_argument.
|
|
126
|
+
return false unless defined_argument.type?(:lvar, :send)
|
|
107
127
|
|
|
108
128
|
if_node.left_siblings.none? do |sibling|
|
|
109
129
|
sibling.respond_to?(:lvasgn_type?) && sibling.lvasgn_type? &&
|
|
@@ -112,12 +132,10 @@ module RuboCop
|
|
|
112
132
|
end
|
|
113
133
|
|
|
114
134
|
def pattern_matching_nodes(condition)
|
|
115
|
-
if condition.
|
|
135
|
+
if condition.any_match_pattern_type?
|
|
116
136
|
[condition]
|
|
117
137
|
else
|
|
118
|
-
condition.each_descendant.select
|
|
119
|
-
node.match_pattern_type? || node.match_pattern_p_type?
|
|
120
|
-
end
|
|
138
|
+
condition.each_descendant.select(&:any_match_pattern_type?)
|
|
121
139
|
end
|
|
122
140
|
end
|
|
123
141
|
|
|
@@ -164,8 +182,8 @@ module RuboCop
|
|
|
164
182
|
|
|
165
183
|
def too_long_due_to_comment_after_modifier?(node, comment)
|
|
166
184
|
source_length = processed_source.lines[node.first_line - 1].length
|
|
167
|
-
|
|
168
|
-
|
|
185
|
+
|
|
186
|
+
max_line_length.between?(source_length - comment.source_range.length, source_length)
|
|
169
187
|
end
|
|
170
188
|
|
|
171
189
|
def allowed_patterns
|
|
@@ -205,8 +223,17 @@ module RuboCop
|
|
|
205
223
|
|
|
206
224
|
def too_long_line_based_on_allow_uri?(line)
|
|
207
225
|
if allow_uri?
|
|
208
|
-
uri_range =
|
|
209
|
-
return false if uri_range &&
|
|
226
|
+
uri_range = find_excessive_range(line, :uri)
|
|
227
|
+
return false if uri_range && allowed_position?(line, uri_range)
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
true
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def too_long_line_based_on_allow_qualified_name?(line)
|
|
234
|
+
if allow_qualified_name?
|
|
235
|
+
namespace_range = find_excessive_range(line, :namespace)
|
|
236
|
+
return false if namespace_range && allowed_position?(line, namespace_range)
|
|
210
237
|
end
|
|
211
238
|
|
|
212
239
|
true
|
|
@@ -28,19 +28,16 @@ module RuboCop
|
|
|
28
28
|
|
|
29
29
|
MSG = 'Avoid modifier `%<keyword>s` after another conditional.'
|
|
30
30
|
|
|
31
|
+
# rubocop:disable Metrics/AbcSize
|
|
31
32
|
def on_if(node)
|
|
32
33
|
return unless node.modifier_form? && node.body.if_type?
|
|
33
34
|
|
|
34
35
|
add_offense(node.loc.keyword, message: format(MSG, keyword: node.keyword)) do |corrector|
|
|
35
|
-
keyword
|
|
36
|
-
|
|
37
|
-
corrector.replace(node, <<~RUBY.chop)
|
|
38
|
-
#{keyword} #{node.condition.source}
|
|
39
|
-
#{node.if_branch.source}
|
|
40
|
-
end
|
|
41
|
-
RUBY
|
|
36
|
+
corrector.wrap(node.if_branch, "#{node.keyword} #{node.condition.source}\n", "\nend")
|
|
37
|
+
corrector.remove(node.if_branch.source_range.end.join(node.condition.source_range.end))
|
|
42
38
|
end
|
|
43
39
|
end
|
|
40
|
+
# rubocop:enable Metrics/AbcSize
|
|
44
41
|
end
|
|
45
42
|
end
|
|
46
43
|
end
|
|
@@ -10,7 +10,7 @@ module RuboCop
|
|
|
10
10
|
# `nonzero?` method is allowed by default.
|
|
11
11
|
# These are customizable with `AllowedMethods` option.
|
|
12
12
|
#
|
|
13
|
-
# This cop targets only
|
|
13
|
+
# This cop targets only ``if``s with a single `elsif` or `else` branch. The following
|
|
14
14
|
# code will be allowed, because it has two `elsif` branches:
|
|
15
15
|
#
|
|
16
16
|
# [source,ruby]
|
|
@@ -44,7 +44,6 @@ module RuboCop
|
|
|
44
44
|
# # good
|
|
45
45
|
# foo == bar
|
|
46
46
|
#
|
|
47
|
-
# @example
|
|
48
47
|
# # bad
|
|
49
48
|
# if foo.do_something?
|
|
50
49
|
# true
|
|
@@ -68,7 +67,7 @@ module RuboCop
|
|
|
68
67
|
|
|
69
68
|
# @!method if_with_boolean_literal_branches?(node)
|
|
70
69
|
def_node_matcher :if_with_boolean_literal_branches?, <<~PATTERN
|
|
71
|
-
(if #return_boolean_value?
|
|
70
|
+
(if #return_boolean_value? <true false>)
|
|
72
71
|
PATTERN
|
|
73
72
|
# @!method double_negative?(node)
|
|
74
73
|
def_node_matcher :double_negative?, '(send (send _ :!) :!)'
|
|
@@ -112,9 +111,11 @@ module RuboCop
|
|
|
112
111
|
end
|
|
113
112
|
|
|
114
113
|
def message(node, keyword)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
if node.elsif?
|
|
115
|
+
MSG_FOR_ELSIF
|
|
116
|
+
else
|
|
117
|
+
format(MSG, keyword: keyword)
|
|
118
|
+
end
|
|
118
119
|
end
|
|
119
120
|
|
|
120
121
|
def return_boolean_value?(condition)
|
|
@@ -154,8 +155,7 @@ module RuboCop
|
|
|
154
155
|
end
|
|
155
156
|
|
|
156
157
|
def require_parentheses?(condition)
|
|
157
|
-
condition.
|
|
158
|
-
(condition.send_type? && condition.comparison_method?)
|
|
158
|
+
condition.operator_keyword? || (condition.send_type? && condition.comparison_method?)
|
|
159
159
|
end
|
|
160
160
|
end
|
|
161
161
|
end
|
|
@@ -18,28 +18,67 @@ module RuboCop
|
|
|
18
18
|
extend AutoCorrector
|
|
19
19
|
|
|
20
20
|
MSG_IF_ELSE = 'Do not use `if %<expr>s;` - use `if/else` instead.'
|
|
21
|
+
MSG_NEWLINE = 'Do not use `if %<expr>s;` - use a newline instead.'
|
|
21
22
|
MSG_TERNARY = 'Do not use `if %<expr>s;` - use a ternary operator instead.'
|
|
22
23
|
|
|
23
24
|
def on_normal_if_unless(node)
|
|
24
25
|
return if node.parent&.if_type?
|
|
26
|
+
return if part_of_ignored_node?(node)
|
|
25
27
|
|
|
26
28
|
beginning = node.loc.begin
|
|
27
29
|
return unless beginning&.is?(';')
|
|
28
30
|
|
|
29
|
-
message = node
|
|
31
|
+
message = message(node)
|
|
30
32
|
|
|
31
|
-
add_offense(node, message:
|
|
32
|
-
corrector
|
|
33
|
+
add_offense(node, message: message) do |corrector|
|
|
34
|
+
autocorrect(corrector, node)
|
|
33
35
|
end
|
|
36
|
+
|
|
37
|
+
ignore_node(node)
|
|
34
38
|
end
|
|
35
39
|
|
|
36
40
|
private
|
|
37
41
|
|
|
38
|
-
def
|
|
42
|
+
def message(node)
|
|
43
|
+
template = if require_newline?(node)
|
|
44
|
+
MSG_NEWLINE
|
|
45
|
+
elsif node.else_branch&.type?(:if, :begin) ||
|
|
46
|
+
use_masgn_or_block_in_branches?(node)
|
|
47
|
+
MSG_IF_ELSE
|
|
48
|
+
else
|
|
49
|
+
MSG_TERNARY
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
format(template, expr: node.condition.source)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def autocorrect(corrector, node)
|
|
56
|
+
if require_newline?(node) || use_masgn_or_block_in_branches?(node)
|
|
57
|
+
corrector.replace(node.loc.begin, "\n")
|
|
58
|
+
else
|
|
59
|
+
corrector.replace(node, replacement(node))
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def require_newline?(node)
|
|
64
|
+
node.branches.compact.any?(&:begin_type?) || use_return_with_argument?(node)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def use_masgn_or_block_in_branches?(node)
|
|
68
|
+
node.branches.compact.any? do |branch|
|
|
69
|
+
branch.type?(:masgn, :any_block)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def use_return_with_argument?(node)
|
|
74
|
+
node.if_branch&.return_type? && node.if_branch&.arguments&.any?
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def replacement(node)
|
|
39
78
|
return correct_elsif(node) if node.else_branch&.if_type?
|
|
40
79
|
|
|
41
|
-
then_code = node.if_branch ? node.if_branch
|
|
42
|
-
else_code = node.else_branch ? node.else_branch
|
|
80
|
+
then_code = node.if_branch ? build_expression(node.if_branch) : 'nil'
|
|
81
|
+
else_code = node.else_branch ? build_expression(node.else_branch) : 'nil'
|
|
43
82
|
|
|
44
83
|
"#{node.condition.source} ? #{then_code} : #{else_code}"
|
|
45
84
|
end
|
|
@@ -53,6 +92,15 @@ module RuboCop
|
|
|
53
92
|
RUBY
|
|
54
93
|
end
|
|
55
94
|
|
|
95
|
+
def build_expression(expr)
|
|
96
|
+
return expr.source unless require_argument_parentheses?(expr)
|
|
97
|
+
|
|
98
|
+
method = expr.source_range.begin.join(expr.loc.selector.end)
|
|
99
|
+
arguments = expr.first_argument.source_range.begin.join(expr.source_range.end)
|
|
100
|
+
|
|
101
|
+
"#{method.source}(#{arguments.source})"
|
|
102
|
+
end
|
|
103
|
+
|
|
56
104
|
def build_else_branch(second_condition)
|
|
57
105
|
result = <<~RUBY
|
|
58
106
|
elsif #{second_condition.condition.source}
|
|
@@ -72,6 +120,12 @@ module RuboCop
|
|
|
72
120
|
|
|
73
121
|
result
|
|
74
122
|
end
|
|
123
|
+
|
|
124
|
+
def require_argument_parentheses?(node)
|
|
125
|
+
return false if !node.call_type? || node.arithmetic_operation?
|
|
126
|
+
|
|
127
|
+
!node.parenthesized? && node.arguments.any? && !node.method?(:[]) && !node.method?(:[]=)
|
|
128
|
+
end
|
|
75
129
|
end
|
|
76
130
|
end
|
|
77
131
|
end
|
|
@@ -44,11 +44,15 @@ module RuboCop
|
|
|
44
44
|
private
|
|
45
45
|
|
|
46
46
|
def alternative_pattern_source(pattern)
|
|
47
|
+
collect_alternative_patterns(pattern).join(' | ')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def collect_alternative_patterns(pattern)
|
|
47
51
|
return pattern.children.map(&:source) unless pattern.children.first.match_alt_type?
|
|
48
52
|
|
|
49
|
-
pattern_sources =
|
|
53
|
+
pattern_sources = collect_alternative_patterns(pattern.children.first)
|
|
50
54
|
|
|
51
|
-
|
|
55
|
+
pattern_sources << pattern.children[1].source
|
|
52
56
|
end
|
|
53
57
|
end
|
|
54
58
|
end
|
|
@@ -68,7 +68,7 @@ module RuboCop
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def autocorrect(corrector, node)
|
|
71
|
-
if node.
|
|
71
|
+
if node.post_condition_loop?
|
|
72
72
|
replace_begin_end_with_modifier(corrector, node)
|
|
73
73
|
elsif node.modifier_form?
|
|
74
74
|
replace_source(corrector, node.source_range, modifier_replacement(node))
|