rubocop 1.69.0 → 1.79.2
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 +23 -19
- data/config/default.yml +290 -65
- data/config/internal_affairs.yml +20 -0
- data/config/obsoletion.yml +8 -3
- data/lib/rubocop/cli/command/execute_runner.rb +3 -3
- data/lib/rubocop/cli/command/show_cops.rb +24 -2
- data/lib/rubocop/cli/command/suggest_extensions.rb +7 -1
- data/lib/rubocop/cli.rb +13 -2
- data/lib/rubocop/comment_config.rb +2 -2
- data/lib/rubocop/config.rb +52 -10
- data/lib/rubocop/config_loader.rb +53 -47
- data/lib/rubocop/config_loader_resolver.rb +36 -10
- data/lib/rubocop/config_obsoletion/extracted_cop.rb +4 -3
- data/lib/rubocop/config_obsoletion/renamed_cop.rb +18 -3
- data/lib/rubocop/config_obsoletion.rb +46 -2
- data/lib/rubocop/config_validator.rb +25 -14
- data/lib/rubocop/cop/autocorrect_logic.rb +44 -39
- data/lib/rubocop/cop/base.rb +6 -0
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -2
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +5 -2
- data/lib/rubocop/cop/gemspec/attribute_assignment.rb +91 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +37 -15
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/gemspec/require_mfa.rb +15 -1
- data/lib/rubocop/cop/generator.rb +6 -0
- data/lib/rubocop/cop/internal_affairs/cop_enabled.rb +85 -0
- data/lib/rubocop/cop/internal_affairs/example_description.rb +9 -5
- data/lib/rubocop/cop/internal_affairs/location_exists.rb +116 -0
- data/lib/rubocop/cop/internal_affairs/location_expression.rb +2 -1
- data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +3 -2
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +5 -5
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +63 -0
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +131 -0
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +231 -0
- data/lib/rubocop/cop/internal_affairs/node_type_group.rb +92 -0
- data/lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb +126 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +4 -3
- data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +90 -0
- data/lib/rubocop/cop/internal_affairs/operator_keyword.rb +4 -2
- data/lib/rubocop/cop/internal_affairs/plugin.rb +33 -0
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +6 -5
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +3 -1
- data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +5 -4
- data/lib/rubocop/cop/internal_affairs/undefined_config.rb +13 -2
- data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +1 -1
- data/lib/rubocop/cop/internal_affairs.rb +6 -16
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/argument_alignment.rb +2 -8
- data/lib/rubocop/cop/layout/block_alignment.rb +3 -1
- data/lib/rubocop/cop/layout/block_end_newline.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +44 -9
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -5
- data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +2 -2
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +7 -11
- data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +101 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +35 -4
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +8 -29
- data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +5 -6
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +1 -0
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +22 -2
- data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +4 -9
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -7
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +2 -7
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +8 -6
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -0
- data/lib/rubocop/cop/layout/leading_comment_space.rb +13 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +11 -2
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +7 -1
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/line_length.rb +35 -9
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +25 -0
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +4 -4
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/redundant_line_break.rb +16 -11
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -5
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_colon.rb +2 -2
- data/lib/rubocop/cop/layout/space_after_comma.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +11 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +7 -1
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +15 -4
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -0
- data/lib/rubocop/cop/layout/space_before_brackets.rb +5 -38
- data/lib/rubocop/cop/layout/space_before_comma.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_semicolon.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +12 -3
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -0
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +3 -0
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +5 -3
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_range.rb +5 -0
- data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +118 -0
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -3
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +2 -3
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +4 -3
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +3 -3
- data/lib/rubocop/cop/lint/constant_reassignment.rb +148 -0
- data/lib/rubocop/cop/lint/cop_directive_syntax.rb +84 -0
- data/lib/rubocop/cop/lint/debugger.rb +3 -3
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +2 -1
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +111 -23
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_set_element.rb +20 -7
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +14 -64
- data/lib/rubocop/cop/lint/empty_expression.rb +0 -2
- data/lib/rubocop/cop/lint/empty_interpolation.rb +3 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +0 -6
- data/lib/rubocop/cop/lint/float_comparison.rb +37 -12
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +2 -2
- data/lib/rubocop/cop/lint/identity_comparison.rb +19 -15
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/literal_as_condition.rb +125 -10
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +24 -6
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -1
- data/lib/rubocop/cop/lint/missing_super.rb +2 -2
- data/lib/rubocop/cop/lint/mixed_case_range.rb +3 -3
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +9 -5
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +4 -2
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +3 -3
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -3
- data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +19 -31
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +2 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -5
- data/lib/rubocop/cop/lint/raise_exception.rb +29 -10
- data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +0 -21
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +101 -2
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_type_conversion.rb +261 -0
- data/lib/rubocop/cop/lint/redundant_with_index.rb +3 -0
- data/lib/rubocop/cop/lint/redundant_with_object.rb +3 -0
- data/lib/rubocop/cop/lint/refinement_import_methods.rb +1 -1
- data/lib/rubocop/cop/lint/require_range_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +1 -1
- data/lib/rubocop/cop/lint/return_in_void_context.rb +9 -11
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +8 -1
- data/lib/rubocop/cop/lint/self_assignment.rb +25 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +13 -1
- data/lib/rubocop/cop/lint/shared_mutable_default.rb +76 -0
- data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/suppressed_exception_in_number_conversion.rb +111 -0
- data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/syntax.rb +4 -1
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
- data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +1 -1
- data/lib/rubocop/cop/lint/unexpected_block_arity.rb +3 -1
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +52 -2
- data/lib/rubocop/cop/lint/unreachable_loop.rb +6 -6
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +34 -8
- data/lib/rubocop/cop/lint/useless_assignment.rb +3 -1
- data/lib/rubocop/cop/lint/useless_constant_scoping.rb +71 -0
- data/lib/rubocop/cop/lint/useless_default_value_argument.rb +90 -0
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +4 -0
- data/lib/rubocop/cop/lint/useless_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/useless_numeric_operation.rb +3 -1
- data/lib/rubocop/cop/lint/useless_or.rb +98 -0
- data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +5 -5
- data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +121 -0
- data/lib/rubocop/cop/lint/void.rb +14 -11
- data/lib/rubocop/cop/message_annotator.rb +7 -3
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/block_length.rb +1 -0
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
- data/lib/rubocop/cop/metrics/class_length.rb +9 -9
- data/lib/rubocop/cop/metrics/collection_literal_length.rb +7 -0
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/method_length.rb +9 -1
- data/lib/rubocop/cop/metrics/module_length.rb +1 -1
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +2 -2
- data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +7 -7
- data/lib/rubocop/cop/mixin/alignment.rb +3 -3
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +4 -4
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +13 -13
- data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +2 -2
- data/lib/rubocop/cop/mixin/comments_help.rb +8 -3
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/dig_help.rb +1 -1
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
- data/lib/rubocop/cop/mixin/forbidden_identifiers.rb +20 -0
- data/lib/rubocop/cop/mixin/forbidden_pattern.rb +16 -0
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -2
- data/lib/rubocop/cop/mixin/gemspec_help.rb +22 -0
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +15 -14
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +22 -22
- data/lib/rubocop/cop/mixin/hash_subset.rb +203 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +74 -74
- data/lib/rubocop/cop/mixin/line_length_help.rb +27 -10
- data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
- data/lib/rubocop/cop/mixin/percent_literal.rb +1 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +68 -30
- data/lib/rubocop/cop/mixin/range_help.rb +15 -3
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +8 -3
- data/lib/rubocop/cop/mixin/string_help.rb +2 -2
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +1 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +21 -5
- data/lib/rubocop/cop/naming/accessor_method_name.rb +6 -6
- data/lib/rubocop/cop/naming/block_forwarding.rb +19 -15
- data/lib/rubocop/cop/naming/file_name.rb +2 -2
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +185 -15
- data/lib/rubocop/cop/naming/predicate_method.rb +306 -0
- data/lib/rubocop/cop/naming/{predicate_name.rb → predicate_prefix.rb} +48 -4
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +4 -4
- data/lib/rubocop/cop/naming/variable_name.rb +51 -6
- data/lib/rubocop/cop/registry.rb +9 -6
- data/lib/rubocop/cop/security/compound_hash.rb +2 -0
- data/lib/rubocop/cop/security/eval.rb +2 -1
- data/lib/rubocop/cop/security/open.rb +1 -0
- data/lib/rubocop/cop/security/yaml_load.rb +3 -2
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +66 -15
- data/lib/rubocop/cop/style/accessor_grouping.rb +32 -6
- data/lib/rubocop/cop/style/and_or.rb +1 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +57 -44
- data/lib/rubocop/cop/style/array_first_last.rb +18 -2
- data/lib/rubocop/cop/style/array_intersect.rb +81 -40
- data/lib/rubocop/cop/style/block_delimiters.rb +27 -24
- data/lib/rubocop/cop/style/case_like_if.rb +1 -1
- data/lib/rubocop/cop/style/class_and_module_children.rb +52 -11
- data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -1
- data/lib/rubocop/cop/style/collection_methods.rb +2 -1
- data/lib/rubocop/cop/style/collection_querying.rb +167 -0
- data/lib/rubocop/cop/style/combinable_defined.rb +1 -1
- data/lib/rubocop/cop/style/combinable_loops.rb +3 -2
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +12 -5
- data/lib/rubocop/cop/style/comparable_between.rb +78 -0
- data/lib/rubocop/cop/style/concat_array_literals.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +23 -7
- data/lib/rubocop/cop/style/data_inheritance.rb +7 -0
- data/lib/rubocop/cop/style/def_with_parentheses.rb +18 -5
- data/lib/rubocop/cop/style/dig_chain.rb +6 -7
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +4 -4
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +4 -7
- data/lib/rubocop/cop/style/each_with_object.rb +2 -3
- data/lib/rubocop/cop/style/empty_else.rb +4 -2
- data/lib/rubocop/cop/style/empty_literal.rb +5 -1
- data/lib/rubocop/cop/style/empty_method.rb +1 -1
- data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +100 -0
- data/lib/rubocop/cop/style/endless_method.rb +163 -18
- data/lib/rubocop/cop/style/eval_with_location.rb +4 -4
- data/lib/rubocop/cop/style/exact_regexp_match.rb +2 -3
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -7
- data/lib/rubocop/cop/style/explicit_block_argument.rb +16 -3
- data/lib/rubocop/cop/style/exponential_notation.rb +6 -5
- data/lib/rubocop/cop/style/fetch_env_var.rb +34 -7
- data/lib/rubocop/cop/style/file_null.rb +20 -4
- data/lib/rubocop/cop/style/float_division.rb +8 -4
- data/lib/rubocop/cop/style/for.rb +1 -0
- data/lib/rubocop/cop/style/format_string_token.rb +38 -11
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -2
- data/lib/rubocop/cop/style/global_std_stream.rb +3 -0
- data/lib/rubocop/cop/style/guard_clause.rb +2 -1
- data/lib/rubocop/cop/style/hash_conversion.rb +16 -8
- data/lib/rubocop/cop/style/hash_each_methods.rb +6 -8
- data/lib/rubocop/cop/style/hash_except.rb +35 -147
- data/lib/rubocop/cop/style/hash_fetch_chain.rb +104 -0
- data/lib/rubocop/cop/style/hash_slice.rb +80 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +9 -3
- data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +25 -6
- data/lib/rubocop/cop/style/if_inside_else.rb +10 -13
- data/lib/rubocop/cop/style/if_unless_modifier.rb +36 -9
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +4 -7
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -2
- 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/inverse_methods.rb +16 -12
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +2 -2
- data/lib/rubocop/cop/style/ip_addresses.rb +2 -2
- data/lib/rubocop/cop/style/it_assignment.rb +93 -0
- data/lib/rubocop/cop/style/it_block_parameter.rb +121 -0
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +14 -8
- data/lib/rubocop/cop/style/lambda.rb +1 -0
- data/lib/rubocop/cop/style/lambda_call.rb +10 -3
- data/lib/rubocop/cop/style/line_end_concatenation.rb +10 -4
- data/lib/rubocop/cop/style/map_into_array.rb +5 -2
- data/lib/rubocop/cop/style/map_to_hash.rb +13 -4
- data/lib/rubocop/cop/style/map_to_set.rb +4 -5
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +27 -19
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +18 -0
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +3 -2
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +3 -4
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/min_max_comparison.rb +13 -5
- data/lib/rubocop/cop/style/missing_else.rb +2 -0
- data/lib/rubocop/cop/style/multiline_block_chain.rb +3 -2
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -0
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -9
- data/lib/rubocop/cop/style/multiple_comparison.rb +34 -22
- data/lib/rubocop/cop/style/mutable_constant.rb +3 -3
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -1
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
- data/lib/rubocop/cop/style/next.rb +44 -0
- data/lib/rubocop/cop/style/object_then.rb +15 -15
- data/lib/rubocop/cop/style/open_struct_use.rb +5 -5
- data/lib/rubocop/cop/style/parallel_assignment.rb +33 -25
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -2
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +2 -2
- data/lib/rubocop/cop/style/quoted_symbols.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +14 -12
- data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
- data/lib/rubocop/cop/style/redundant_argument.rb +3 -1
- data/lib/rubocop/cop/style/redundant_array_flatten.rb +50 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +2 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +59 -2
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +16 -5
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +6 -10
- data/lib/rubocop/cop/style/redundant_each.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +2 -2
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -9
- data/lib/rubocop/cop/style/redundant_format.rb +262 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +4 -4
- data/lib/rubocop/cop/style/redundant_initialize.rb +12 -3
- data/lib/rubocop/cop/style/redundant_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +39 -22
- data/lib/rubocop/cop/style/redundant_parentheses.rb +85 -17
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +3 -0
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self.rb +10 -6
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +14 -28
- data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
- data/lib/rubocop/cop/style/redundant_sort_by.rb +17 -1
- data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
- data/lib/rubocop/cop/style/rescue_modifier.rb +3 -0
- data/lib/rubocop/cop/style/return_nil.rb +2 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +46 -16
- data/lib/rubocop/cop/style/select_by_regexp.rb +4 -1
- data/lib/rubocop/cop/style/semicolon.rb +1 -1
- data/lib/rubocop/cop/style/send_with_literal_method_name.rb +2 -1
- data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +4 -3
- data/lib/rubocop/cop/style/single_line_methods.rb +13 -11
- data/lib/rubocop/cop/style/slicing_with_range.rb +40 -11
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +68 -101
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/string_concatenation.rb +15 -14
- data/lib/rubocop/cop/style/string_literals.rb +1 -1
- data/lib/rubocop/cop/style/string_methods.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +8 -1
- data/lib/rubocop/cop/style/super_arguments.rb +66 -19
- data/lib/rubocop/cop/style/symbol_proc.rb +3 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/top_level_method_definition.rb +2 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +11 -2
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +47 -6
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +48 -6
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +8 -4
- data/lib/rubocop/cop/style/yoda_expression.rb +2 -1
- data/lib/rubocop/cop/team.rb +1 -1
- data/lib/rubocop/cop/util.rb +12 -5
- data/lib/rubocop/cop/utils/format_string.rb +10 -5
- data/lib/rubocop/cop/variable_force/assignment.rb +7 -3
- data/lib/rubocop/cop/variable_force/scope.rb +1 -1
- data/lib/rubocop/cop/variable_force/variable.rb +10 -3
- data/lib/rubocop/cop/variable_force/variable_table.rb +3 -3
- data/lib/rubocop/cop/variable_force.rb +23 -8
- data/lib/rubocop/cops_documentation_generator.rb +32 -16
- data/lib/rubocop/directive_comment.rb +45 -11
- data/lib/rubocop/ext/regexp_node.rb +0 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -1
- data/lib/rubocop/formatter/formatter_set.rb +1 -1
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/html_formatter.rb +1 -1
- data/lib/rubocop/formatter/markdown_formatter.rb +1 -0
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
- data/lib/rubocop/formatter/pacman_formatter.rb +2 -1
- data/lib/rubocop/lsp/diagnostic.rb +189 -0
- data/lib/rubocop/lsp/logger.rb +2 -2
- data/lib/rubocop/lsp/routes.rb +10 -26
- data/lib/rubocop/lsp/runtime.rb +18 -50
- data/lib/rubocop/lsp/server.rb +0 -2
- data/lib/rubocop/lsp/stdin_runner.rb +85 -0
- data/lib/rubocop/magic_comment.rb +11 -3
- data/lib/rubocop/options.rb +28 -12
- data/lib/rubocop/path_util.rb +15 -8
- data/lib/rubocop/pending_cops_reporter.rb +56 -0
- data/lib/rubocop/plugin/configuration_integrator.rb +143 -0
- data/lib/rubocop/plugin/load_error.rb +26 -0
- data/lib/rubocop/plugin/loader.rb +100 -0
- data/lib/rubocop/plugin/not_supported_error.rb +29 -0
- data/lib/rubocop/plugin.rb +46 -0
- data/lib/rubocop/rake_task.rb +4 -1
- data/lib/rubocop/result_cache.rb +26 -24
- data/lib/rubocop/rspec/cop_helper.rb +13 -1
- data/lib/rubocop/rspec/expect_offense.rb +15 -5
- data/lib/rubocop/rspec/shared_contexts.rb +38 -1
- data/lib/rubocop/rspec/support.rb +4 -2
- data/lib/rubocop/runner.rb +10 -7
- data/lib/rubocop/server/cache.rb +51 -13
- data/lib/rubocop/server/cli.rb +2 -2
- data/lib/rubocop/server/client_command/base.rb +10 -0
- data/lib/rubocop/server/client_command/exec.rb +2 -1
- data/lib/rubocop/server/client_command/start.rb +11 -1
- data/lib/rubocop/target_finder.rb +7 -2
- data/lib/rubocop/target_ruby.rb +16 -1
- data/lib/rubocop/version.rb +30 -8
- data/lib/rubocop.rb +27 -2
- data/lib/ruby_lsp/rubocop/addon.rb +75 -0
- data/lib/ruby_lsp/rubocop/runtime_adapter.rb +65 -0
- metadata +72 -19
- data/lib/rubocop/cop/utils/regexp_ranges.rb +0 -113
- data/lib/rubocop/rspec/host_environment_simulation_helper.rb +0 -28
@@ -110,8 +110,13 @@ module RuboCop
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def multiple_assignment_node
|
113
|
-
return nil unless node.parent
|
114
|
-
|
113
|
+
return nil unless (candidate_mlhs_node = node.parent)
|
114
|
+
|
115
|
+
# In `(foo, bar), *baz`, the splat node must be traversed as well.
|
116
|
+
candidate_mlhs_node = candidate_mlhs_node.parent if candidate_mlhs_node.splat_type?
|
117
|
+
|
118
|
+
return nil unless candidate_mlhs_node.mlhs_type?
|
119
|
+
return nil unless (grandparent_node = node.parent.parent)
|
115
120
|
if (node = find_multiple_assignment_node(grandparent_node))
|
116
121
|
return node
|
117
122
|
end
|
@@ -139,7 +144,6 @@ module RuboCop
|
|
139
144
|
|
140
145
|
def find_multiple_assignment_node(grandparent_node)
|
141
146
|
return unless grandparent_node.type == MULTIPLE_LEFT_HAND_SIDE_TYPE
|
142
|
-
return if grandparent_node.children.any?(&:splat_type?)
|
143
147
|
|
144
148
|
parent = grandparent_node.parent
|
145
149
|
return parent if parent.type == MULTIPLE_ASSIGNMENT_TYPE
|
@@ -31,11 +31,18 @@ module RuboCop
|
|
31
31
|
def assign(node)
|
32
32
|
assignment = Assignment.new(node, self)
|
33
33
|
|
34
|
-
|
34
|
+
mark_last_as_reassigned!(assignment)
|
35
35
|
|
36
36
|
@assignments << assignment
|
37
37
|
end
|
38
38
|
|
39
|
+
def mark_last_as_reassigned!(assignment)
|
40
|
+
return if captured_by_block?
|
41
|
+
return unless assignment.branch == @assignments.last&.branch
|
42
|
+
|
43
|
+
@assignments.last&.reassigned!
|
44
|
+
end
|
45
|
+
|
39
46
|
def referenced?
|
40
47
|
!@references.empty?
|
41
48
|
end
|
@@ -72,7 +79,7 @@ module RuboCop
|
|
72
79
|
parent = parent.parent if parent&.begin_type?
|
73
80
|
return false if parent.nil?
|
74
81
|
|
75
|
-
|
82
|
+
parent.type?(:if, :while, :until) && parent.modifier_form?
|
76
83
|
end
|
77
84
|
|
78
85
|
def capture_with_block!
|
@@ -100,7 +107,7 @@ module RuboCop
|
|
100
107
|
end
|
101
108
|
|
102
109
|
def method_argument?
|
103
|
-
argument? &&
|
110
|
+
argument? && @scope.node.any_def_type?
|
104
111
|
end
|
105
112
|
|
106
113
|
def block_argument?
|
@@ -100,7 +100,7 @@ module RuboCop
|
|
100
100
|
|
101
101
|
# Only block scope allows referencing outer scope variables.
|
102
102
|
node = scope.node
|
103
|
-
return nil unless node.
|
103
|
+
return nil unless node.any_block_type?
|
104
104
|
end
|
105
105
|
|
106
106
|
nil
|
@@ -113,14 +113,14 @@ module RuboCop
|
|
113
113
|
def accessible_variables
|
114
114
|
scope_stack.reverse_each.with_object([]) do |scope, variables|
|
115
115
|
variables.concat(scope.variables.values)
|
116
|
-
break variables unless scope.node.
|
116
|
+
break variables unless scope.node.any_block_type?
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
private
|
121
121
|
|
122
122
|
def mark_variable_as_captured_by_block_if_so(variable)
|
123
|
-
return unless current_scope.node.
|
123
|
+
return unless current_scope.node.any_block_type?
|
124
124
|
return if variable.scope == current_scope
|
125
125
|
|
126
126
|
variable.capture_with_block!
|
@@ -54,7 +54,7 @@ module RuboCop
|
|
54
54
|
|
55
55
|
ZERO_ARITY_SUPER_TYPE = :zsuper
|
56
56
|
|
57
|
-
TWISTED_SCOPE_TYPES = %i[block numblock class sclass defs module].freeze
|
57
|
+
TWISTED_SCOPE_TYPES = %i[block numblock itblock class sclass defs module].freeze
|
58
58
|
SCOPE_TYPES = (TWISTED_SCOPE_TYPES + [:def]).freeze
|
59
59
|
|
60
60
|
SEND_TYPE = :send
|
@@ -71,6 +71,8 @@ module RuboCop
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
BRANCH_NODES = %i[if case case_match rescue].freeze
|
75
|
+
|
74
76
|
def variable_table
|
75
77
|
@variable_table ||= VariableTable.new(self)
|
76
78
|
end
|
@@ -296,7 +298,7 @@ module RuboCop
|
|
296
298
|
variable_table.accessible_variables.each { |variable| variable.reference!(node) }
|
297
299
|
end
|
298
300
|
|
299
|
-
# Mark
|
301
|
+
# Mark last assignments which are referenced in the same loop
|
300
302
|
# as referenced by ignoring AST order since they would be referenced
|
301
303
|
# in next iteration.
|
302
304
|
def mark_assignments_as_referenced_in_loop(node)
|
@@ -308,13 +310,12 @@ module RuboCop
|
|
308
310
|
# would be skipped here.
|
309
311
|
next unless variable
|
310
312
|
|
311
|
-
variable.assignments.
|
312
|
-
|
313
|
-
assignment_node.equal?(assignment.node)
|
314
|
-
end
|
315
|
-
|
316
|
-
assignment.reference!(node)
|
313
|
+
loop_assignments = variable.assignments.select do |assignment|
|
314
|
+
assignment_nodes_in_loop.include?(assignment.node)
|
317
315
|
end
|
316
|
+
next unless loop_assignments.any?
|
317
|
+
|
318
|
+
reference_assignments(loop_assignments, node)
|
318
319
|
end
|
319
320
|
end
|
320
321
|
|
@@ -354,6 +355,20 @@ module RuboCop
|
|
354
355
|
end
|
355
356
|
end
|
356
357
|
|
358
|
+
def reference_assignments(loop_assignments, loop_node)
|
359
|
+
node = loop_assignments.first.node
|
360
|
+
|
361
|
+
# If inside a branching statement, mark all as referenced.
|
362
|
+
# Otherwise, mark only the last assignment as referenced.
|
363
|
+
# Note that `rescue` must be considered as branching because of
|
364
|
+
# the `retry` keyword.
|
365
|
+
if node.each_ancestor(*BRANCH_NODES).any? || node.parent.each_descendant(*BRANCH_NODES).any?
|
366
|
+
loop_assignments.each { |assignment| assignment.reference!(loop_node) }
|
367
|
+
else
|
368
|
+
loop_assignments.last&.reference!(loop_node)
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
357
372
|
def scanned_node?(node)
|
358
373
|
scanned_nodes.include?(node)
|
359
374
|
end
|
@@ -7,6 +7,7 @@ require 'yard'
|
|
7
7
|
# @api private
|
8
8
|
class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
9
9
|
include ::RuboCop::Cop::Documentation
|
10
|
+
|
10
11
|
CopData = Struct.new(
|
11
12
|
:cop, :description, :example_objects, :safety_objects, :see_objects, :config, keyword_init: true
|
12
13
|
)
|
@@ -18,7 +19,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
18
19
|
description: ->(data) { "#{data.description}\n" },
|
19
20
|
safety: ->(data) { safety_object(data.safety_objects, data.cop) },
|
20
21
|
examples: ->(data) { examples(data.example_objects, data.cop) },
|
21
|
-
configuration: ->(data) { configurations(data.cop.department, data.
|
22
|
+
configuration: ->(data) { configurations(data.cop.department, data.cop, data.config) },
|
22
23
|
references: ->(data) { references(data.cop, data.see_objects) }
|
23
24
|
}.freeze
|
24
25
|
|
@@ -28,6 +29,12 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
28
29
|
#
|
29
30
|
# CopsDocumentationGenerator.new(departments: ['Lint']).call
|
30
31
|
#
|
32
|
+
# For plugin extensions, specify `:plugin_name` keyword as follows:
|
33
|
+
#
|
34
|
+
# CopsDocumentationGenerator.new(
|
35
|
+
# departments: ['Performance'], plugin_name: 'rubocop-performance'
|
36
|
+
# ).call
|
37
|
+
#
|
31
38
|
# You can append additional information:
|
32
39
|
#
|
33
40
|
# callback = ->(data) { required_rails_version(data.cop) }
|
@@ -36,11 +43,16 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
36
43
|
# This will insert the string returned from the lambda _after_ the section from RuboCop itself.
|
37
44
|
# See `CopsDocumentationGenerator::STRUCTURE` for available sections.
|
38
45
|
#
|
39
|
-
def initialize(departments: [], extra_info: {}, base_dir: Dir.pwd)
|
46
|
+
def initialize(departments: [], extra_info: {}, base_dir: Dir.pwd, plugin_name: nil)
|
40
47
|
@departments = departments.map(&:to_sym).sort!
|
41
48
|
@extra_info = extra_info
|
42
49
|
@cops = RuboCop::Cop::Registry.global
|
43
50
|
@config = RuboCop::ConfigLoader.default_configuration
|
51
|
+
# NOTE: For example, this prevents excessive plugin loading before another task executes,
|
52
|
+
# in cases where plugins are already loaded by `internal_investigation`.
|
53
|
+
if plugin_name && @config.loaded_plugins.none? { |plugin| plugin.about.name == plugin_name }
|
54
|
+
RuboCop::Plugin.integrate_plugins(RuboCop::Config.new, [plugin_name])
|
55
|
+
end
|
44
56
|
@base_dir = base_dir
|
45
57
|
@docs_path = "#{base_dir}/docs/modules/ROOT"
|
46
58
|
FileUtils.mkdir_p("#{@docs_path}/pages")
|
@@ -180,17 +192,17 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
180
192
|
content
|
181
193
|
end
|
182
194
|
|
183
|
-
def configurations(department,
|
184
|
-
return '' if pars.empty?
|
185
|
-
|
195
|
+
def configurations(department, cop, cop_config)
|
186
196
|
header = ['Name', 'Default value', 'Configurable values']
|
187
|
-
configs =
|
197
|
+
configs = cop_config
|
188
198
|
.each_key
|
189
199
|
.reject { |key| key.start_with?('Supported') }
|
190
200
|
.reject { |key| key.start_with?('AllowMultipleStyles') }
|
201
|
+
return '' if configs.empty?
|
202
|
+
|
191
203
|
content = configs.map do |name|
|
192
|
-
configurable = configurable_values(
|
193
|
-
default = format_table_value(
|
204
|
+
configurable = configurable_values(cop_config, name)
|
205
|
+
default = format_table_value(cop_config[name])
|
194
206
|
|
195
207
|
[configuration_name(department, name), default, configurable]
|
196
208
|
end
|
@@ -206,17 +218,17 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
206
218
|
end
|
207
219
|
|
208
220
|
# rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
|
209
|
-
def configurable_values(
|
221
|
+
def configurable_values(cop_config, name)
|
210
222
|
case name
|
211
223
|
when /^Enforced/
|
212
224
|
supported_style_name = RuboCop::Cop::Util.to_supported_styles(name)
|
213
|
-
format_table_value(
|
225
|
+
format_table_value(cop_config[supported_style_name])
|
214
226
|
when 'IndentationWidth'
|
215
227
|
'Integer'
|
216
228
|
when 'Database'
|
217
|
-
format_table_value(
|
229
|
+
format_table_value(cop_config['SupportedDatabases'])
|
218
230
|
else
|
219
|
-
case
|
231
|
+
case cop_config[name]
|
220
232
|
when String
|
221
233
|
'String'
|
222
234
|
when Integer
|
@@ -316,10 +328,14 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
316
328
|
def print_cop_with_doc(cop) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
|
317
329
|
cop_config = config.for_cop(cop)
|
318
330
|
non_display_keys = %w[
|
319
|
-
|
320
|
-
|
331
|
+
Enabled
|
332
|
+
Description
|
333
|
+
StyleGuide
|
334
|
+
Reference References
|
335
|
+
Safe SafeAutoCorrect AutoCorrect
|
336
|
+
VersionAdded VersionChanged
|
321
337
|
]
|
322
|
-
|
338
|
+
parameters = cop_config.reject { |k| non_display_keys.include? k }
|
323
339
|
description = 'No documentation'
|
324
340
|
example_objects = safety_objects = see_objects = []
|
325
341
|
cop_code(cop) do |code_object|
|
@@ -329,7 +345,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
329
345
|
see_objects = code_object.tags('see')
|
330
346
|
end
|
331
347
|
data = CopData.new(cop: cop, description: description, example_objects: example_objects,
|
332
|
-
safety_objects: safety_objects, see_objects: see_objects, config:
|
348
|
+
safety_objects: safety_objects, see_objects: see_objects, config: parameters)
|
333
349
|
cops_body(data)
|
334
350
|
end
|
335
351
|
|
@@ -12,16 +12,30 @@ module RuboCop
|
|
12
12
|
# @api private
|
13
13
|
LINT_SYNTAX_COP = "#{LINT_DEPARTMENT}/Syntax"
|
14
14
|
# @api private
|
15
|
-
COP_NAME_PATTERN = '([A-
|
15
|
+
COP_NAME_PATTERN = '([A-Za-z]\w+/)*(?:[A-Za-z]\w+)'
|
16
16
|
# @api private
|
17
17
|
COP_NAMES_PATTERN = "(?:#{COP_NAME_PATTERN} , )*#{COP_NAME_PATTERN}"
|
18
18
|
# @api private
|
19
19
|
COPS_PATTERN = "(all|#{COP_NAMES_PATTERN})"
|
20
20
|
# @api private
|
21
|
+
AVAILABLE_MODES = %w[disable enable todo].freeze
|
22
|
+
# @api private
|
23
|
+
DIRECTIVE_MARKER_PATTERN = '# rubocop : '
|
24
|
+
# @api private
|
25
|
+
DIRECTIVE_MARKER_REGEXP = Regexp.new(DIRECTIVE_MARKER_PATTERN.gsub(' ', '\s*'))
|
26
|
+
# @api private
|
27
|
+
DIRECTIVE_HEADER_PATTERN = "#{DIRECTIVE_MARKER_PATTERN}((?:#{AVAILABLE_MODES.join('|')}))\\b"
|
28
|
+
# @api private
|
21
29
|
DIRECTIVE_COMMENT_REGEXP = Regexp.new(
|
22
|
-
"#
|
30
|
+
"#{DIRECTIVE_HEADER_PATTERN} #{COPS_PATTERN}"
|
23
31
|
.gsub(' ', '\s*')
|
24
32
|
)
|
33
|
+
# @api private
|
34
|
+
TRAILING_COMMENT_MARKER = '--'
|
35
|
+
# @api private
|
36
|
+
MALFORMED_DIRECTIVE_WITHOUT_COP_NAME_REGEXP = Regexp.new(
|
37
|
+
"\\A#{DIRECTIVE_HEADER_PATTERN}\\s*\\z".gsub(' ', '\s*')
|
38
|
+
)
|
25
39
|
|
26
40
|
def self.before_comment(line)
|
27
41
|
line.split(DIRECTIVE_COMMENT_REGEXP).first
|
@@ -32,9 +46,28 @@ module RuboCop
|
|
32
46
|
def initialize(comment, cop_registry = Cop::Registry.global)
|
33
47
|
@comment = comment
|
34
48
|
@cop_registry = cop_registry
|
49
|
+
@match_data = comment.text.match(DIRECTIVE_COMMENT_REGEXP)
|
35
50
|
@mode, @cops = match_captures
|
36
51
|
end
|
37
52
|
|
53
|
+
# Checks if the comment starts with `# rubocop:` marker
|
54
|
+
def start_with_marker?
|
55
|
+
comment.text.start_with?(DIRECTIVE_MARKER_REGEXP)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Checks if the comment is malformed as a `# rubocop:` directive
|
59
|
+
def malformed?
|
60
|
+
return true if !start_with_marker? || @match_data.nil?
|
61
|
+
|
62
|
+
tail = @match_data.post_match.lstrip
|
63
|
+
!(tail.empty? || tail.start_with?(TRAILING_COMMENT_MARKER))
|
64
|
+
end
|
65
|
+
|
66
|
+
# Checks if the directive comment is missing a cop name
|
67
|
+
def missing_cop_name?
|
68
|
+
MALFORMED_DIRECTIVE_WITHOUT_COP_NAME_REGEXP.match?(comment.text)
|
69
|
+
end
|
70
|
+
|
38
71
|
# Checks if this directive relates to single line
|
39
72
|
def single_line?
|
40
73
|
!comment.text.start_with?(DIRECTIVE_COMMENT_REGEXP)
|
@@ -55,7 +88,7 @@ module RuboCop
|
|
55
88
|
|
56
89
|
# Returns match captures to directive comment pattern
|
57
90
|
def match_captures
|
58
|
-
@match_captures ||=
|
91
|
+
@match_captures ||= @match_data&.captures
|
59
92
|
end
|
60
93
|
|
61
94
|
# Checks if this directive disables cops
|
@@ -88,10 +121,15 @@ module RuboCop
|
|
88
121
|
@cop_names ||= all_cops? ? all_cop_names : parsed_cop_names
|
89
122
|
end
|
90
123
|
|
124
|
+
# Returns an array of cops for this directive comment, without resolving departments
|
125
|
+
def raw_cop_names
|
126
|
+
@raw_cop_names ||= (cops || '').split(/,\s*/)
|
127
|
+
end
|
128
|
+
|
91
129
|
# Returns array of specified in this directive department names
|
92
130
|
# when all department disabled
|
93
131
|
def department_names
|
94
|
-
|
132
|
+
raw_cop_names.select { |cop| department?(cop) }
|
95
133
|
end
|
96
134
|
|
97
135
|
# Checks if directive departments include cop
|
@@ -101,11 +139,11 @@ module RuboCop
|
|
101
139
|
|
102
140
|
# Checks if cop department has already used in directive comment
|
103
141
|
def overridden_by_department?(cop)
|
104
|
-
in_directive_department?(cop) &&
|
142
|
+
in_directive_department?(cop) && raw_cop_names.include?(cop)
|
105
143
|
end
|
106
144
|
|
107
145
|
def directive_count
|
108
|
-
|
146
|
+
raw_cop_names.count
|
109
147
|
end
|
110
148
|
|
111
149
|
# Returns line number for directive
|
@@ -115,12 +153,8 @@ module RuboCop
|
|
115
153
|
|
116
154
|
private
|
117
155
|
|
118
|
-
def splitted_cops_string
|
119
|
-
(cops || '').split(/,\s*/)
|
120
|
-
end
|
121
|
-
|
122
156
|
def parsed_cop_names
|
123
|
-
cops =
|
157
|
+
cops = raw_cop_names.map do |name|
|
124
158
|
department?(name) ? cop_names_for_department(name) : name
|
125
159
|
end.flatten
|
126
160
|
cops - [LINT_SYNTAX_COP]
|
@@ -164,7 +164,7 @@ module RuboCop
|
|
164
164
|
|
165
165
|
def cop_config_params(default_cfg, cfg)
|
166
166
|
default_cfg.keys -
|
167
|
-
%w[Description StyleGuide Reference Enabled Exclude Safe
|
167
|
+
%w[Description StyleGuide Reference References Enabled Exclude Safe
|
168
168
|
SafeAutoCorrect VersionAdded VersionChanged VersionRemoved] -
|
169
169
|
cfg.keys
|
170
170
|
end
|
@@ -178,6 +178,7 @@ module RuboCop
|
|
178
178
|
next unless value.is_a?(Array)
|
179
179
|
next if value.empty?
|
180
180
|
|
181
|
+
value.map! { |v| v.nil? ? '~' : v } # Change nil back to ~ as in the YAML file.
|
181
182
|
output_buffer.puts "# #{param}: #{value.uniq.join(', ')}"
|
182
183
|
end
|
183
184
|
end
|
@@ -9,6 +9,7 @@ module RuboCop
|
|
9
9
|
# https://github.com/go-labs/rspec_pacman_formatter
|
10
10
|
class PacmanFormatter < ClangStyleFormatter
|
11
11
|
include TextUtil
|
12
|
+
|
12
13
|
attr_accessor :progress_line
|
13
14
|
|
14
15
|
FALLBACK_TERMINAL_WIDTH = 80
|
@@ -58,7 +59,7 @@ module RuboCop
|
|
58
59
|
return pacdots(@total_files) unless @total_files > cols
|
59
60
|
return pacdots(cols) unless (@total_files / cols).eql?(@repetitions)
|
60
61
|
|
61
|
-
pacdots(
|
62
|
+
pacdots(@total_files - (cols * @repetitions))
|
62
63
|
end
|
63
64
|
|
64
65
|
def pacdots(number)
|
@@ -0,0 +1,189 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'severity'
|
4
|
+
|
5
|
+
#
|
6
|
+
# This code is based on https://github.com/standardrb/standard.
|
7
|
+
#
|
8
|
+
# Copyright (c) 2023 Test Double, Inc.
|
9
|
+
#
|
10
|
+
# The MIT License (MIT)
|
11
|
+
#
|
12
|
+
# https://github.com/standardrb/standard/blob/main/LICENSE.txt
|
13
|
+
#
|
14
|
+
module RuboCop
|
15
|
+
module LSP
|
16
|
+
# Diagnostic for Language Server Protocol of RuboCop.
|
17
|
+
# @api private
|
18
|
+
class Diagnostic
|
19
|
+
def initialize(document_encoding, offense, uri, cop_class)
|
20
|
+
@document_encoding = document_encoding
|
21
|
+
@offense = offense
|
22
|
+
@uri = uri
|
23
|
+
@cop_class = cop_class
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_lsp_code_actions
|
27
|
+
code_actions = []
|
28
|
+
|
29
|
+
code_actions << autocorrect_action if correctable?
|
30
|
+
code_actions << disable_line_action
|
31
|
+
|
32
|
+
code_actions
|
33
|
+
end
|
34
|
+
|
35
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
36
|
+
def to_lsp_diagnostic(config)
|
37
|
+
highlighted = @offense.highlighted_area
|
38
|
+
|
39
|
+
LanguageServer::Protocol::Interface::Diagnostic.new(
|
40
|
+
message: message,
|
41
|
+
source: 'RuboCop',
|
42
|
+
code: @offense.cop_name,
|
43
|
+
code_description: code_description(config),
|
44
|
+
severity: severity,
|
45
|
+
range: LanguageServer::Protocol::Interface::Range.new(
|
46
|
+
start: LanguageServer::Protocol::Interface::Position.new(
|
47
|
+
line: @offense.line - 1,
|
48
|
+
character: highlighted.begin_pos
|
49
|
+
),
|
50
|
+
end: LanguageServer::Protocol::Interface::Position.new(
|
51
|
+
line: @offense.line - 1,
|
52
|
+
character: highlighted.end_pos
|
53
|
+
)
|
54
|
+
),
|
55
|
+
data: {
|
56
|
+
correctable: correctable?,
|
57
|
+
code_actions: to_lsp_code_actions
|
58
|
+
}
|
59
|
+
)
|
60
|
+
end
|
61
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def message
|
66
|
+
message = @offense.message
|
67
|
+
message += "\n\nThis offense is not autocorrectable.\n" unless correctable?
|
68
|
+
message
|
69
|
+
end
|
70
|
+
|
71
|
+
def severity
|
72
|
+
Severity.find_by(@offense.severity.name)
|
73
|
+
end
|
74
|
+
|
75
|
+
def code_description(config)
|
76
|
+
return unless @cop_class
|
77
|
+
return unless (doc_url = @cop_class.documentation_url(config))
|
78
|
+
|
79
|
+
LanguageServer::Protocol::Interface::CodeDescription.new(href: doc_url)
|
80
|
+
end
|
81
|
+
|
82
|
+
# rubocop:disable Metrics/MethodLength
|
83
|
+
def autocorrect_action
|
84
|
+
LanguageServer::Protocol::Interface::CodeAction.new(
|
85
|
+
title: "Autocorrect #{@offense.cop_name}",
|
86
|
+
kind: LanguageServer::Protocol::Constant::CodeActionKind::QUICK_FIX,
|
87
|
+
edit: LanguageServer::Protocol::Interface::WorkspaceEdit.new(
|
88
|
+
document_changes: [
|
89
|
+
LanguageServer::Protocol::Interface::TextDocumentEdit.new(
|
90
|
+
text_document: LanguageServer::Protocol::Interface::OptionalVersionedTextDocumentIdentifier.new(
|
91
|
+
uri: ensure_uri_scheme(@uri.to_s).to_s,
|
92
|
+
version: nil
|
93
|
+
),
|
94
|
+
edits: correctable? ? offense_replacements : []
|
95
|
+
)
|
96
|
+
]
|
97
|
+
),
|
98
|
+
is_preferred: true
|
99
|
+
)
|
100
|
+
end
|
101
|
+
# rubocop:enable Metrics/MethodLength
|
102
|
+
|
103
|
+
# rubocop:disable Metrics/MethodLength
|
104
|
+
def offense_replacements
|
105
|
+
@offense.corrector.as_replacements.map do |range, replacement|
|
106
|
+
LanguageServer::Protocol::Interface::TextEdit.new(
|
107
|
+
range: LanguageServer::Protocol::Interface::Range.new(
|
108
|
+
start: LanguageServer::Protocol::Interface::Position.new(
|
109
|
+
line: range.line - 1,
|
110
|
+
character: range.column
|
111
|
+
),
|
112
|
+
end: LanguageServer::Protocol::Interface::Position.new(
|
113
|
+
line: range.last_line - 1,
|
114
|
+
character: range.last_column
|
115
|
+
)
|
116
|
+
),
|
117
|
+
new_text: replacement
|
118
|
+
)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
# rubocop:enable Metrics/MethodLength
|
122
|
+
|
123
|
+
# rubocop:disable Metrics/MethodLength
|
124
|
+
def disable_line_action
|
125
|
+
LanguageServer::Protocol::Interface::CodeAction.new(
|
126
|
+
title: "Disable #{@offense.cop_name} for this line",
|
127
|
+
kind: LanguageServer::Protocol::Constant::CodeActionKind::QUICK_FIX,
|
128
|
+
edit: LanguageServer::Protocol::Interface::WorkspaceEdit.new(
|
129
|
+
document_changes: [
|
130
|
+
LanguageServer::Protocol::Interface::TextDocumentEdit.new(
|
131
|
+
text_document: LanguageServer::Protocol::Interface::OptionalVersionedTextDocumentIdentifier.new(
|
132
|
+
uri: ensure_uri_scheme(@uri.to_s).to_s,
|
133
|
+
version: nil
|
134
|
+
),
|
135
|
+
edits: line_disable_comment
|
136
|
+
)
|
137
|
+
]
|
138
|
+
)
|
139
|
+
)
|
140
|
+
end
|
141
|
+
# rubocop:enable Metrics/MethodLength
|
142
|
+
|
143
|
+
def line_disable_comment
|
144
|
+
new_text = if @offense.source_line.include?(' # rubocop:disable ')
|
145
|
+
",#{@offense.cop_name}"
|
146
|
+
else
|
147
|
+
" # rubocop:disable #{@offense.cop_name}"
|
148
|
+
end
|
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]
|
163
|
+
end
|
164
|
+
|
165
|
+
def length_of_line(line)
|
166
|
+
if @document_encoding == Encoding::UTF_16LE
|
167
|
+
line_length = 0
|
168
|
+
line.codepoints.each do |codepoint|
|
169
|
+
line_length += 1
|
170
|
+
line_length += 1 if codepoint > RubyLsp::Document::Scanner::SURROGATE_PAIR_START
|
171
|
+
end
|
172
|
+
line_length
|
173
|
+
else
|
174
|
+
line.length
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def correctable?
|
179
|
+
!@offense.corrector.nil?
|
180
|
+
end
|
181
|
+
|
182
|
+
def ensure_uri_scheme(uri)
|
183
|
+
uri = URI.parse(uri)
|
184
|
+
uri.scheme = 'file' if uri.scheme.nil?
|
185
|
+
uri
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|