rubocop 1.84.2 → 1.88.1
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/config/default.yml +183 -87
- data/config/obsoletion.yml +26 -1
- data/lib/rubocop/cache_config.rb +1 -1
- data/lib/rubocop/cli/command/auto_generate_config.rb +34 -2
- data/lib/rubocop/cli/command/list_enabled_cops_for.rb +40 -0
- 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 +9 -7
- data/lib/rubocop/comment_config.rb +12 -15
- data/lib/rubocop/config.rb +14 -10
- data/lib/rubocop/config_finder.rb +1 -1
- data/lib/rubocop/config_loader.rb +17 -2
- data/lib/rubocop/config_loader_resolver.rb +13 -4
- data/lib/rubocop/config_obsoletion/extracted_cop.rb +4 -2
- data/lib/rubocop/config_store.rb +2 -2
- data/lib/rubocop/config_validator.rb +1 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +2 -1
- data/lib/rubocop/cop/base.rb +25 -4
- data/lib/rubocop/cop/bundler/gem_comment.rb +5 -3
- data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +7 -1
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +1 -5
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +8 -1
- 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/development_dependencies.rb +1 -1
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/require_mfa.rb +9 -6
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +3 -3
- data/lib/rubocop/cop/internal_affairs/itblock_handler.rb +69 -0
- data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +5 -3
- 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 +58 -4
- data/lib/rubocop/cop/layout/class_structure.rb +8 -4
- data/lib/rubocop/cop/layout/condition_position.rb +13 -3
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/empty_comment.rb +8 -10
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +23 -7
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +15 -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 +8 -5
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +20 -15
- data/lib/rubocop/cop/layout/hash_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +40 -0
- data/lib/rubocop/cop/layout/line_length.rb +5 -3
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +9 -2
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +53 -3
- 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/space_around_block_parameters.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +3 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +6 -2
- data/lib/rubocop/cop/layout/space_before_brackets.rb +1 -1
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -0
- 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/assignment_in_condition.rb +13 -1
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +1 -3
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +1 -1
- 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/data_define_override.rb +63 -0
- data/lib/rubocop/cop/lint/debugger.rb +0 -1
- data/lib/rubocop/cop/lint/deprecated_constants.rb +2 -8
- data/lib/rubocop/cop/lint/duplicate_methods.rb +55 -8
- 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_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 +1 -0
- 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_assignment_in_condition.rb +11 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +8 -11
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +5 -5
- 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 +16 -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 +4 -1
- 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_safe_navigation.rb +36 -12
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +4 -0
- 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_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 +24 -1
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -1
- 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/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 +35 -2
- 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 +36 -10
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +2 -2
- 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/useless_assignment.rb +14 -14
- 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_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 +35 -9
- data/lib/rubocop/cop/lint/void.rb +32 -12
- 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 +2 -2
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +38 -7
- 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 +1 -1
- data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +2 -2
- data/lib/rubocop/cop/mixin/configurable_max.rb +6 -5
- data/lib/rubocop/cop/mixin/hash_subset.rb +8 -0
- data/lib/rubocop/cop/mixin/hash_transform_method/autocorrection.rb +63 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +14 -60
- data/lib/rubocop/cop/mixin/project_index_help.rb +48 -0
- 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/file_name.rb +4 -3
- data/lib/rubocop/cop/naming/inclusive_language.rb +8 -2
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +10 -1
- data/lib/rubocop/cop/naming/predicate_method.rb +2 -2
- data/lib/rubocop/cop/naming/predicate_prefix.rb +1 -1
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -4
- data/lib/rubocop/cop/offense.rb +8 -0
- 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 +2 -2
- data/lib/rubocop/cop/security/marshal_load.rb +1 -1
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +14 -2
- data/lib/rubocop/cop/style/accessor_grouping.rb +15 -3
- 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 +4 -0
- data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +3 -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 +3 -1
- data/lib/rubocop/cop/style/begin_block.rb +3 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +37 -31
- data/lib/rubocop/cop/style/case_equality.rb +18 -2
- data/lib/rubocop/cop/style/character_literal.rb +2 -2
- data/lib/rubocop/cop/style/class_and_module_children.rb +18 -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 +6 -5
- data/lib/rubocop/cop/style/constant_visibility.rb +4 -1
- data/lib/rubocop/cop/style/copyright.rb +22 -11
- data/lib/rubocop/cop/style/data_inheritance.rb +4 -0
- 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/dir_empty.rb +4 -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/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_case_condition.rb +12 -2
- data/lib/rubocop/cop/style/empty_class_definition.rb +51 -21
- data/lib/rubocop/cop/style/empty_heredoc.rb +4 -0
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
- data/lib/rubocop/cop/style/empty_literal.rb +7 -2
- data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +30 -20
- 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 +8 -3
- data/lib/rubocop/cop/style/env_home.rb +4 -0
- data/lib/rubocop/cop/style/even_odd.rb +11 -1
- data/lib/rubocop/cop/style/exact_regexp_match.rb +8 -1
- data/lib/rubocop/cop/style/fetch_env_var.rb +1 -1
- data/lib/rubocop/cop/style/file_null.rb +4 -2
- 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/for.rb +3 -0
- data/lib/rubocop/cop/style/format_string.rb +17 -4
- data/lib/rubocop/cop/style/format_string_token.rb +29 -2
- data/lib/rubocop/cop/style/global_vars.rb +5 -2
- data/lib/rubocop/cop/style/guard_clause.rb +9 -6
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +21 -5
- data/lib/rubocop/cop/style/hash_conversion.rb +1 -1
- data/lib/rubocop/cop/style/hash_lookup_method.rb +19 -7
- data/lib/rubocop/cop/style/hash_slice.rb +16 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +2 -0
- 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 +15 -4
- data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -6
- data/lib/rubocop/cop/style/inline_comment.rb +5 -2
- data/lib/rubocop/cop/style/ip_addresses.rb +1 -2
- data/lib/rubocop/cop/style/keyword_arguments_merging.rb +4 -0
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +7 -3
- data/lib/rubocop/cop/style/lambda.rb +7 -1
- data/lib/rubocop/cop/style/magic_comment_format.rb +3 -3
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +11 -0
- data/lib/rubocop/cop/style/map_into_array.rb +1 -1
- data/lib/rubocop/cop/style/map_join.rb +123 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +5 -3
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +6 -2
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/min_max_comparison.rb +4 -1
- data/lib/rubocop/cop/style/module_member_existence_check.rb +7 -14
- data/lib/rubocop/cop/style/multiline_if_then.rb +4 -2
- data/lib/rubocop/cop/style/multiline_memoization.rb +7 -1
- data/lib/rubocop/cop/style/multiline_method_signature.rb +11 -4
- data/lib/rubocop/cop/style/mutable_constant.rb +106 -12
- data/lib/rubocop/cop/style/nil_comparison.rb +2 -3
- data/lib/rubocop/cop/style/nil_lambda.rb +9 -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/numeric_predicate.rb +1 -1
- data/lib/rubocop/cop/style/one_class_per_file.rb +115 -0
- data/lib/rubocop/cop/style/one_line_conditional.rb +4 -3
- data/lib/rubocop/cop/style/open_struct_use.rb +1 -1
- data/lib/rubocop/cop/style/option_hash.rb +1 -1
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -0
- data/lib/rubocop/cop/style/parallel_assignment.rb +23 -3
- data/lib/rubocop/cop/style/partition_instead_of_double_select.rb +270 -0
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +4 -0
- data/lib/rubocop/cop/style/perl_backrefs.rb +5 -3
- data/lib/rubocop/cop/style/predicate_with_kind.rb +84 -0
- 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_array_constructor.rb +2 -2
- data/lib/rubocop/cop/style/redundant_begin.rb +3 -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 +6 -0
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -1
- data/lib/rubocop/cop/style/redundant_filter_chain.rb +1 -1
- data/lib/rubocop/cop/style/redundant_format.rb +29 -0
- data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +26 -10
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +27 -3
- data/lib/rubocop/cop/style/redundant_min_max_by.rb +93 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +25 -22
- data/lib/rubocop/cop/style/redundant_percent_q.rb +4 -1
- data/lib/rubocop/cop/style/redundant_regexp_constructor.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -4
- data/lib/rubocop/cop/style/redundant_return.rb +3 -1
- data/lib/rubocop/cop/style/redundant_self.rb +11 -2
- data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +0 -5
- data/lib/rubocop/cop/style/redundant_struct_keyword_init.rb +133 -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/safe_navigation.rb +7 -7
- 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 +22 -5
- data/lib/rubocop/cop/style/single_line_block_params.rb +2 -2
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +18 -5
- data/lib/rubocop/cop/style/single_line_methods.rb +3 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +4 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +6 -1
- data/lib/rubocop/cop/style/string_hash_keys.rb +1 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +13 -0
- 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/ternary_parentheses.rb +11 -0
- data/lib/rubocop/cop/style/top_level_method_definition.rb +2 -2
- 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 +7 -8
- 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 +86 -35
- data/lib/rubocop/cop/variable_force/branch.rb +2 -2
- data/lib/rubocop/directive_comment.rb +2 -1
- data/lib/rubocop/file_patterns.rb +9 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +19 -9
- data/lib/rubocop/formatter/formatter_set.rb +1 -1
- data/lib/rubocop/formatter/junit_formatter.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +0 -2
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -1
- data/lib/rubocop/formatter.rb +22 -21
- data/lib/rubocop/lsp/diagnostic.rb +1 -0
- data/lib/rubocop/lsp/routes.rb +10 -3
- data/lib/rubocop/lsp/runtime.rb +1 -2
- 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/result_cache.rb +22 -10
- data/lib/rubocop/rspec/cop_helper.rb +8 -0
- data/lib/rubocop/rspec/shared_contexts.rb +32 -2
- data/lib/rubocop/runner.rb +126 -53
- data/lib/rubocop/server/cache.rb +5 -7
- data/lib/rubocop/server/core.rb +8 -0
- data/lib/rubocop/target_finder.rb +14 -7
- data/lib/rubocop/target_ruby.rb +18 -12
- data/lib/rubocop/version.rb +21 -3
- data/lib/rubocop.rb +22 -96
- metadata +27 -5
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# Lint/RedundantCopDisableDirective needs to be disabled so as
|
|
4
|
+
# to be able to provide examples of rubocop:disable comments.
|
|
5
|
+
# rubocop:disable Lint/RedundantCopDisableDirective
|
|
3
6
|
module RuboCop
|
|
4
7
|
module Cop
|
|
5
8
|
module Migration
|
|
6
|
-
#
|
|
9
|
+
# Checks that cop names in rubocop:disable comments are given with
|
|
7
10
|
# department name.
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# # bad
|
|
14
|
+
# # rubocop:disable AbcSize
|
|
15
|
+
#
|
|
16
|
+
# # good
|
|
17
|
+
# # rubocop:disable Metrics/AbcSize
|
|
8
18
|
class DepartmentName < Base
|
|
9
19
|
include RangeHelp
|
|
10
20
|
extend AutoCorrector
|
|
@@ -79,3 +89,4 @@ module RuboCop
|
|
|
79
89
|
end
|
|
80
90
|
end
|
|
81
91
|
end
|
|
92
|
+
# rubocop:enable Lint/RedundantCopDisableDirective
|
|
@@ -38,9 +38,9 @@ module RuboCop
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def safe_to_split?(node)
|
|
41
|
-
node.each_descendant(:if, :case, :kwbegin, :any_def).none? &&
|
|
41
|
+
node.each_descendant(:if, :case, :kwbegin, :any_def, :rescue, :ensure).none? &&
|
|
42
42
|
node.each_descendant(:dstr, :str).none? { |n| n.heredoc? || n.value.include?("\n") } &&
|
|
43
|
-
node.each_descendant(:begin, :sym).none?
|
|
43
|
+
node.each_descendant(:begin, :sym).none?(&:multiline?)
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
end
|
|
@@ -13,11 +13,12 @@ module RuboCop
|
|
|
13
13
|
`max=` is deprecated. Use `exclude_limit <ParameterName>` instead.
|
|
14
14
|
WARNING
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
cop_dir = RuboCop::ExcludeLimit.cop_dir_for(self.class.badge.to_s)
|
|
17
|
+
return unless cop_dir
|
|
18
|
+
|
|
19
|
+
cop_dir.mkpath
|
|
20
|
+
filepath = cop_dir.join(max_parameter_name)
|
|
21
|
+
filepath.write("#{value}\n", mode: 'a')
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
def max_parameter_name
|
|
@@ -182,10 +182,18 @@ module RuboCop
|
|
|
182
182
|
return ":\"#{value.source}\"" if value.dsym_type?
|
|
183
183
|
return "\"#{value.source}\"" if value.dstr_type?
|
|
184
184
|
return ":#{value.source}" if value.sym_type?
|
|
185
|
+
# The element of a `%w` array can contain characters that are special
|
|
186
|
+
# inside a single-quoted string (e.g. a `'`), so escape them rather than
|
|
187
|
+
# wrapping the raw source.
|
|
188
|
+
return to_single_quoted(value.value) if value.str_type?
|
|
185
189
|
|
|
186
190
|
"'#{value.source}'"
|
|
187
191
|
end
|
|
188
192
|
|
|
193
|
+
def to_single_quoted(string)
|
|
194
|
+
"'#{string.gsub(/['\\]/) { |character| "\\#{character}" }}'"
|
|
195
|
+
end
|
|
196
|
+
|
|
189
197
|
def except_key(node)
|
|
190
198
|
key_arg = node.argument_list.first.source
|
|
191
199
|
body, = extract_body_if_negated(node.body)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module HashTransformMethod
|
|
6
|
+
# Internal helper class to hold autocorrect data
|
|
7
|
+
Autocorrection = Struct.new(:match, :block_node, :leading, :trailing) do
|
|
8
|
+
def self.from_each_with_object(node, match)
|
|
9
|
+
new(match, node, 0, 0)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.from_hash_brackets_map(node, match)
|
|
13
|
+
new(match, node.children.last, 'Hash['.length, ']'.length)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.from_map_to_h(node, match)
|
|
17
|
+
if node.parent&.block_type? && node.parent.send_node == node
|
|
18
|
+
strip_trailing_chars = 0
|
|
19
|
+
else
|
|
20
|
+
map_range = node.children.first.source_range
|
|
21
|
+
node_range = node.source_range
|
|
22
|
+
strip_trailing_chars = node_range.end_pos - map_range.end_pos
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
new(match, node.children.first, 0, strip_trailing_chars)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.from_to_h(node, match)
|
|
29
|
+
new(match, node, 0, 0)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def strip_prefix_and_suffix(node, corrector)
|
|
33
|
+
expression = node.source_range
|
|
34
|
+
corrector.remove_leading(expression, leading)
|
|
35
|
+
corrector.remove_trailing(expression, trailing)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def set_new_method_name(new_method_name, corrector)
|
|
39
|
+
range = block_node.send_node.loc.selector
|
|
40
|
+
if (send_end = block_node.send_node.loc.end)
|
|
41
|
+
# If there are arguments (only true in the `each_with_object`
|
|
42
|
+
# case)
|
|
43
|
+
range = range.begin.join(send_end)
|
|
44
|
+
end
|
|
45
|
+
corrector.replace(range, new_method_name)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def set_new_arg_name(transformed_argname, corrector)
|
|
49
|
+
corrector.replace(block_node.arguments, "|#{transformed_argname}|")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def set_new_body_expression(transforming_body_expr, corrector)
|
|
53
|
+
body_source = transforming_body_expr.source
|
|
54
|
+
if transforming_body_expr.hash_type? && !transforming_body_expr.braces?
|
|
55
|
+
body_source = "{ #{body_source} }"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
corrector.replace(block_node.body, body_source)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'hash_transform_method/autocorrection'
|
|
4
|
+
|
|
3
5
|
module RuboCop
|
|
4
6
|
module Cop
|
|
5
7
|
# Common functionality for Style/HashTransformKeys and
|
|
@@ -27,68 +29,16 @@ module RuboCop
|
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
|
|
30
|
-
#
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
new(match, node.children.last, 'Hash['.length, ']'.length)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def self.from_map_to_h(node, match)
|
|
41
|
-
if node.parent&.block_type? && node.parent.send_node == node
|
|
42
|
-
strip_trailing_chars = 0
|
|
43
|
-
else
|
|
44
|
-
map_range = node.children.first.source_range
|
|
45
|
-
node_range = node.source_range
|
|
46
|
-
strip_trailing_chars = node_range.end_pos - map_range.end_pos
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
new(match, node.children.first, 0, strip_trailing_chars)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def self.from_to_h(node, match)
|
|
53
|
-
new(match, node, 0, 0)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def strip_prefix_and_suffix(node, corrector)
|
|
57
|
-
expression = node.source_range
|
|
58
|
-
corrector.remove_leading(expression, leading)
|
|
59
|
-
corrector.remove_trailing(expression, trailing)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def set_new_method_name(new_method_name, corrector)
|
|
63
|
-
range = block_node.send_node.loc.selector
|
|
64
|
-
if (send_end = block_node.send_node.loc.end)
|
|
65
|
-
# If there are arguments (only true in the `each_with_object`
|
|
66
|
-
# case)
|
|
67
|
-
range = range.begin.join(send_end)
|
|
68
|
-
end
|
|
69
|
-
corrector.replace(range, new_method_name)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def set_new_arg_name(transformed_argname, corrector)
|
|
73
|
-
corrector.replace(block_node.arguments, "|#{transformed_argname}|")
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def set_new_body_expression(transforming_body_expr, corrector)
|
|
77
|
-
body_source = transforming_body_expr.source
|
|
78
|
-
if transforming_body_expr.hash_type? && !transforming_body_expr.braces?
|
|
79
|
-
body_source = "{ #{body_source} }"
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
corrector.replace(block_node.body, body_source)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# @!method array_receiver?(node)
|
|
87
|
-
def_node_matcher :array_receiver?, <<~PATTERN
|
|
88
|
-
{(array ...) (send _ :each_with_index) (send _ :with_index _ ?) (send _ :zip ...)}
|
|
32
|
+
# @!method hash_receiver?(node)
|
|
33
|
+
def_node_matcher :hash_receiver?, <<~PATTERN
|
|
34
|
+
{(hash ...)
|
|
35
|
+
(send _ {:to_h :to_hash :merge :merge! :update :invert :except :tally} ...)
|
|
36
|
+
(block (send _ {:group_by :to_h :tally :transform_keys :transform_keys!
|
|
37
|
+
:transform_values :transform_values!}) ...)
|
|
38
|
+
(block (send _ :each_with_object (hash)) ...)}
|
|
89
39
|
PATTERN
|
|
90
40
|
|
|
91
|
-
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
|
|
41
|
+
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler
|
|
92
42
|
on_bad_each_with_object(node) do |*match|
|
|
93
43
|
handle_possible_offense(node, match, 'each_with_object')
|
|
94
44
|
end
|
|
@@ -144,6 +94,10 @@ module RuboCop
|
|
|
144
94
|
|
|
145
95
|
return unless captures.use_transformed_argname?
|
|
146
96
|
|
|
97
|
+
# A splat transforming expression (e.g. `[k, *v]`) can't be used as a
|
|
98
|
+
# standalone block return value, so the rewrite would produce invalid Ruby.
|
|
99
|
+
return if captures.transforming_body_expr.splat_type?
|
|
100
|
+
|
|
147
101
|
message = "Prefer `#{new_method_name}` over `#{match_desc}`."
|
|
148
102
|
add_offense(node, message: message) do |corrector|
|
|
149
103
|
correction = prepare_correction(node)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
# Common helpers for cops that consult the project-wide static-analysis index
|
|
6
|
+
# via `Cop::Base#project_index`.
|
|
7
|
+
#
|
|
8
|
+
# Mixed-in cops gain the `external_dependency_checksum` override that invalidates
|
|
9
|
+
# the `ResultCache` whenever the indexed project files change on disk.
|
|
10
|
+
# To run index-backed analysis, cops should simply check whether `project_index` is non-nil;
|
|
11
|
+
# the runner only exposes a non-nil index when the user opted in via `AllCops/UseProjectIndex`
|
|
12
|
+
# and the underlying gem is available.
|
|
13
|
+
module ProjectIndexHelp
|
|
14
|
+
BUILTIN_DOCUMENT_URI = 'rubydex:built-in'
|
|
15
|
+
FILE_URI_PREFIX = 'file://'
|
|
16
|
+
# Matches the spurious leading slash before a Windows drive letter that
|
|
17
|
+
# remains after stripping `file://` from a `file:///C:/...` URI.
|
|
18
|
+
WINDOWS_DRIVE_PREFIX = %r{\A/(?=[A-Za-z]:[/\\])}.freeze
|
|
19
|
+
|
|
20
|
+
def external_dependency_checksum
|
|
21
|
+
return nil unless project_index
|
|
22
|
+
|
|
23
|
+
@external_dependency_checksum ||= Digest::SHA1.hexdigest(
|
|
24
|
+
project_index_signature.join("\n")
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def project_index_signature
|
|
31
|
+
project_index.documents.filter_map do |doc|
|
|
32
|
+
uri = doc.uri
|
|
33
|
+
next if uri == BUILTIN_DOCUMENT_URI
|
|
34
|
+
|
|
35
|
+
path = uri.delete_prefix(FILE_URI_PREFIX).sub(WINDOWS_DRIVE_PREFIX, '')
|
|
36
|
+
mtime, size = begin
|
|
37
|
+
stat = File.stat(path)
|
|
38
|
+
[stat.mtime.to_f, stat.size]
|
|
39
|
+
rescue StandardError
|
|
40
|
+
[0, 0]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
"#{path}:#{mtime}:#{size}"
|
|
44
|
+
end.sort
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop # rubocop:disable Style/Documentation
|
|
5
|
+
# Autoloads mixin modules included by cops. Mixins are autoloaded to reduce the number of
|
|
6
|
+
# requires because they're used only when the relevant cop class is loaded.
|
|
7
|
+
|
|
8
|
+
autoload :ArrayMinSize, 'rubocop/cop/mixin/array_min_size'
|
|
9
|
+
autoload :ArraySyntax, 'rubocop/cop/mixin/array_syntax'
|
|
10
|
+
autoload :Alignment, 'rubocop/cop/mixin/alignment'
|
|
11
|
+
autoload :AllowedIdentifiers, 'rubocop/cop/mixin/allowed_identifiers'
|
|
12
|
+
autoload :AllowedMethods, 'rubocop/cop/mixin/allowed_methods'
|
|
13
|
+
autoload :AllowedPattern, 'rubocop/cop/mixin/allowed_pattern'
|
|
14
|
+
autoload :AllowedReceivers, 'rubocop/cop/mixin/allowed_receivers'
|
|
15
|
+
autoload :ForbiddenIdentifiers, 'rubocop/cop/mixin/forbidden_identifiers'
|
|
16
|
+
autoload :ForbiddenPattern, 'rubocop/cop/mixin/forbidden_pattern'
|
|
17
|
+
autoload :AutoCorrector, 'rubocop/cop/mixin/auto_corrector' # rubocop:todo Naming/InclusiveLanguage
|
|
18
|
+
autoload :CheckAssignment, 'rubocop/cop/mixin/check_assignment'
|
|
19
|
+
autoload :CheckLineBreakable, 'rubocop/cop/mixin/check_line_breakable'
|
|
20
|
+
autoload :CheckSingleLineSuitability, 'rubocop/cop/mixin/check_single_line_suitability'
|
|
21
|
+
autoload :ConfigurableMax, 'rubocop/cop/mixin/configurable_max'
|
|
22
|
+
autoload :CodeLength, 'rubocop/cop/mixin/code_length'
|
|
23
|
+
autoload :ConfigurableEnforcedStyle, 'rubocop/cop/mixin/configurable_enforced_style'
|
|
24
|
+
autoload :ConfigurableFormatting, 'rubocop/cop/mixin/configurable_formatting'
|
|
25
|
+
autoload :ConfigurableNaming, 'rubocop/cop/mixin/configurable_naming'
|
|
26
|
+
autoload :ConfigurableNumbering, 'rubocop/cop/mixin/configurable_numbering'
|
|
27
|
+
autoload :DigHelp, 'rubocop/cop/mixin/dig_help'
|
|
28
|
+
autoload :DocumentationComment, 'rubocop/cop/mixin/documentation_comment'
|
|
29
|
+
autoload :Duplication, 'rubocop/cop/mixin/duplication'
|
|
30
|
+
autoload :RangeHelp, 'rubocop/cop/mixin/range_help'
|
|
31
|
+
autoload :ProjectIndexHelp, 'rubocop/cop/mixin/project_index_help'
|
|
32
|
+
autoload :AnnotationComment, 'rubocop/cop/mixin/annotation_comment'
|
|
33
|
+
autoload :EmptyParameter, 'rubocop/cop/mixin/empty_parameter'
|
|
34
|
+
autoload :EndKeywordAlignment, 'rubocop/cop/mixin/end_keyword_alignment'
|
|
35
|
+
autoload :EndlessMethodRewriter, 'rubocop/cop/mixin/endless_method_rewriter'
|
|
36
|
+
autoload :EnforceSuperclass, 'rubocop/cop/mixin/enforce_superclass'
|
|
37
|
+
autoload :FirstElementLineBreak, 'rubocop/cop/mixin/first_element_line_break'
|
|
38
|
+
autoload :FrozenStringLiteral, 'rubocop/cop/mixin/frozen_string_literal'
|
|
39
|
+
autoload :GemDeclaration, 'rubocop/cop/mixin/gem_declaration'
|
|
40
|
+
autoload :GemspecHelp, 'rubocop/cop/mixin/gemspec_help'
|
|
41
|
+
autoload :HashAlignmentStyles, 'rubocop/cop/mixin/hash_alignment_styles'
|
|
42
|
+
autoload :HashSubset, 'rubocop/cop/mixin/hash_subset'
|
|
43
|
+
autoload :HashTransformMethod, 'rubocop/cop/mixin/hash_transform_method'
|
|
44
|
+
autoload :IntegerNode, 'rubocop/cop/mixin/integer_node'
|
|
45
|
+
autoload :Interpolation, 'rubocop/cop/mixin/interpolation'
|
|
46
|
+
autoload :LineLengthHelp, 'rubocop/cop/mixin/line_length_help'
|
|
47
|
+
autoload :MatchRange, 'rubocop/cop/mixin/match_range'
|
|
48
|
+
autoload :HashShorthandSyntax, 'rubocop/cop/mixin/hash_shorthand_syntax'
|
|
49
|
+
autoload :MethodComplexity, 'rubocop/cop/mixin/method_complexity'
|
|
50
|
+
autoload :MethodPreference, 'rubocop/cop/mixin/method_preference'
|
|
51
|
+
autoload :MinBodyLength, 'rubocop/cop/mixin/min_body_length'
|
|
52
|
+
autoload :MinBranchesCount, 'rubocop/cop/mixin/min_branches_count'
|
|
53
|
+
autoload :MultilineElementIndentation, 'rubocop/cop/mixin/multiline_element_indentation'
|
|
54
|
+
autoload :MultilineElementLineBreaks, 'rubocop/cop/mixin/multiline_element_line_breaks'
|
|
55
|
+
autoload :MultilineExpressionIndentation, 'rubocop/cop/mixin/multiline_expression_indentation'
|
|
56
|
+
autoload :MultilineLiteralBraceLayout, 'rubocop/cop/mixin/multiline_literal_brace_layout'
|
|
57
|
+
autoload :NegativeConditional, 'rubocop/cop/mixin/negative_conditional'
|
|
58
|
+
autoload :Heredoc, 'rubocop/cop/mixin/heredoc'
|
|
59
|
+
autoload :NilMethods, 'rubocop/cop/mixin/nil_methods'
|
|
60
|
+
autoload :OnNormalIfUnless, 'rubocop/cop/mixin/on_normal_if_unless'
|
|
61
|
+
autoload :OrderedGemNode, 'rubocop/cop/mixin/ordered_gem_node'
|
|
62
|
+
autoload :Parentheses, 'rubocop/cop/mixin/parentheses'
|
|
63
|
+
autoload :PercentArray, 'rubocop/cop/mixin/percent_array'
|
|
64
|
+
autoload :PercentLiteral, 'rubocop/cop/mixin/percent_literal'
|
|
65
|
+
autoload :PrecedingFollowingAlignment, 'rubocop/cop/mixin/preceding_following_alignment'
|
|
66
|
+
autoload :PreferredDelimiters, 'rubocop/cop/mixin/preferred_delimiters'
|
|
67
|
+
autoload :RationalLiteral, 'rubocop/cop/mixin/rational_literal'
|
|
68
|
+
autoload :RequireLibrary, 'rubocop/cop/mixin/require_library'
|
|
69
|
+
autoload :RescueNode, 'rubocop/cop/mixin/rescue_node'
|
|
70
|
+
autoload :SafeAssignment, 'rubocop/cop/mixin/safe_assignment'
|
|
71
|
+
autoload :SpaceAfterPunctuation, 'rubocop/cop/mixin/space_after_punctuation'
|
|
72
|
+
autoload :SpaceBeforePunctuation, 'rubocop/cop/mixin/space_before_punctuation'
|
|
73
|
+
autoload :SurroundingSpace, 'rubocop/cop/mixin/surrounding_space'
|
|
74
|
+
autoload :StatementModifier, 'rubocop/cop/mixin/statement_modifier'
|
|
75
|
+
autoload :StringHelp, 'rubocop/cop/mixin/string_help'
|
|
76
|
+
autoload :StringLiteralsHelp, 'rubocop/cop/mixin/string_literals_help'
|
|
77
|
+
autoload :SymbolHelp, 'rubocop/cop/mixin/symbol_help'
|
|
78
|
+
autoload :TargetRubyVersion, 'rubocop/cop/mixin/target_ruby_version'
|
|
79
|
+
autoload :TrailingBody, 'rubocop/cop/mixin/trailing_body'
|
|
80
|
+
autoload :TrailingComma, 'rubocop/cop/mixin/trailing_comma'
|
|
81
|
+
autoload :UncommunicativeName, 'rubocop/cop/mixin/uncommunicative_name'
|
|
82
|
+
autoload :VisibilityHelp, 'rubocop/cop/mixin/visibility_help'
|
|
83
|
+
autoload :CommentsHelp, 'rubocop/cop/mixin/comments_help'
|
|
84
|
+
autoload :DefNode, 'rubocop/cop/mixin/def_node'
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -38,7 +38,7 @@ module RuboCop
|
|
|
38
38
|
class BlockParameterName < Base
|
|
39
39
|
include UncommunicativeName
|
|
40
40
|
|
|
41
|
-
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
|
|
41
|
+
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler
|
|
42
42
|
return unless node.arguments?
|
|
43
43
|
|
|
44
44
|
check(node, node.arguments)
|
|
@@ -203,9 +203,10 @@ module RuboCop
|
|
|
203
203
|
|
|
204
204
|
def match_acronym?(expected, name)
|
|
205
205
|
expected = expected.to_s
|
|
206
|
-
name = name.to_s
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
name = allowed_acronyms.reduce(name.to_s) do |result, acronym|
|
|
207
|
+
result.gsub(acronym, acronym.capitalize)
|
|
208
|
+
end
|
|
209
|
+
expected == name
|
|
209
210
|
end
|
|
210
211
|
|
|
211
212
|
def to_namespace(path) # rubocop:disable Metrics/AbcSize
|
|
@@ -91,6 +91,8 @@ module RuboCop
|
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
def on_new_investigation
|
|
94
|
+
return unless @flagged_terms_regex
|
|
95
|
+
|
|
94
96
|
investigate_filepath if cop_config['CheckFilepaths']
|
|
95
97
|
investigate_tokens
|
|
96
98
|
end
|
|
@@ -144,7 +146,7 @@ module RuboCop
|
|
|
144
146
|
def preprocess_flagged_terms
|
|
145
147
|
allowed_strings = []
|
|
146
148
|
flagged_term_strings = []
|
|
147
|
-
cop_config['FlaggedTerms'].each do |term, term_definition|
|
|
149
|
+
(cop_config['FlaggedTerms'] || {}).each do |term, term_definition|
|
|
148
150
|
next if term_definition.nil?
|
|
149
151
|
|
|
150
152
|
allowed_strings.concat(process_allowed_regex(term_definition['AllowedRegex']))
|
|
@@ -181,7 +183,11 @@ module RuboCop
|
|
|
181
183
|
end
|
|
182
184
|
|
|
183
185
|
def set_regexes(flagged_term_strings, allowed_strings)
|
|
184
|
-
|
|
186
|
+
# With no flagged terms an empty regex would match everything, so leave the
|
|
187
|
+
# regex nil and let `on_new_investigation` treat the cop as a no-op.
|
|
188
|
+
unless flagged_term_strings.empty?
|
|
189
|
+
@flagged_terms_regex = array_to_ignorecase_regex(flagged_term_strings)
|
|
190
|
+
end
|
|
185
191
|
@allowed_regex = array_to_ignorecase_regex(allowed_strings) unless allowed_strings.empty?
|
|
186
192
|
end
|
|
187
193
|
|
|
@@ -109,7 +109,7 @@ module RuboCop
|
|
|
109
109
|
# @_foo = calculate_expensive_thing
|
|
110
110
|
# end
|
|
111
111
|
#
|
|
112
|
-
# @example EnforcedStyleForLeadingUnderscores
|
|
112
|
+
# @example EnforcedStyleForLeadingUnderscores: optional
|
|
113
113
|
# # bad
|
|
114
114
|
# def foo
|
|
115
115
|
# @something ||= calculate_expensive_thing
|
|
@@ -174,6 +174,7 @@ module RuboCop
|
|
|
174
174
|
|
|
175
175
|
method_node, method_name = find_definition(node)
|
|
176
176
|
return unless method_node
|
|
177
|
+
return unless nameable_method?(method_name)
|
|
177
178
|
|
|
178
179
|
body = method_node.body
|
|
179
180
|
return unless body == node || body.children.last == node
|
|
@@ -209,6 +210,7 @@ module RuboCop
|
|
|
209
210
|
|
|
210
211
|
method_node, method_name = find_definition(node)
|
|
211
212
|
return false unless method_node
|
|
213
|
+
return false unless nameable_method?(method_name)
|
|
212
214
|
|
|
213
215
|
defined_memoized?(method_node.body, arg.name) do |defined_ivar, return_ivar, ivar_assign|
|
|
214
216
|
return false if matches?(method_name, ivar_assign)
|
|
@@ -250,6 +252,13 @@ module RuboCop
|
|
|
250
252
|
nil
|
|
251
253
|
end
|
|
252
254
|
|
|
255
|
+
# Operator and other non-word method names (e.g. `[]`, `+`, `<=>`) cannot form a
|
|
256
|
+
# valid instance variable name, so there is no matching ivar to enforce and a
|
|
257
|
+
# suggested correction like `@[]` would be invalid Ruby.
|
|
258
|
+
def nameable_method?(method_name)
|
|
259
|
+
/\A[a-zA-Z_]\w*\z/.match?(method_name.to_s.delete('!?='))
|
|
260
|
+
end
|
|
261
|
+
|
|
253
262
|
def matches?(method_name, ivar_assign)
|
|
254
263
|
return true if ivar_assign.nil? || INITIALIZE_METHODS.include?(method_name)
|
|
255
264
|
|
|
@@ -6,7 +6,7 @@ module RuboCop
|
|
|
6
6
|
# Checks that predicate methods end with `?` and non-predicate methods do not.
|
|
7
7
|
#
|
|
8
8
|
# The names of predicate methods (methods that return a boolean value) should end
|
|
9
|
-
# in a question mark. Methods that don't return a boolean
|
|
9
|
+
# in a question mark. Methods that don't return a boolean shouldn't
|
|
10
10
|
# end in a question mark.
|
|
11
11
|
#
|
|
12
12
|
# The cop assesses a predicate method as one that returns boolean values. Likewise,
|
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
|
22
22
|
# return values are detected.
|
|
23
23
|
#
|
|
24
24
|
# The cop also has `AllowedMethods` configuration in order to prevent the cop from
|
|
25
|
-
# registering an offense from a method name that does not
|
|
25
|
+
# registering an offense from a method name that does not conform to the naming
|
|
26
26
|
# guidelines. By default, `call` is allowed. The cop also has `AllowedPatterns`
|
|
27
27
|
# configuration to allow method names by regular expression.
|
|
28
28
|
#
|
|
@@ -17,7 +17,7 @@ module RuboCop
|
|
|
17
17
|
# they end with a `?`. These methods should be changed to remove the
|
|
18
18
|
# prefix.
|
|
19
19
|
#
|
|
20
|
-
# When `UseSorbetSigs` set to true (optional), the cop will only report
|
|
20
|
+
# When `UseSorbetSigs` is set to true (optional), the cop will only report
|
|
21
21
|
# offenses if the method has a Sorbet `sig` with a return type of
|
|
22
22
|
# `T::Boolean`. Dynamic methods are not supported with this configuration.
|
|
23
23
|
#
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
module Cop
|
|
5
5
|
module Naming
|
|
6
|
-
# Makes sure that rescued
|
|
6
|
+
# Makes sure that rescued exception variables are named as
|
|
7
7
|
# expected.
|
|
8
8
|
#
|
|
9
9
|
# The `PreferredName` config option takes a `String`. It represents
|
|
@@ -95,11 +95,14 @@ module RuboCop
|
|
|
95
95
|
|
|
96
96
|
def autocorrect(corrector, node, range, offending_name, preferred_name)
|
|
97
97
|
corrector.replace(range, preferred_name)
|
|
98
|
-
|
|
98
|
+
# Once the exception variable is reassigned, later references point to a
|
|
99
|
+
# different value, so stop correcting after the reassignment - both in the
|
|
100
|
+
# body and in the code following the `begin`/`rescue`.
|
|
101
|
+
return if correct_node(corrector, node.body, offending_name, preferred_name)
|
|
99
102
|
return unless (kwbegin_node = node.parent.each_ancestor(:kwbegin).first)
|
|
100
103
|
|
|
101
104
|
kwbegin_node.right_siblings.each do |child_node|
|
|
102
|
-
correct_node(corrector, child_node, offending_name, preferred_name)
|
|
105
|
+
break if correct_node(corrector, child_node, offending_name, preferred_name)
|
|
103
106
|
end
|
|
104
107
|
end
|
|
105
108
|
|
|
@@ -113,6 +116,8 @@ module RuboCop
|
|
|
113
116
|
end
|
|
114
117
|
end
|
|
115
118
|
|
|
119
|
+
# Returns the reassignment node once the exception variable is reassigned (a truthy
|
|
120
|
+
# signal to stop correcting later references), or `nil` when no reassignment is found.
|
|
116
121
|
# rubocop:disable Metrics/MethodLength
|
|
117
122
|
def correct_node(corrector, node, offending_name, preferred_name)
|
|
118
123
|
return unless node
|
|
@@ -131,9 +136,10 @@ module RuboCop
|
|
|
131
136
|
|
|
132
137
|
if child_node.type?(:masgn, :lvasgn)
|
|
133
138
|
correct_reassignment(corrector, child_node, offending_name, preferred_name)
|
|
134
|
-
|
|
139
|
+
return child_node
|
|
135
140
|
end
|
|
136
141
|
end
|
|
142
|
+
nil
|
|
137
143
|
end
|
|
138
144
|
# rubocop:enable Metrics/MethodLength
|
|
139
145
|
|
data/lib/rubocop/cop/offense.rb
CHANGED
|
@@ -98,6 +98,14 @@ module RuboCop
|
|
|
98
98
|
freeze
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
+
def marshal_dump
|
|
102
|
+
[@severity, @location, @message, @cop_name, @status]
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def marshal_load(array)
|
|
106
|
+
@severity, @location, @message, @cop_name, @status = array
|
|
107
|
+
end
|
|
108
|
+
|
|
101
109
|
# @api public
|
|
102
110
|
#
|
|
103
111
|
# @!attribute [r] correctable?
|