rubocop 1.79.2 → 1.87.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 +185 -20
- data/config/obsoletion.yml +9 -0
- data/exe/rubocop +1 -8
- data/lib/rubocop/cache_config.rb +29 -0
- data/lib/rubocop/cli/command/auto_generate_config.rb +30 -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 +8 -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/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/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_block_association.rb +1 -1
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +47 -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 -2
- data/lib/rubocop/cop/lint/deprecated_constants.rb +1 -1
- 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 +1 -1
- 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/erb_new_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/float_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/interpolation_check.rb +7 -2
- data/lib/rubocop/cop/lint/literal_as_condition.rb +5 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +18 -9
- 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 +4 -0
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +4 -2
- data/lib/rubocop/cop/lint/number_conversion.rb +6 -6
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +3 -13
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +23 -9
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +2 -11
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +4 -2
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +23 -6
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +8 -2
- data/lib/rubocop/cop/lint/redundant_type_conversion.rb +3 -3
- data/lib/rubocop/cop/lint/require_relative_self_path.rb +3 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -4
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +17 -0
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +7 -1
- data/lib/rubocop/cop/lint/self_assignment.rb +15 -6
- 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/struct_new_override.rb +17 -1
- data/lib/rubocop/cop/lint/syntax.rb +25 -1
- data/lib/rubocop/cop/lint/to_json.rb +12 -16
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -0
- data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +1 -1
- 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 +48 -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 +1 -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/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 +14 -2
- data/lib/rubocop/cop/style/and_or.rb +1 -0
- data/lib/rubocop/cop/style/arguments_forwarding.rb +25 -7
- data/lib/rubocop/cop/style/array_intersect.rb +46 -12
- data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -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 +27 -34
- data/lib/rubocop/cop/style/case_equality.rb +15 -13
- 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/collection_compact.rb +36 -16
- data/lib/rubocop/cop/style/colon_method_call.rb +3 -1
- data/lib/rubocop/cop/style/concat_array_literals.rb +2 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +8 -18
- data/lib/rubocop/cop/style/constant_visibility.rb +17 -12
- data/lib/rubocop/cop/style/copyright.rb +22 -11
- data/lib/rubocop/cop/style/date_time.rb +2 -2
- 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/file_open.rb +84 -0
- data/lib/rubocop/cop/style/file_write.rb +18 -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_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 +57 -17
- 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 +1 -1
- 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 +6 -2
- 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 +26 -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 +25 -7
- 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_modifier.rb +16 -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/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 +24 -7
- 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 +2 -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
|
@@ -254,8 +254,8 @@ module RuboCop
|
|
|
254
254
|
end
|
|
255
255
|
end
|
|
256
256
|
|
|
257
|
-
# Mix-in module for
|
|
258
|
-
module
|
|
257
|
+
# Mix-in module for operator control structures.
|
|
258
|
+
module Operator
|
|
259
259
|
def always_run?
|
|
260
260
|
left_body?
|
|
261
261
|
end
|
|
@@ -263,7 +263,15 @@ module RuboCop
|
|
|
263
263
|
|
|
264
264
|
# left_body && right_body
|
|
265
265
|
class And < Base
|
|
266
|
-
include
|
|
266
|
+
include Operator
|
|
267
|
+
|
|
268
|
+
define_predicate :left_body?, child_index: 0
|
|
269
|
+
define_predicate :right_body?, child_index: 1
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
# left_body &&= right_body
|
|
273
|
+
class AndAsgn < Base
|
|
274
|
+
include Operator
|
|
267
275
|
|
|
268
276
|
define_predicate :left_body?, child_index: 0
|
|
269
277
|
define_predicate :right_body?, child_index: 1
|
|
@@ -271,7 +279,23 @@ module RuboCop
|
|
|
271
279
|
|
|
272
280
|
# left_body || right_body
|
|
273
281
|
class Or < Base
|
|
274
|
-
include
|
|
282
|
+
include Operator
|
|
283
|
+
|
|
284
|
+
define_predicate :left_body?, child_index: 0
|
|
285
|
+
define_predicate :right_body?, child_index: 1
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
# left_body ||= right_body
|
|
289
|
+
class OrAsgn < Base
|
|
290
|
+
include Operator
|
|
291
|
+
|
|
292
|
+
define_predicate :left_body?, child_index: 0
|
|
293
|
+
define_predicate :right_body?, child_index: 1
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
# e.g. left_body += right_body
|
|
297
|
+
class OpAsgn < Base
|
|
298
|
+
include Operator
|
|
275
299
|
|
|
276
300
|
define_predicate :left_body?, child_index: 0
|
|
277
301
|
define_predicate :right_body?, child_index: 1
|
|
@@ -322,8 +346,8 @@ module RuboCop
|
|
|
322
346
|
end
|
|
323
347
|
end
|
|
324
348
|
|
|
325
|
-
CLASSES_BY_TYPE = Base.classes.
|
|
326
|
-
|
|
349
|
+
CLASSES_BY_TYPE = Base.classes.to_h do |klass|
|
|
350
|
+
[klass.type, klass]
|
|
327
351
|
end
|
|
328
352
|
end
|
|
329
353
|
end
|
|
@@ -238,11 +238,16 @@ module RuboCop
|
|
|
238
238
|
end
|
|
239
239
|
|
|
240
240
|
def process_loop(node)
|
|
241
|
-
if
|
|
241
|
+
if node.post_condition_loop?
|
|
242
242
|
# See the comment at the end of file for this behavior.
|
|
243
243
|
condition_node, body_node = *node
|
|
244
244
|
process_node(body_node)
|
|
245
245
|
process_node(condition_node)
|
|
246
|
+
elsif node.for_type?
|
|
247
|
+
# In `for item in items` the rightmost expression is evaluated first.
|
|
248
|
+
process_node(node.collection)
|
|
249
|
+
process_node(node.variable)
|
|
250
|
+
process_node(node.body) if node.body
|
|
246
251
|
else
|
|
247
252
|
process_children(node)
|
|
248
253
|
end
|
|
@@ -356,17 +361,14 @@ module RuboCop
|
|
|
356
361
|
end
|
|
357
362
|
|
|
358
363
|
def reference_assignments(loop_assignments, loop_node)
|
|
359
|
-
node = loop_assignments.first.node
|
|
360
|
-
|
|
361
364
|
# If inside a branching statement, mark all as referenced.
|
|
362
365
|
# Otherwise, mark only the last assignment as referenced.
|
|
363
366
|
# Note that `rescue` must be considered as branching because of
|
|
364
367
|
# the `retry` keyword.
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
else
|
|
368
|
-
loop_assignments.last&.reference!(loop_node)
|
|
368
|
+
loop_assignments.each do |assignment|
|
|
369
|
+
assignment.reference!(loop_node) if assignment.node.each_ancestor(*BRANCH_NODES).any?
|
|
369
370
|
end
|
|
371
|
+
loop_assignments.last&.reference!(loop_node)
|
|
370
372
|
end
|
|
371
373
|
|
|
372
374
|
def scanned_node?(node)
|
|
@@ -194,10 +194,10 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
|
194
194
|
|
|
195
195
|
def configurations(department, cop, cop_config)
|
|
196
196
|
header = ['Name', 'Default value', 'Configurable values']
|
|
197
|
-
configs = cop_config
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
197
|
+
configs = cop_config.each_key.reject do |key|
|
|
198
|
+
key == 'AllowMultipleStyles' ||
|
|
199
|
+
(key != 'SupportedTypes' && key.start_with?('Supported'))
|
|
200
|
+
end
|
|
201
201
|
return '' if configs.empty?
|
|
202
202
|
|
|
203
203
|
content = configs.map do |name|
|
|
@@ -14,11 +14,17 @@ module RuboCop
|
|
|
14
14
|
# @api private
|
|
15
15
|
COP_NAME_PATTERN = '([A-Za-z]\w+/)*(?:[A-Za-z]\w+)'
|
|
16
16
|
# @api private
|
|
17
|
+
COP_NAME_PATTERN_NC = '(?:[A-Za-z]\w+/)*[A-Za-z]\w+'
|
|
18
|
+
# @api private
|
|
19
|
+
COP_NAMES_PATTERN_NC = "(?:#{COP_NAME_PATTERN_NC} , )*#{COP_NAME_PATTERN_NC}"
|
|
20
|
+
# @api private
|
|
17
21
|
COP_NAMES_PATTERN = "(?:#{COP_NAME_PATTERN} , )*#{COP_NAME_PATTERN}"
|
|
18
22
|
# @api private
|
|
19
23
|
COPS_PATTERN = "(all|#{COP_NAMES_PATTERN})"
|
|
20
24
|
# @api private
|
|
21
|
-
|
|
25
|
+
PUSH_POP_ARGS_PATTERN = "([+\\-]#{COP_NAME_PATTERN_NC}(?:\\s+[+\\-]#{COP_NAME_PATTERN_NC})*)"
|
|
26
|
+
# @api private
|
|
27
|
+
AVAILABLE_MODES = %w[disable enable todo push pop].freeze
|
|
22
28
|
# @api private
|
|
23
29
|
DIRECTIVE_MARKER_PATTERN = '# rubocop : '
|
|
24
30
|
# @api private
|
|
@@ -27,7 +33,7 @@ module RuboCop
|
|
|
27
33
|
DIRECTIVE_HEADER_PATTERN = "#{DIRECTIVE_MARKER_PATTERN}((?:#{AVAILABLE_MODES.join('|')}))\\b"
|
|
28
34
|
# @api private
|
|
29
35
|
DIRECTIVE_COMMENT_REGEXP = Regexp.new(
|
|
30
|
-
"#{DIRECTIVE_HEADER_PATTERN}
|
|
36
|
+
"#{DIRECTIVE_HEADER_PATTERN}(?:\\s+#{COPS_PATTERN}|\\s+#{PUSH_POP_ARGS_PATTERN})?"
|
|
31
37
|
.gsub(' ', '\s*')
|
|
32
38
|
)
|
|
33
39
|
# @api private
|
|
@@ -46,7 +52,8 @@ module RuboCop
|
|
|
46
52
|
def initialize(comment, cop_registry = Cop::Registry.global)
|
|
47
53
|
@comment = comment
|
|
48
54
|
@cop_registry = cop_registry
|
|
49
|
-
|
|
55
|
+
match_data = comment.text.match(DIRECTIVE_COMMENT_REGEXP)
|
|
56
|
+
@match_data = match_data&.pre_match&.match?(/\A#\s*\z/) ? nil : match_data
|
|
50
57
|
@mode, @cops = match_captures
|
|
51
58
|
end
|
|
52
59
|
|
|
@@ -58,6 +65,7 @@ module RuboCop
|
|
|
58
65
|
# Checks if the comment is malformed as a `# rubocop:` directive
|
|
59
66
|
def malformed?
|
|
60
67
|
return true if !start_with_marker? || @match_data.nil?
|
|
68
|
+
return true if missing_cop_name?
|
|
61
69
|
|
|
62
70
|
tail = @match_data.post_match.lstrip
|
|
63
71
|
!(tail.empty? || tail.start_with?(TRAILING_COMMENT_MARKER))
|
|
@@ -65,6 +73,8 @@ module RuboCop
|
|
|
65
73
|
|
|
66
74
|
# Checks if the directive comment is missing a cop name
|
|
67
75
|
def missing_cop_name?
|
|
76
|
+
return false if push? || pop?
|
|
77
|
+
|
|
68
78
|
MALFORMED_DIRECTIVE_WITHOUT_COP_NAME_REGEXP.match?(comment.text)
|
|
69
79
|
end
|
|
70
80
|
|
|
@@ -88,7 +98,13 @@ module RuboCop
|
|
|
88
98
|
|
|
89
99
|
# Returns match captures to directive comment pattern
|
|
90
100
|
def match_captures
|
|
91
|
-
@match_captures ||= @match_data
|
|
101
|
+
@match_captures ||= @match_data && begin
|
|
102
|
+
captures = @match_data.captures
|
|
103
|
+
mode = captures[0]
|
|
104
|
+
# COPS_PATTERN is at captures[1], PUSH_POP_ARGS_PATTERN is at captures[4]
|
|
105
|
+
cops = captures[1] || captures[4]
|
|
106
|
+
[mode, cops]
|
|
107
|
+
end
|
|
92
108
|
end
|
|
93
109
|
|
|
94
110
|
# Checks if this directive disables cops
|
|
@@ -101,6 +117,21 @@ module RuboCop
|
|
|
101
117
|
mode == 'enable'
|
|
102
118
|
end
|
|
103
119
|
|
|
120
|
+
# Checks if this directive is a push
|
|
121
|
+
def push?
|
|
122
|
+
mode == 'push'
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Checks if this directive is a pop
|
|
126
|
+
def pop?
|
|
127
|
+
mode == 'pop'
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Returns the push arguments as a hash of cop names with their operations
|
|
131
|
+
def push_args
|
|
132
|
+
@push_args ||= parse_push_args
|
|
133
|
+
end
|
|
134
|
+
|
|
104
135
|
# Checks if this directive enables all cops
|
|
105
136
|
def enabled_all?
|
|
106
137
|
!disabled? && all_cops?
|
|
@@ -176,5 +207,18 @@ module RuboCop
|
|
|
176
207
|
def exclude_lint_department_cops(cops)
|
|
177
208
|
cops - [LINT_REDUNDANT_DIRECTIVE_COP, LINT_SYNTAX_COP]
|
|
178
209
|
end
|
|
210
|
+
|
|
211
|
+
def parse_push_args
|
|
212
|
+
return {} unless push? && cops
|
|
213
|
+
|
|
214
|
+
args = {}
|
|
215
|
+
cops.split.each do |cop_spec|
|
|
216
|
+
op = cop_spec[0]
|
|
217
|
+
cop_name = cop_spec[1..]
|
|
218
|
+
args[op] ||= []
|
|
219
|
+
args[op] << cop_name
|
|
220
|
+
end
|
|
221
|
+
args
|
|
222
|
+
end
|
|
179
223
|
end
|
|
180
224
|
end
|
|
@@ -21,11 +21,19 @@ module RuboCop
|
|
|
21
21
|
def initialize(patterns)
|
|
22
22
|
@strings = Set.new
|
|
23
23
|
@patterns = []
|
|
24
|
+
@match_cache = {}
|
|
24
25
|
partition_patterns(patterns)
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
def match?(path)
|
|
28
|
-
|
|
29
|
+
# `FilePatterns.from` memoizes one instance per pattern array (by identity),
|
|
30
|
+
# so this cache is shared across every cop using the same Include/Exclude
|
|
31
|
+
# list. Patterns are immutable within a run, so caching by path is safe.
|
|
32
|
+
cached = @match_cache[path]
|
|
33
|
+
return cached unless cached.nil?
|
|
34
|
+
|
|
35
|
+
@match_cache[path] =
|
|
36
|
+
@strings.include?(path) || @patterns.any? { |pattern| PathUtil.match_path?(pattern, path) }
|
|
29
37
|
end
|
|
30
38
|
|
|
31
39
|
private
|
|
@@ -47,8 +47,11 @@ module RuboCop
|
|
|
47
47
|
def report_highlighted_area(highlighted_area)
|
|
48
48
|
space_area = highlighted_area.source_buffer.slice(0...highlighted_area.begin_pos)
|
|
49
49
|
source_area = highlighted_area.source
|
|
50
|
-
output.puts("#{'
|
|
51
|
-
|
|
50
|
+
output.puts("#{to_whitespace(space_area)}#{'^' * Unicode::DisplayWidth.of(source_area)}")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def to_whitespace(string)
|
|
54
|
+
"#{string.delete("^\t")}#{' ' * Unicode::DisplayWidth.of(string.delete("\t"))}"
|
|
52
55
|
end
|
|
53
56
|
end
|
|
54
57
|
end
|
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
|
4
4
|
module Formatter
|
|
5
5
|
# This formatter displays a YAML configuration file where all cops that
|
|
6
6
|
# detected any offenses are configured to not detect the offense.
|
|
7
|
-
class DisabledConfigFormatter < BaseFormatter
|
|
7
|
+
class DisabledConfigFormatter < BaseFormatter # rubocop:disable Metrics/ClassLength
|
|
8
8
|
include PathUtil
|
|
9
9
|
|
|
10
10
|
HEADING = <<~COMMENTS
|
|
@@ -17,6 +17,23 @@ module RuboCop
|
|
|
17
17
|
# versions of RuboCop, may require this file to be generated again.
|
|
18
18
|
COMMENTS
|
|
19
19
|
|
|
20
|
+
EXCLUDED_CONFIG_KEYS = %w[
|
|
21
|
+
AutoCorrect
|
|
22
|
+
Description
|
|
23
|
+
Enabled
|
|
24
|
+
Exclude
|
|
25
|
+
Include
|
|
26
|
+
Reference
|
|
27
|
+
References
|
|
28
|
+
Safe
|
|
29
|
+
SafeAutoCorrect
|
|
30
|
+
Severity
|
|
31
|
+
StyleGuide
|
|
32
|
+
VersionAdded
|
|
33
|
+
VersionChanged
|
|
34
|
+
VersionRemoved
|
|
35
|
+
].freeze
|
|
36
|
+
|
|
20
37
|
@config_to_allow_offenses = {}
|
|
21
38
|
@detected_styles = {}
|
|
22
39
|
|
|
@@ -114,6 +131,9 @@ module RuboCop
|
|
|
114
131
|
end
|
|
115
132
|
|
|
116
133
|
def set_max(cfg, cop_name)
|
|
134
|
+
exclude_limits = RuboCop::ExcludeLimit.read_limits(cop_name)
|
|
135
|
+
cfg[:exclude_limit] = exclude_limits unless exclude_limits.empty?
|
|
136
|
+
|
|
117
137
|
return unless cfg[:exclude_limit]
|
|
118
138
|
|
|
119
139
|
cfg.merge!(cfg[:exclude_limit]) if should_set_max?(cop_name)
|
|
@@ -163,10 +183,7 @@ module RuboCop
|
|
|
163
183
|
end
|
|
164
184
|
|
|
165
185
|
def cop_config_params(default_cfg, cfg)
|
|
166
|
-
default_cfg.keys -
|
|
167
|
-
%w[Description StyleGuide Reference References Enabled Exclude Safe
|
|
168
|
-
SafeAutoCorrect VersionAdded VersionChanged VersionRemoved] -
|
|
169
|
-
cfg.keys
|
|
186
|
+
default_cfg.keys - EXCLUDED_CONFIG_KEYS - cfg.keys
|
|
170
187
|
end
|
|
171
188
|
|
|
172
189
|
def output_cop_param_comments(output_buffer, params, default_cfg)
|
|
@@ -178,7 +195,7 @@ module RuboCop
|
|
|
178
195
|
next unless value.is_a?(Array)
|
|
179
196
|
next if value.empty?
|
|
180
197
|
|
|
181
|
-
value.map
|
|
198
|
+
value = value.map { |v| v.nil? ? '~' : v } # Change nil back to ~ as in the YAML file.
|
|
182
199
|
output_buffer.puts "# #{param}: #{value.uniq.join(', ')}"
|
|
183
200
|
end
|
|
184
201
|
end
|
|
@@ -219,7 +236,7 @@ module RuboCop
|
|
|
219
236
|
|
|
220
237
|
def output_exclude_list(output_buffer, offending_files, cop_name)
|
|
221
238
|
require 'pathname'
|
|
222
|
-
parent = Pathname.new(
|
|
239
|
+
parent = Pathname.new(PathUtil.pwd)
|
|
223
240
|
|
|
224
241
|
output_buffer.puts ' Exclude:'
|
|
225
242
|
excludes(offending_files, cop_name, parent).each do |exclude_path|
|
|
@@ -57,7 +57,7 @@ module RuboCop
|
|
|
57
57
|
if output_path
|
|
58
58
|
dir_path = File.dirname(output_path)
|
|
59
59
|
FileUtils.mkdir_p(dir_path)
|
|
60
|
-
output = File.open(output_path, 'w')
|
|
60
|
+
output = File.open(output_path, 'w') # rubocop:disable Style/FileOpen
|
|
61
61
|
else
|
|
62
62
|
output = $stdout
|
|
63
63
|
end
|
|
@@ -86,7 +86,7 @@ module RuboCop
|
|
|
86
86
|
|
|
87
87
|
def builtin_formatter_class(specified_key)
|
|
88
88
|
matching_keys = BUILTIN_FORMATTERS_FOR_KEYS.keys.select do |key|
|
|
89
|
-
|
|
89
|
+
key.start_with?("[#{specified_key}]") || specified_key == key.delete('[]')
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
if matching_keys.empty?
|
|
@@ -93,7 +93,7 @@ module RuboCop
|
|
|
93
93
|
|
|
94
94
|
def classname_attribute_value(file)
|
|
95
95
|
@classname_attribute_value_cache ||= Hash.new do |hash, key|
|
|
96
|
-
hash[key] = key.delete_suffix('.rb').gsub("#{
|
|
96
|
+
hash[key] = key.delete_suffix('.rb').gsub("#{PathUtil.pwd}/", '').tr('/', '.')
|
|
97
97
|
end
|
|
98
98
|
@classname_attribute_value_cache[file]
|
|
99
99
|
end
|
|
@@ -39,8 +39,11 @@ module RuboCop
|
|
|
39
39
|
def report_highlighted_area(highlighted_area)
|
|
40
40
|
space_area = highlighted_area.source_buffer.slice(0...highlighted_area.begin_pos)
|
|
41
41
|
source_area = highlighted_area.source
|
|
42
|
-
output.puts("# #{'
|
|
43
|
-
|
|
42
|
+
output.puts("# #{to_whitespace(space_area)}#{'^' * Unicode::DisplayWidth.of(source_area)}")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def to_whitespace(string)
|
|
46
|
+
"#{string.delete("^\t")}#{' ' * Unicode::DisplayWidth.of(string.delete("\t"))}"
|
|
44
47
|
end
|
|
45
48
|
|
|
46
49
|
def report_offense(file, offense)
|
|
@@ -24,7 +24,7 @@ module RuboCop
|
|
|
24
24
|
def file_finished(file, offenses)
|
|
25
25
|
return if offenses.empty?
|
|
26
26
|
|
|
27
|
-
path = Pathname.new(file).relative_path_from(Pathname.new(
|
|
27
|
+
path = Pathname.new(file).relative_path_from(Pathname.new(PathUtil.pwd))
|
|
28
28
|
@offense_counts[path] = offenses.size
|
|
29
29
|
end
|
|
30
30
|
|
data/lib/rubocop/formatter.rb
CHANGED
|
@@ -3,32 +3,33 @@
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
# The bootstrap module for formatter.
|
|
5
5
|
module Formatter
|
|
6
|
-
|
|
6
|
+
autoload :Colorizable, 'rubocop/formatter/colorizable'
|
|
7
|
+
autoload :TextUtil, 'rubocop/formatter/text_util'
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
autoload :BaseFormatter, 'rubocop/formatter/base_formatter'
|
|
10
|
+
autoload :SimpleTextFormatter, 'rubocop/formatter/simple_text_formatter'
|
|
10
11
|
|
|
11
12
|
# relies on simple text
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
autoload :ClangStyleFormatter, 'rubocop/formatter/clang_style_formatter'
|
|
14
|
+
autoload :DisabledConfigFormatter, 'rubocop/formatter/disabled_config_formatter'
|
|
15
|
+
autoload :EmacsStyleFormatter, 'rubocop/formatter/emacs_style_formatter'
|
|
16
|
+
autoload :FileListFormatter, 'rubocop/formatter/file_list_formatter'
|
|
17
|
+
autoload :FuubarStyleFormatter, 'rubocop/formatter/fuubar_style_formatter'
|
|
18
|
+
autoload :GitHubActionsFormatter, 'rubocop/formatter/github_actions_formatter'
|
|
19
|
+
autoload :HTMLFormatter, 'rubocop/formatter/html_formatter'
|
|
20
|
+
autoload :JSONFormatter, 'rubocop/formatter/json_formatter'
|
|
21
|
+
autoload :JUnitFormatter, 'rubocop/formatter/junit_formatter'
|
|
22
|
+
autoload :MarkdownFormatter, 'rubocop/formatter/markdown_formatter'
|
|
23
|
+
autoload :OffenseCountFormatter, 'rubocop/formatter/offense_count_formatter'
|
|
24
|
+
autoload :PacmanFormatter, 'rubocop/formatter/pacman_formatter'
|
|
25
|
+
autoload :ProgressFormatter, 'rubocop/formatter/progress_formatter'
|
|
26
|
+
autoload :QuietFormatter, 'rubocop/formatter/quiet_formatter'
|
|
27
|
+
autoload :TapFormatter, 'rubocop/formatter/tap_formatter'
|
|
28
|
+
autoload :WorstOffendersFormatter, 'rubocop/formatter/worst_offenders_formatter'
|
|
28
29
|
|
|
29
30
|
# relies on progress formatter
|
|
30
|
-
|
|
31
|
+
autoload :AutoGenConfigFormatter, 'rubocop/formatter/auto_gen_config_formatter'
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
autoload :FormatterSet, 'rubocop/formatter/formatter_set'
|
|
33
34
|
end
|
|
34
35
|
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'language_server-protocol'
|
|
4
|
+
require_relative 'disable_comment_edits'
|
|
3
5
|
require_relative 'severity'
|
|
4
6
|
|
|
5
7
|
#
|
|
@@ -16,11 +18,12 @@ module RuboCop
|
|
|
16
18
|
# Diagnostic for Language Server Protocol of RuboCop.
|
|
17
19
|
# @api private
|
|
18
20
|
class Diagnostic
|
|
19
|
-
def initialize(document_encoding, offense, uri, cop_class)
|
|
21
|
+
def initialize(document_encoding, offense, uri, cop_class, processed_source = nil)
|
|
20
22
|
@document_encoding = document_encoding
|
|
21
23
|
@offense = offense
|
|
22
24
|
@uri = uri
|
|
23
25
|
@cop_class = cop_class
|
|
26
|
+
@processed_source = processed_source
|
|
24
27
|
end
|
|
25
28
|
|
|
26
29
|
def to_lsp_code_actions
|
|
@@ -45,11 +48,11 @@ module RuboCop
|
|
|
45
48
|
range: LanguageServer::Protocol::Interface::Range.new(
|
|
46
49
|
start: LanguageServer::Protocol::Interface::Position.new(
|
|
47
50
|
line: @offense.line - 1,
|
|
48
|
-
character: highlighted.begin_pos
|
|
51
|
+
character: to_position_character(highlighted.begin_pos)
|
|
49
52
|
),
|
|
50
53
|
end: LanguageServer::Protocol::Interface::Position.new(
|
|
51
54
|
line: @offense.line - 1,
|
|
52
|
-
character: highlighted.end_pos
|
|
55
|
+
character: to_position_character(highlighted.end_pos)
|
|
53
56
|
)
|
|
54
57
|
),
|
|
55
58
|
data: {
|
|
@@ -107,11 +110,11 @@ module RuboCop
|
|
|
107
110
|
range: LanguageServer::Protocol::Interface::Range.new(
|
|
108
111
|
start: LanguageServer::Protocol::Interface::Position.new(
|
|
109
112
|
line: range.line - 1,
|
|
110
|
-
character: range.column
|
|
113
|
+
character: to_position_character(range.column)
|
|
111
114
|
),
|
|
112
115
|
end: LanguageServer::Protocol::Interface::Position.new(
|
|
113
116
|
line: range.last_line - 1,
|
|
114
|
-
character: range.last_column
|
|
117
|
+
character: to_position_character(range.last_column)
|
|
115
118
|
)
|
|
116
119
|
),
|
|
117
120
|
new_text: replacement
|
|
@@ -141,37 +144,19 @@ module RuboCop
|
|
|
141
144
|
# rubocop:enable Metrics/MethodLength
|
|
142
145
|
|
|
143
146
|
def line_disable_comment
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
eol = LanguageServer::Protocol::Interface::Position.new(
|
|
151
|
-
line: @offense.line - 1,
|
|
152
|
-
character: length_of_line(@offense.source_line)
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
# TODO: fails for multiline strings - may be preferable to use block
|
|
156
|
-
# comments to disable some offenses
|
|
157
|
-
inline_comment = LanguageServer::Protocol::Interface::TextEdit.new(
|
|
158
|
-
range: LanguageServer::Protocol::Interface::Range.new(start: eol, end: eol),
|
|
159
|
-
new_text: new_text
|
|
160
|
-
)
|
|
161
|
-
|
|
162
|
-
[inline_comment]
|
|
147
|
+
DisableCommentEdits.new(
|
|
148
|
+
offense: @offense,
|
|
149
|
+
document_encoding: @document_encoding,
|
|
150
|
+
processed_source: @processed_source
|
|
151
|
+
).edits
|
|
163
152
|
end
|
|
164
153
|
|
|
165
|
-
def
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
line_length += 1
|
|
170
|
-
line_length += 1 if codepoint > RubyLsp::Document::Scanner::SURROGATE_PAIR_START
|
|
171
|
-
end
|
|
172
|
-
line_length
|
|
154
|
+
def to_position_character(utf8_index)
|
|
155
|
+
str = @offense.source_line[0, utf8_index]
|
|
156
|
+
if @document_encoding == Encoding::UTF_16LE || @document_encoding.nil?
|
|
157
|
+
str.length + str.b.count("\xf0-\xff".b)
|
|
173
158
|
else
|
|
174
|
-
|
|
159
|
+
str.length
|
|
175
160
|
end
|
|
176
161
|
end
|
|
177
162
|
|