rubocop 1.79.2 → 1.88.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/config/default.yml +259 -90
- data/config/obsoletion.yml +30 -1
- data/exe/rubocop +1 -8
- data/lib/rubocop/cache_config.rb +29 -0
- data/lib/rubocop/cli/command/auto_generate_config.rb +36 -4
- data/lib/rubocop/cli/command/list_enabled_cops_for.rb +40 -0
- data/lib/rubocop/cli/command/lsp.rb +1 -1
- data/lib/rubocop/cli/command/mcp.rb +19 -0
- data/lib/rubocop/cli/command/show_cops.rb +2 -2
- data/lib/rubocop/cli/command/show_docs_url.rb +4 -8
- data/lib/rubocop/cli/command/suggest_extensions.rb +1 -1
- data/lib/rubocop/cli.rb +35 -9
- data/lib/rubocop/comment_config.rb +59 -17
- data/lib/rubocop/config.rb +14 -10
- data/lib/rubocop/config_finder.rb +1 -1
- data/lib/rubocop/config_loader.rb +37 -23
- data/lib/rubocop/config_loader_resolver.rb +20 -10
- data/lib/rubocop/config_obsoletion/extracted_cop.rb +4 -2
- data/lib/rubocop/config_store.rb +7 -2
- data/lib/rubocop/config_validator.rb +1 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +10 -5
- data/lib/rubocop/cop/base.rb +25 -4
- data/lib/rubocop/cop/bundler/gem_comment.rb +2 -2
- data/lib/rubocop/cop/bundler/gem_version.rb +28 -28
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -2
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +26 -7
- data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -2
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +1 -5
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +33 -2
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors.rb +28 -0
- data/lib/rubocop/cop/documentation.rb +2 -3
- data/lib/rubocop/cop/exclude_limit.rb +31 -5
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -2
- data/lib/rubocop/cop/gemspec/require_mfa.rb +5 -5
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +12 -7
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +8 -8
- data/lib/rubocop/cop/internal_affairs/itblock_handler.rb +69 -0
- data/lib/rubocop/cop/internal_affairs/location_exists.rb +28 -2
- data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +9 -9
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +3 -1
- data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +5 -3
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +4 -4
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/argument_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/begin_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/block_alignment.rb +41 -4
- data/lib/rubocop/cop/layout/case_indentation.rb +3 -1
- data/lib/rubocop/cop/layout/class_structure.rb +14 -7
- data/lib/rubocop/cop/layout/dot_position.rb +2 -2
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +26 -7
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +31 -13
- data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +2 -2
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +1 -0
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +12 -2
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +16 -2
- data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +16 -2
- data/lib/rubocop/cop/layout/end_alignment.rb +10 -3
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +34 -1
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +26 -0
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +7 -1
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +25 -25
- data/lib/rubocop/cop/layout/hash_alignment.rb +3 -6
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +33 -3
- data/lib/rubocop/cop/layout/indentation_style.rb +1 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +123 -7
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +26 -9
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +57 -57
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +9 -2
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -0
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +56 -56
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +229 -39
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +8 -4
- data/lib/rubocop/cop/layout/parameter_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/redundant_line_break.rb +3 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +13 -3
- data/lib/rubocop/cop/layout/space_after_comma.rb +2 -10
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +4 -2
- data/lib/rubocop/cop/layout/space_before_brackets.rb +1 -1
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -8
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_assignment.rb +1 -11
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_operator_precedence.rb +1 -10
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +45 -3
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +4 -3
- data/lib/rubocop/cop/lint/constant_reassignment.rb +93 -11
- data/lib/rubocop/cop/lint/constant_resolution.rb +6 -6
- data/lib/rubocop/cop/lint/cop_directive_syntax.rb +14 -8
- data/lib/rubocop/cop/lint/data_define_override.rb +63 -0
- data/lib/rubocop/cop/lint/debugger.rb +0 -3
- data/lib/rubocop/cop/lint/deprecated_constants.rb +2 -8
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +4 -1
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +4 -4
- data/lib/rubocop/cop/lint/duplicate_methods.rb +111 -12
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
- data/lib/rubocop/cop/lint/else_layout.rb +19 -0
- data/lib/rubocop/cop/lint/empty_block.rb +4 -4
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +6 -1
- data/lib/rubocop/cop/lint/empty_in_pattern.rb +8 -1
- data/lib/rubocop/cop/lint/empty_interpolation.rb +11 -0
- data/lib/rubocop/cop/lint/empty_when.rb +8 -1
- data/lib/rubocop/cop/lint/ensure_return.rb +19 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +4 -2
- data/lib/rubocop/cop/lint/float_comparison.rb +2 -1
- data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +5 -1
- data/lib/rubocop/cop/lint/interpolation_check.rb +25 -5
- data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +1 -1
- data/lib/rubocop/cop/lint/literal_as_condition.rb +5 -1
- data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +11 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +9 -12
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +19 -10
- data/lib/rubocop/cop/lint/multiple_comparison.rb +2 -2
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +2 -0
- data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +20 -0
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +4 -2
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +1 -1
- data/lib/rubocop/cop/lint/number_conversion.rb +19 -10
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +1 -1
- data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +3 -0
- data/lib/rubocop/cop/lint/ordered_magic_comments.rb +7 -7
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +3 -13
- data/lib/rubocop/cop/lint/raise_exception.rb +1 -1
- data/lib/rubocop/cop/lint/rand_one.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +27 -10
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +6 -12
- data/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb +15 -4
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +4 -2
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +36 -12
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +12 -2
- data/lib/rubocop/cop/lint/redundant_type_conversion.rb +10 -3
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_with_object.rb +5 -0
- data/lib/rubocop/cop/lint/refinement_import_methods.rb +8 -1
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +9 -1
- data/lib/rubocop/cop/lint/require_parentheses.rb +13 -4
- data/lib/rubocop/cop/lint/require_range_parentheses.rb +2 -1
- data/lib/rubocop/cop/lint/require_relative_self_path.rb +7 -5
- 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/safe_navigation_chain.rb +18 -0
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +7 -1
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -1
- data/lib/rubocop/cop/lint/script_permission.rb +5 -1
- data/lib/rubocop/cop/lint/self_assignment.rb +39 -7
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -1
- data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
- data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +14 -0
- data/lib/rubocop/cop/lint/shared_mutable_default.rb +3 -1
- data/lib/rubocop/cop/lint/struct_new_override.rb +17 -1
- data/lib/rubocop/cop/lint/suppressed_exception_in_number_conversion.rb +12 -0
- data/lib/rubocop/cop/lint/symbol_conversion.rb +21 -4
- data/lib/rubocop/cop/lint/syntax.rb +25 -1
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +28 -1
- data/lib/rubocop/cop/lint/to_json.rb +12 -16
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +5 -1
- data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +4 -2
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +7 -5
- data/lib/rubocop/cop/lint/unreachable_pattern_branch.rb +113 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +10 -0
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
- data/lib/rubocop/cop/lint/useless_assignment.rb +53 -25
- data/lib/rubocop/cop/lint/useless_constant_scoping.rb +4 -4
- data/lib/rubocop/cop/lint/useless_default_value_argument.rb +2 -0
- data/lib/rubocop/cop/lint/useless_or.rb +15 -2
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +8 -4
- data/lib/rubocop/cop/lint/useless_setter_call.rb +4 -1
- data/lib/rubocop/cop/lint/useless_times.rb +22 -1
- data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +37 -11
- data/lib/rubocop/cop/lint/void.rb +39 -12
- data/lib/rubocop/cop/message_annotator.rb +1 -1
- data/lib/rubocop/cop/metrics/block_length.rb +1 -1
- data/lib/rubocop/cop/metrics/block_nesting.rb +23 -0
- data/lib/rubocop/cop/metrics/collection_literal_length.rb +1 -1
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +4 -3
- data/lib/rubocop/cop/metrics/utils/iterating_block.rb +1 -1
- data/lib/rubocop/cop/migration/department_name.rb +12 -1
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +2 -2
- data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +4 -6
- data/lib/rubocop/cop/mixin/code_length.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_max.rb +6 -5
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +5 -5
- data/lib/rubocop/cop/mixin/hash_transform_method/autocorrection.rb +63 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +10 -60
- data/lib/rubocop/cop/mixin/line_length_help.rb +21 -2
- data/lib/rubocop/cop/mixin/method_complexity.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -1
- data/lib/rubocop/cop/mixin/project_index_help.rb +48 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +5 -4
- data/lib/rubocop/cop/mixin/statement_modifier.rb +0 -6
- data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -5
- data/lib/rubocop/cop/mixin.rb +86 -0
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +5 -3
- data/lib/rubocop/cop/naming/predicate_method.rb +32 -8
- data/lib/rubocop/cop/naming/predicate_prefix.rb +12 -12
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
- data/lib/rubocop/cop/offense.rb +17 -1
- data/lib/rubocop/cop/registry.rb +62 -38
- data/lib/rubocop/cop/security/eval.rb +15 -2
- data/lib/rubocop/cop/security/io_methods.rb +1 -1
- data/lib/rubocop/cop/security/json_load.rb +33 -11
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +15 -4
- data/lib/rubocop/cop/style/accessor_grouping.rb +4 -2
- data/lib/rubocop/cop/style/alias.rb +15 -3
- data/lib/rubocop/cop/style/and_or.rb +2 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +25 -7
- data/lib/rubocop/cop/style/array_first_last.rb +12 -1
- data/lib/rubocop/cop/style/array_intersect.rb +50 -12
- data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +50 -0
- data/lib/rubocop/cop/style/array_join.rb +4 -2
- data/lib/rubocop/cop/style/ascii_comments.rb +6 -3
- data/lib/rubocop/cop/style/attr.rb +5 -2
- data/lib/rubocop/cop/style/bare_percent_literals.rb +4 -3
- data/lib/rubocop/cop/style/begin_block.rb +3 -1
- data/lib/rubocop/cop/style/bitwise_predicate.rb +8 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +39 -32
- data/lib/rubocop/cop/style/case_equality.rb +29 -15
- data/lib/rubocop/cop/style/character_literal.rb +2 -2
- data/lib/rubocop/cop/style/class_and_module_children.rb +19 -2
- data/lib/rubocop/cop/style/class_equality_comparison.rb +21 -13
- data/lib/rubocop/cop/style/class_methods_definitions.rb +11 -5
- data/lib/rubocop/cop/style/collection_compact.rb +36 -16
- data/lib/rubocop/cop/style/colon_method_call.rb +16 -7
- data/lib/rubocop/cop/style/combinable_loops.rb +5 -0
- data/lib/rubocop/cop/style/comparable_clamp.rb +12 -1
- data/lib/rubocop/cop/style/concat_array_literals.rb +7 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +14 -19
- data/lib/rubocop/cop/style/constant_visibility.rb +20 -12
- data/lib/rubocop/cop/style/copyright.rb +22 -11
- data/lib/rubocop/cop/style/date_time.rb +4 -4
- data/lib/rubocop/cop/style/dig_chain.rb +5 -0
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +6 -1
- data/lib/rubocop/cop/style/documentation.rb +6 -6
- data/lib/rubocop/cop/style/documentation_method.rb +8 -8
- data/lib/rubocop/cop/style/double_negation.rb +1 -1
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
- data/lib/rubocop/cop/style/each_with_object.rb +2 -0
- data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
- data/lib/rubocop/cop/style/empty_class_definition.rb +119 -0
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
- data/lib/rubocop/cop/style/empty_method.rb +0 -6
- data/lib/rubocop/cop/style/encoding.rb +7 -1
- data/lib/rubocop/cop/style/end_block.rb +3 -1
- data/lib/rubocop/cop/style/endless_method.rb +23 -5
- data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
- data/lib/rubocop/cop/style/fetch_env_var.rb +1 -1
- data/lib/rubocop/cop/style/file_open.rb +84 -0
- data/lib/rubocop/cop/style/file_write.rb +21 -16
- data/lib/rubocop/cop/style/float_division.rb +15 -1
- data/lib/rubocop/cop/style/for.rb +3 -0
- data/lib/rubocop/cop/style/format_string.rb +4 -3
- data/lib/rubocop/cop/style/format_string_token.rb +49 -5
- data/lib/rubocop/cop/style/global_vars.rb +5 -2
- data/lib/rubocop/cop/style/guard_clause.rb +27 -22
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +27 -9
- data/lib/rubocop/cop/style/hash_conversion.rb +1 -1
- data/lib/rubocop/cop/style/hash_lookup_method.rb +106 -0
- data/lib/rubocop/cop/style/hash_slice.rb +16 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/hash_transform_keys.rb +17 -7
- data/lib/rubocop/cop/style/hash_transform_values.rb +17 -7
- data/lib/rubocop/cop/style/if_inside_else.rb +16 -7
- data/lib/rubocop/cop/style/if_unless_modifier.rb +58 -18
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -12
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +4 -1
- data/lib/rubocop/cop/style/if_with_semicolon.rb +7 -5
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inline_comment.rb +4 -1
- data/lib/rubocop/cop/style/ip_addresses.rb +1 -2
- data/lib/rubocop/cop/style/lambda_call.rb +8 -8
- data/lib/rubocop/cop/style/magic_comment_format.rb +3 -3
- data/lib/rubocop/cop/style/map_join.rb +123 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +15 -2
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +17 -4
- data/lib/rubocop/cop/style/method_def_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/min_max_comparison.rb +1 -1
- data/lib/rubocop/cop/style/module_member_existence_check.rb +110 -0
- data/lib/rubocop/cop/style/multiline_if_then.rb +4 -4
- data/lib/rubocop/cop/style/multiline_method_signature.rb +2 -4
- data/lib/rubocop/cop/style/mutable_constant.rb +106 -12
- data/lib/rubocop/cop/style/negative_array_index.rb +220 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +11 -10
- data/lib/rubocop/cop/style/nil_lambda.rb +1 -1
- data/lib/rubocop/cop/style/non_nil_check.rb +5 -11
- data/lib/rubocop/cop/style/not.rb +2 -0
- data/lib/rubocop/cop/style/numeric_literals.rb +3 -2
- data/lib/rubocop/cop/style/one_class_per_file.rb +115 -0
- data/lib/rubocop/cop/style/one_line_conditional.rb +21 -12
- data/lib/rubocop/cop/style/operator_method_call.rb +11 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +14 -3
- data/lib/rubocop/cop/style/partition_instead_of_double_select.rb +270 -0
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -0
- data/lib/rubocop/cop/style/predicate_with_kind.rb +84 -0
- data/lib/rubocop/cop/style/preferred_hash_methods.rb +12 -12
- data/lib/rubocop/cop/style/proc.rb +3 -2
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/reduce_to_hash.rb +200 -0
- data/lib/rubocop/cop/style/redundant_argument.rb +2 -0
- data/lib/rubocop/cop/style/redundant_array_constructor.rb +2 -2
- data/lib/rubocop/cop/style/redundant_begin.rb +37 -3
- data/lib/rubocop/cop/style/redundant_condition.rb +6 -3
- data/lib/rubocop/cop/style/redundant_constant_base.rb +5 -5
- data/lib/rubocop/cop/style/redundant_each.rb +3 -3
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -1
- data/lib/rubocop/cop/style/redundant_format.rb +27 -5
- data/lib/rubocop/cop/style/redundant_interpolation.rb +11 -2
- data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +26 -10
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +16 -0
- data/lib/rubocop/cop/style/redundant_min_max_by.rb +93 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +36 -30
- data/lib/rubocop/cop/style/redundant_percent_q.rb +5 -3
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +9 -0
- data/lib/rubocop/cop/style/redundant_regexp_constructor.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -0
- data/lib/rubocop/cop/style/redundant_return.rb +3 -1
- data/lib/rubocop/cop/style/redundant_self.rb +2 -2
- data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +0 -5
- data/lib/rubocop/cop/style/redundant_sort.rb +7 -7
- data/lib/rubocop/cop/style/redundant_struct_keyword_init.rb +114 -0
- data/lib/rubocop/cop/style/regexp_literal.rb +31 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +3 -3
- data/lib/rubocop/cop/style/reverse_find.rb +51 -0
- data/lib/rubocop/cop/style/safe_navigation.rb +25 -8
- data/lib/rubocop/cop/style/select_by_kind.rb +158 -0
- data/lib/rubocop/cop/style/select_by_range.rb +197 -0
- data/lib/rubocop/cop/style/select_by_regexp.rb +51 -21
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +41 -8
- data/lib/rubocop/cop/style/single_line_block_params.rb +2 -2
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +3 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +12 -3
- data/lib/rubocop/cop/style/special_global_vars.rb +6 -1
- data/lib/rubocop/cop/style/string_concatenation.rb +17 -13
- data/lib/rubocop/cop/style/struct_inheritance.rb +13 -0
- data/lib/rubocop/cop/style/super_arguments.rb +2 -2
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +7 -6
- data/lib/rubocop/cop/style/tally_method.rb +181 -0
- data/lib/rubocop/cop/style/top_level_method_definition.rb +2 -2
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +45 -0
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +11 -11
- data/lib/rubocop/cop/style/unless_else.rb +10 -9
- data/lib/rubocop/cop/style/unless_logical_operators.rb +3 -3
- data/lib/rubocop/cop/style/while_until_do.rb +7 -0
- data/lib/rubocop/cop/style/while_until_modifier.rb +16 -0
- data/lib/rubocop/cop/style/word_array.rb +1 -0
- data/lib/rubocop/cop/style/yoda_condition.rb +1 -1
- data/lib/rubocop/cop/style/yoda_expression.rb +1 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +6 -3
- data/lib/rubocop/cop/team.rb +87 -36
- data/lib/rubocop/cop/util.rb +2 -3
- data/lib/rubocop/cop/utils/format_string.rb +10 -0
- data/lib/rubocop/cop/variable_force/branch.rb +30 -6
- data/lib/rubocop/cop/variable_force/variable.rb +1 -1
- data/lib/rubocop/cop/variable_force.rb +9 -7
- data/lib/rubocop/cops_documentation_generator.rb +4 -4
- data/lib/rubocop/directive_comment.rb +48 -4
- data/lib/rubocop/file_patterns.rb +9 -1
- data/lib/rubocop/formatter/clang_style_formatter.rb +5 -2
- data/lib/rubocop/formatter/disabled_config_formatter.rb +38 -14
- data/lib/rubocop/formatter/formatter_set.rb +2 -2
- data/lib/rubocop/formatter/junit_formatter.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +0 -2
- data/lib/rubocop/formatter/tap_formatter.rb +5 -2
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -1
- data/lib/rubocop/formatter.rb +22 -21
- data/lib/rubocop/lsp/diagnostic.rb +18 -33
- data/lib/rubocop/lsp/disable_comment_edits.rb +135 -0
- data/lib/rubocop/lsp/routes.rb +43 -7
- data/lib/rubocop/lsp/runtime.rb +13 -4
- data/lib/rubocop/lsp/stdin_runner.rb +8 -17
- data/lib/rubocop/magic_comment.rb +20 -0
- data/lib/rubocop/mcp/server.rb +200 -0
- data/lib/rubocop/options.rb +35 -4
- data/lib/rubocop/path_util.rb +14 -2
- data/lib/rubocop/plugin/loader.rb +1 -1
- data/lib/rubocop/project_index_loader.rb +66 -0
- data/lib/rubocop/rake_task.rb +1 -1
- data/lib/rubocop/remote_config.rb +10 -8
- data/lib/rubocop/result_cache.rb +61 -38
- data/lib/rubocop/rspec/cop_helper.rb +8 -0
- data/lib/rubocop/rspec/shared_contexts.rb +39 -5
- data/lib/rubocop/rspec/support.rb +2 -1
- data/lib/rubocop/runner.rb +134 -57
- data/lib/rubocop/server/cache.rb +6 -29
- data/lib/rubocop/server/core.rb +8 -0
- data/lib/rubocop/target_finder.rb +17 -10
- data/lib/rubocop/target_ruby.rb +31 -14
- data/lib/rubocop/version.rb +21 -3
- data/lib/rubocop.rb +28 -96
- data/lib/ruby_lsp/rubocop/addon.rb +23 -8
- data/lib/ruby_lsp/rubocop/runtime_adapter.rb +49 -15
- metadata +38 -9
|
@@ -7,18 +7,18 @@ module RuboCop
|
|
|
7
7
|
# parenthesis (`(`) in lambda literals.
|
|
8
8
|
#
|
|
9
9
|
# @example EnforcedStyle: require_no_space (default)
|
|
10
|
-
#
|
|
11
|
-
#
|
|
10
|
+
# # bad
|
|
11
|
+
# a = -> (x, y) { x + y }
|
|
12
12
|
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
13
|
+
# # good
|
|
14
|
+
# a = ->(x, y) { x + y }
|
|
15
15
|
#
|
|
16
16
|
# @example EnforcedStyle: require_space
|
|
17
|
-
#
|
|
18
|
-
#
|
|
17
|
+
# # bad
|
|
18
|
+
# a = ->(x, y) { x + y }
|
|
19
19
|
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
20
|
+
# # good
|
|
21
|
+
# a = -> (x, y) { x + y }
|
|
22
22
|
class SpaceInLambdaLiteral < Base
|
|
23
23
|
include ConfigurableEnforcedStyle
|
|
24
24
|
include RangeHelp
|
|
@@ -26,6 +26,7 @@ module RuboCop
|
|
|
26
26
|
|
|
27
27
|
MSG_REQUIRE_SPACE = 'Use a space between `->` and `(` in lambda literals.'
|
|
28
28
|
MSG_REQUIRE_NO_SPACE = 'Do not use spaces between `->` and `(` in lambda literals.'
|
|
29
|
+
RESTRICT_ON_SEND = %i[lambda].freeze
|
|
29
30
|
|
|
30
31
|
def on_send(node)
|
|
31
32
|
return unless arrow_lambda_with_args?(node)
|
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
|
28
28
|
MISTAKES = { '=-' => '-=', '=+' => '+=', '=*' => '*=', '=!' => '!=' }.freeze
|
|
29
29
|
|
|
30
30
|
def on_asgn(node)
|
|
31
|
-
return unless (rhs =
|
|
31
|
+
return unless (rhs = node.expression)
|
|
32
32
|
|
|
33
33
|
range = range_between(node.loc.operator.end_pos - 1, rhs.source_range.begin_pos + 1)
|
|
34
34
|
source = range.source
|
|
@@ -38,16 +38,6 @@ module RuboCop
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
SIMPLE_ASSIGNMENT_TYPES.each { |asgn_type| alias_method :"on_#{asgn_type}", :on_asgn }
|
|
41
|
-
|
|
42
|
-
private
|
|
43
|
-
|
|
44
|
-
def rhs(node)
|
|
45
|
-
if node.casgn_type?
|
|
46
|
-
node.children[2]
|
|
47
|
-
else
|
|
48
|
-
node.children[1]
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
41
|
end
|
|
52
42
|
end
|
|
53
43
|
end
|
|
@@ -44,13 +44,6 @@ module RuboCop
|
|
|
44
44
|
RESTRICT_ON_SEND = PRECEDENCE.flatten.freeze
|
|
45
45
|
MSG = 'Wrap expressions with varying precedence with parentheses to avoid ambiguity.'
|
|
46
46
|
|
|
47
|
-
def on_new_investigation
|
|
48
|
-
# Cache the precedence of each node being investigated
|
|
49
|
-
# so that we only need to calculate it once
|
|
50
|
-
@node_precedences = {}
|
|
51
|
-
super
|
|
52
|
-
end
|
|
53
|
-
|
|
54
47
|
def on_and(node)
|
|
55
48
|
return unless (parent = node.parent)
|
|
56
49
|
|
|
@@ -77,9 +70,7 @@ module RuboCop
|
|
|
77
70
|
private
|
|
78
71
|
|
|
79
72
|
def precedence(node)
|
|
80
|
-
|
|
81
|
-
PRECEDENCE.index { |operators| operators.include?(operator_name(node)) }
|
|
82
|
-
end
|
|
73
|
+
PRECEDENCE.index { |operators| operators.include?(operator_name(node)) }
|
|
83
74
|
end
|
|
84
75
|
|
|
85
76
|
def operator?(node)
|
|
@@ -35,6 +35,26 @@ module RuboCop
|
|
|
35
35
|
# def cook(dry_ingredients = self.dry_ingredients)
|
|
36
36
|
# dry_ingredients.combine
|
|
37
37
|
# end
|
|
38
|
+
#
|
|
39
|
+
# # bad
|
|
40
|
+
# def foo(pie = pie = pie)
|
|
41
|
+
# pie.heat_up
|
|
42
|
+
# end
|
|
43
|
+
#
|
|
44
|
+
# # good
|
|
45
|
+
# def foo(pie)
|
|
46
|
+
# pie.heat_up
|
|
47
|
+
# end
|
|
48
|
+
#
|
|
49
|
+
# # bad
|
|
50
|
+
# def foo(pie = cake = pie)
|
|
51
|
+
# [pie, cake].each(&:heat_up)
|
|
52
|
+
# end
|
|
53
|
+
#
|
|
54
|
+
# # good
|
|
55
|
+
# def foo(cake = pie)
|
|
56
|
+
# [pie, cake].each(&:heat_up)
|
|
57
|
+
# end
|
|
38
58
|
class CircularArgumentReference < Base
|
|
39
59
|
extend TargetRubyVersion
|
|
40
60
|
|
|
@@ -51,10 +71,32 @@ module RuboCop
|
|
|
51
71
|
private
|
|
52
72
|
|
|
53
73
|
def check_for_circular_argument_references(arg_name, arg_value)
|
|
54
|
-
|
|
55
|
-
|
|
74
|
+
if arg_value.lvar_type? && arg_value.to_a == [arg_name]
|
|
75
|
+
add_offense(arg_value, message: format(MSG, arg_name: arg_name))
|
|
76
|
+
|
|
77
|
+
return
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
check_assignment_chain(arg_name, arg_value)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def check_assignment_chain(arg_name, node)
|
|
84
|
+
return unless node.lvasgn_type?
|
|
85
|
+
|
|
86
|
+
seen_variables = Set[]
|
|
87
|
+
current_node = node
|
|
88
|
+
|
|
89
|
+
while current_node.lvasgn_type?
|
|
90
|
+
seen_variables << current_node.children.first
|
|
91
|
+
current_node = current_node.children.last
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
return unless current_node.lvar_type?
|
|
95
|
+
|
|
96
|
+
variable_node = current_node.children.first
|
|
97
|
+
return unless seen_variables.include?(variable_node) || variable_node == arg_name
|
|
56
98
|
|
|
57
|
-
add_offense(
|
|
99
|
+
add_offense(current_node, message: format(MSG, arg_name: arg_name))
|
|
58
100
|
end
|
|
59
101
|
end
|
|
60
102
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
module Cop
|
|
5
5
|
module Lint
|
|
6
|
-
# Checks for overwriting an exception with an exception result by
|
|
6
|
+
# Checks for overwriting an exception with an exception result by using ``rescue =>``.
|
|
7
7
|
#
|
|
8
8
|
# You intended to write as `rescue StandardError`.
|
|
9
9
|
# However, you have written `rescue => StandardError`.
|
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
|
31
31
|
|
|
32
32
|
# @!method overwritten_constant(node)
|
|
33
33
|
def_node_matcher :overwritten_constant, <<~PATTERN
|
|
34
|
-
(resbody nil? (casgn
|
|
34
|
+
(resbody nil? $(casgn _ _) nil?)
|
|
35
35
|
PATTERN
|
|
36
36
|
|
|
37
37
|
def self.autocorrect_incompatible_with
|
|
@@ -41,7 +41,8 @@ module RuboCop
|
|
|
41
41
|
def on_resbody(node)
|
|
42
42
|
return unless (constant = overwritten_constant(node))
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
message = format(MSG, constant: constant.source)
|
|
45
|
+
add_offense(node.loc.assoc, message: message) do |corrector|
|
|
45
46
|
corrector.remove(range_between(node.loc.keyword.end_pos, node.loc.assoc.end_pos))
|
|
46
47
|
end
|
|
47
48
|
end
|
|
@@ -6,11 +6,19 @@ module RuboCop
|
|
|
6
6
|
# Checks for constant reassignments.
|
|
7
7
|
#
|
|
8
8
|
# Emulates Ruby's runtime warning "already initialized constant X"
|
|
9
|
-
# when a constant is reassigned in the same file and namespace
|
|
10
|
-
# `NAME = value` syntax.
|
|
9
|
+
# when a constant is reassigned in the same file and namespace.
|
|
11
10
|
#
|
|
12
|
-
# The cop
|
|
13
|
-
#
|
|
11
|
+
# The cop tracks constants defined via `NAME = value` syntax as well as
|
|
12
|
+
# class/module keyword definitions. It detects reassignment when a constant
|
|
13
|
+
# is first defined one way and then redefined using the `NAME = value` syntax.
|
|
14
|
+
#
|
|
15
|
+
# The cop cannot catch all offenses, like, for example, when using metaprogramming
|
|
16
|
+
# (`Module#const_set`).
|
|
17
|
+
#
|
|
18
|
+
# By default the cop also cannot detect reassignment across files.
|
|
19
|
+
# When `AllCops/UseProjectIndex` is enabled and the `rubydex` gem is installed,
|
|
20
|
+
# the cop additionally consults the project-wide index and reports reassignments
|
|
21
|
+
# whose previous definition lives in another file.
|
|
14
22
|
#
|
|
15
23
|
# The cop only takes into account constants assigned in a "simple" way: directly
|
|
16
24
|
# inside class/module definition, or within another constant. Other type of assignments
|
|
@@ -36,6 +44,14 @@ module RuboCop
|
|
|
36
44
|
# X = :bar
|
|
37
45
|
# end
|
|
38
46
|
#
|
|
47
|
+
# # bad
|
|
48
|
+
# class FooError < StandardError; end
|
|
49
|
+
# FooError = Class.new(RuntimeError)
|
|
50
|
+
#
|
|
51
|
+
# # bad
|
|
52
|
+
# module M; end
|
|
53
|
+
# M = 1
|
|
54
|
+
#
|
|
39
55
|
# # good - keep only one assignment
|
|
40
56
|
# X = :bar
|
|
41
57
|
#
|
|
@@ -63,22 +79,44 @@ module RuboCop
|
|
|
63
79
|
# end
|
|
64
80
|
#
|
|
65
81
|
class ConstantReassignment < Base
|
|
82
|
+
include ProjectIndexHelp
|
|
83
|
+
|
|
66
84
|
MSG = 'Constant `%<constant>s` is already assigned in this namespace.'
|
|
85
|
+
CROSS_FILE_MSG = 'Constant `%<constant>s` is already assigned in `%<path>s`.'
|
|
67
86
|
|
|
68
87
|
RESTRICT_ON_SEND = %i[remove_const].freeze
|
|
69
88
|
|
|
70
89
|
# @!method remove_constant(node)
|
|
71
90
|
def_node_matcher :remove_constant, <<~PATTERN
|
|
72
|
-
(send
|
|
91
|
+
(send {nil? self} :remove_const
|
|
73
92
|
({sym str} $_))
|
|
74
93
|
PATTERN
|
|
75
94
|
|
|
95
|
+
def on_class(node)
|
|
96
|
+
return unless unconditional_definition?(node)
|
|
97
|
+
|
|
98
|
+
constant_definitions[definition_name(node)] ||= :class
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def on_module(node)
|
|
102
|
+
return unless unconditional_definition?(node)
|
|
103
|
+
|
|
104
|
+
constant_definitions[definition_name(node)] ||= :module
|
|
105
|
+
end
|
|
106
|
+
|
|
76
107
|
def on_casgn(node)
|
|
77
108
|
return unless fixed_constant_path?(node)
|
|
78
109
|
return unless simple_assignment?(node)
|
|
79
|
-
return if constant_names.add?(fully_qualified_constant_name(node))
|
|
80
110
|
|
|
81
|
-
|
|
111
|
+
name = fully_qualified_constant_name(node)
|
|
112
|
+
|
|
113
|
+
if constant_definitions.key?(name)
|
|
114
|
+
add_offense(node, message: format(MSG, constant: constant_display_name(node)))
|
|
115
|
+
return
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
constant_definitions[name] = :casgn
|
|
119
|
+
report_cross_file_collision(node, name, constant_display_name(node))
|
|
82
120
|
end
|
|
83
121
|
|
|
84
122
|
def on_send(node)
|
|
@@ -90,7 +128,7 @@ module RuboCop
|
|
|
90
128
|
|
|
91
129
|
return if namespaces.none?
|
|
92
130
|
|
|
93
|
-
|
|
131
|
+
constant_definitions.delete(fully_qualified_name_for(namespaces, constant))
|
|
94
132
|
end
|
|
95
133
|
|
|
96
134
|
private
|
|
@@ -104,7 +142,7 @@ module RuboCop
|
|
|
104
142
|
return true if ancestor.type?(:module, :class)
|
|
105
143
|
|
|
106
144
|
ancestor.begin_type? || ancestor.literal? || ancestor.casgn_type? ||
|
|
107
|
-
freeze_method?(ancestor)
|
|
145
|
+
ancestor.type?(:masgn, :mlhs) || freeze_method?(ancestor)
|
|
108
146
|
end
|
|
109
147
|
end
|
|
110
148
|
|
|
@@ -128,6 +166,10 @@ module RuboCop
|
|
|
128
166
|
['', *namespaces, constant].join('::')
|
|
129
167
|
end
|
|
130
168
|
|
|
169
|
+
def constant_display_name(node)
|
|
170
|
+
[*constant_namespaces(node), node.name].join('::')
|
|
171
|
+
end
|
|
172
|
+
|
|
131
173
|
def constant_namespaces(node)
|
|
132
174
|
node.each_path.select(&:const_type?).map(&:short_name)
|
|
133
175
|
end
|
|
@@ -139,8 +181,48 @@ module RuboCop
|
|
|
139
181
|
.reverse
|
|
140
182
|
end
|
|
141
183
|
|
|
142
|
-
def
|
|
143
|
-
|
|
184
|
+
def unconditional_definition?(node)
|
|
185
|
+
node.each_ancestor.all? do |ancestor|
|
|
186
|
+
ancestor.type?(:begin, :module, :class)
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def definition_name(node)
|
|
191
|
+
identifier = node.identifier
|
|
192
|
+
|
|
193
|
+
if identifier.namespace&.cbase_type?
|
|
194
|
+
fully_qualified_name_for([], identifier.short_name)
|
|
195
|
+
else
|
|
196
|
+
namespaces = ancestor_namespaces(node) + identifier_namespaces(identifier)
|
|
197
|
+
fully_qualified_name_for(namespaces, identifier.short_name)
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def identifier_namespaces(identifier)
|
|
202
|
+
identifier.each_path.select(&:const_type?).map(&:short_name)
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def constant_definitions
|
|
206
|
+
@constant_definitions ||= {}
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def report_cross_file_collision(node, fully_qualified_name, display_name)
|
|
210
|
+
return unless project_index
|
|
211
|
+
return unless (declaration = project_index[fully_qualified_name.delete_prefix('::')])
|
|
212
|
+
return unless (prior = prior_definition_in_other_file(declaration))
|
|
213
|
+
|
|
214
|
+
msg = format(CROSS_FILE_MSG, constant: display_name, path: prior.location.to_file_path)
|
|
215
|
+
|
|
216
|
+
add_offense(node, message: msg)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def prior_definition_in_other_file(declaration)
|
|
220
|
+
current = processed_source.file_path
|
|
221
|
+
|
|
222
|
+
declaration.definitions.find do |definition|
|
|
223
|
+
other = definition.location.to_file_path
|
|
224
|
+
!File.identical?(other, current)
|
|
225
|
+
end
|
|
144
226
|
end
|
|
145
227
|
end
|
|
146
228
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
module Cop
|
|
5
5
|
module Lint
|
|
6
|
-
#
|
|
6
|
+
# Checks that certain constants are fully qualified.
|
|
7
7
|
#
|
|
8
8
|
# This is not enabled by default because it would mark a lot of offenses
|
|
9
9
|
# unnecessarily.
|
|
@@ -13,12 +13,12 @@ module RuboCop
|
|
|
13
13
|
#
|
|
14
14
|
# Large projects will over time end up with one or two constant names that
|
|
15
15
|
# are problematic because of a conflict with a library or just internally
|
|
16
|
-
# using the same name a namespace and a class. To avoid too many unnecessary
|
|
17
|
-
# offenses,
|
|
16
|
+
# using the same name for a namespace and a class. To avoid too many unnecessary
|
|
17
|
+
# offenses, enable this cop with `Only: [The, Constant, Names, Causing, Issues]`
|
|
18
18
|
#
|
|
19
|
-
# NOTE: `Style/RedundantConstantBase` cop is disabled if this cop is enabled
|
|
20
|
-
# conflicting rules.
|
|
21
|
-
# this cop which is disabled by default.
|
|
19
|
+
# NOTE: `Style/RedundantConstantBase` cop is disabled if this cop is enabled,
|
|
20
|
+
# to prevent conflicting rules. This is because it respects user configurations
|
|
21
|
+
# that want to enable this cop which is disabled by default.
|
|
22
22
|
#
|
|
23
23
|
# @example
|
|
24
24
|
# # By default checks every constant
|
|
@@ -13,34 +13,40 @@ module RuboCop
|
|
|
13
13
|
# @example
|
|
14
14
|
# # bad
|
|
15
15
|
# # rubocop:disable Layout/LineLength Style/Encoding
|
|
16
|
-
#
|
|
16
|
+
#
|
|
17
|
+
# # good
|
|
18
|
+
# # rubocop:disable Layout/LineLength, Style/Encoding
|
|
17
19
|
#
|
|
18
20
|
# # bad
|
|
19
21
|
# # rubocop:disable
|
|
20
22
|
#
|
|
23
|
+
# # good
|
|
24
|
+
# # rubocop:disable all
|
|
25
|
+
#
|
|
21
26
|
# # bad
|
|
22
27
|
# # rubocop:disable Layout/LineLength # rubocop:disable Style/Encoding
|
|
23
28
|
#
|
|
29
|
+
# # good
|
|
30
|
+
# # rubocop:disable Layout/LineLength
|
|
31
|
+
# # rubocop:disable Style/Encoding
|
|
32
|
+
#
|
|
24
33
|
# # bad
|
|
25
34
|
# # rubocop:wrongmode Layout/LineLength
|
|
26
35
|
#
|
|
27
36
|
# # good
|
|
28
37
|
# # rubocop:disable Layout/LineLength
|
|
29
38
|
#
|
|
30
|
-
# #
|
|
31
|
-
# # rubocop:disable Layout/LineLength
|
|
32
|
-
#
|
|
33
|
-
# # good
|
|
34
|
-
# # rubocop:disable all
|
|
39
|
+
# # bad
|
|
40
|
+
# # rubocop:disable Layout/LineLength comment
|
|
35
41
|
#
|
|
36
42
|
# # good
|
|
37
|
-
# # rubocop:disable Layout/LineLength --
|
|
43
|
+
# # rubocop:disable Layout/LineLength -- comment
|
|
38
44
|
#
|
|
39
45
|
class CopDirectiveSyntax < Base
|
|
40
46
|
COMMON_MSG = 'Malformed directive comment detected.'
|
|
41
47
|
|
|
42
48
|
MISSING_MODE_NAME_MSG = 'The mode name is missing.'
|
|
43
|
-
INVALID_MODE_NAME_MSG = 'The mode name must be one of `enable`, `disable`, or `
|
|
49
|
+
INVALID_MODE_NAME_MSG = 'The mode name must be one of `enable`, `disable`, `todo`, `push`, or `pop`.' # rubocop:disable Layout/LineLength
|
|
44
50
|
MISSING_COP_NAME_MSG = 'The cop name is missing.'
|
|
45
51
|
MALFORMED_COP_NAMES_MSG = 'Cop names must be separated by commas. ' \
|
|
46
52
|
'Comment in the directive must start with `--`.'
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Lint
|
|
6
|
+
# Checks unexpected overrides of the `Data` built-in methods
|
|
7
|
+
# via `Data.define`.
|
|
8
|
+
#
|
|
9
|
+
# @example
|
|
10
|
+
# # bad
|
|
11
|
+
# Bad = Data.define(:members, :clone, :to_s)
|
|
12
|
+
# b = Bad.new(members: [], clone: true, to_s: 'bad')
|
|
13
|
+
# b.members #=> [] (overriding `Data#members`)
|
|
14
|
+
# b.clone #=> true (overriding `Object#clone`)
|
|
15
|
+
# b.to_s #=> "bad" (overriding `Data#to_s`)
|
|
16
|
+
#
|
|
17
|
+
# # good
|
|
18
|
+
# Good = Data.define(:id, :name)
|
|
19
|
+
# g = Good.new(id: 1, name: "foo")
|
|
20
|
+
# g.members #=> [:id, :name]
|
|
21
|
+
# g.clone #=> #<data Good id=1, name="foo">
|
|
22
|
+
#
|
|
23
|
+
class DataDefineOverride < Base
|
|
24
|
+
MSG = '`%<member_name>s` member overrides `Data#%<method_name>s` and it may be unexpected.'
|
|
25
|
+
RESTRICT_ON_SEND = %i[define].freeze
|
|
26
|
+
|
|
27
|
+
# This is based on `Data.define.instance_methods.sort` in Ruby 4.0.0.
|
|
28
|
+
DATA_METHOD_NAMES = %i[
|
|
29
|
+
! != !~ <=> == === __id__ __send__ class clone deconstruct deconstruct_keys
|
|
30
|
+
define_singleton_method display dup enum_for eql? equal? extend freeze frozen? hash
|
|
31
|
+
inspect instance_eval instance_exec instance_of? instance_variable_defined?
|
|
32
|
+
instance_variable_get instance_variable_set instance_variables is_a? itself kind_of?
|
|
33
|
+
members method methods nil? object_id private_methods protected_methods
|
|
34
|
+
public_method public_methods public_send remove_instance_variable respond_to? send
|
|
35
|
+
singleton_class singleton_method singleton_methods tap then to_enum to_h to_s with
|
|
36
|
+
yield_self
|
|
37
|
+
].freeze
|
|
38
|
+
MEMBER_NAME_TYPES = %i[sym str].freeze
|
|
39
|
+
|
|
40
|
+
# @!method data_define(node)
|
|
41
|
+
def_node_matcher :data_define, <<~PATTERN
|
|
42
|
+
(send
|
|
43
|
+
(const {nil? cbase} :Data) :define ...)
|
|
44
|
+
PATTERN
|
|
45
|
+
|
|
46
|
+
def on_send(node)
|
|
47
|
+
return unless data_define(node)
|
|
48
|
+
|
|
49
|
+
node.arguments.each do |arg|
|
|
50
|
+
next unless MEMBER_NAME_TYPES.include?(arg.type)
|
|
51
|
+
|
|
52
|
+
member_name = arg.value
|
|
53
|
+
|
|
54
|
+
next unless DATA_METHOD_NAMES.include?(member_name.to_sym)
|
|
55
|
+
|
|
56
|
+
message = format(MSG, member_name: member_name.inspect, method_name: member_name.to_s)
|
|
57
|
+
add_offense(arg, message: message)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -73,7 +73,6 @@ module RuboCop
|
|
|
73
73
|
# require 'my_debugger/start'
|
|
74
74
|
class Debugger < Base
|
|
75
75
|
MSG = 'Remove debugger entry point `%<source>s`.'
|
|
76
|
-
BLOCK_TYPES = %i[block numblock itblock kwbegin].freeze
|
|
77
76
|
|
|
78
77
|
def on_send(node)
|
|
79
78
|
return if assumed_usage_context?(node)
|
|
@@ -102,8 +101,6 @@ module RuboCop
|
|
|
102
101
|
end
|
|
103
102
|
|
|
104
103
|
def debugger_method?(send_node)
|
|
105
|
-
return false if send_node.parent&.send_type? && send_node.parent.receiver == send_node
|
|
106
|
-
|
|
107
104
|
debugger_methods.include?(chained_method_name(send_node))
|
|
108
105
|
end
|
|
109
106
|
|
|
@@ -14,7 +14,7 @@ module RuboCop
|
|
|
14
14
|
# Alternative: 'alternative_value'
|
|
15
15
|
# DeprecatedVersion: 'deprecated_version'
|
|
16
16
|
#
|
|
17
|
-
# By default, `NIL`, `TRUE`, `FALSE`, `Net::HTTPServerException
|
|
17
|
+
# By default, `NIL`, `TRUE`, `FALSE`, `Net::HTTPServerException`, `Random::DEFAULT`,
|
|
18
18
|
# `Struct::Group`, and `Struct::Passwd` are configured.
|
|
19
19
|
#
|
|
20
20
|
# @example
|
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
|
49
49
|
# Maybe further investigation of RuboCop AST will lead to an essential solution.
|
|
50
50
|
return unless node.loc
|
|
51
51
|
|
|
52
|
-
constant = node.
|
|
52
|
+
constant = node.source.delete_prefix('::')
|
|
53
53
|
return unless (deprecated_constant = deprecated_constants[constant])
|
|
54
54
|
|
|
55
55
|
alternative = deprecated_constant['Alternative']
|
|
@@ -63,12 +63,6 @@ module RuboCop
|
|
|
63
63
|
|
|
64
64
|
private
|
|
65
65
|
|
|
66
|
-
def constant_name(node, nested_constant_name)
|
|
67
|
-
return nested_constant_name.to_s unless node.namespace.const_type?
|
|
68
|
-
|
|
69
|
-
constant_name(node.namespace, "#{node.namespace.short_name}::#{nested_constant_name}")
|
|
70
|
-
end
|
|
71
|
-
|
|
72
66
|
def message(good, bad, deprecated_version)
|
|
73
67
|
deprecated_message = ", deprecated since Ruby #{deprecated_version}" if deprecated_version
|
|
74
68
|
|
|
@@ -118,8 +118,11 @@ module RuboCop
|
|
|
118
118
|
|
|
119
119
|
def replacement_args(node)
|
|
120
120
|
algorithm_constant, = algorithm_const(node)
|
|
121
|
-
|
|
121
|
+
if algorithm_constant.source == 'OpenSSL::Cipher::Cipher'
|
|
122
|
+
return node.first_argument.source
|
|
123
|
+
end
|
|
122
124
|
|
|
125
|
+
algorithm_name = algorithm_name(algorithm_constant)
|
|
123
126
|
if openssl_class(algorithm_constant) == 'OpenSSL::Cipher'
|
|
124
127
|
build_cipher_arguments(node, algorithm_name, node.arguments.empty?)
|
|
125
128
|
else
|
|
@@ -25,17 +25,17 @@ module RuboCop
|
|
|
25
25
|
#
|
|
26
26
|
# # bad - repeated alternate patterns with the same conditions don't depend on the order
|
|
27
27
|
# case x
|
|
28
|
-
# in
|
|
28
|
+
# in 0 | 1
|
|
29
29
|
# first_method
|
|
30
|
-
# in
|
|
30
|
+
# in 1 | 0
|
|
31
31
|
# second_method
|
|
32
32
|
# end
|
|
33
33
|
#
|
|
34
34
|
# # good
|
|
35
35
|
# case x
|
|
36
|
-
# in
|
|
36
|
+
# in 0 | 1
|
|
37
37
|
# first_method
|
|
38
|
-
# in
|
|
38
|
+
# in 2 | 3
|
|
39
39
|
# second_method
|
|
40
40
|
# end
|
|
41
41
|
#
|