rubocop 1.67.0 → 1.81.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +23 -19
- data/config/default.yml +384 -72
- data/config/internal_affairs.yml +20 -0
- data/config/obsoletion.yml +8 -3
- data/exe/rubocop +1 -8
- data/lib/rubocop/cached_data.rb +12 -4
- data/lib/rubocop/cli/command/auto_generate_config.rb +2 -2
- data/lib/rubocop/cli/command/execute_runner.rb +4 -4
- data/lib/rubocop/cli/command/show_cops.rb +24 -2
- data/lib/rubocop/cli/command/suggest_extensions.rb +7 -1
- data/lib/rubocop/cli/command/version.rb +2 -2
- data/lib/rubocop/cli.rb +19 -4
- data/lib/rubocop/comment_config.rb +2 -2
- data/lib/rubocop/config.rb +52 -10
- data/lib/rubocop/config_loader.rb +56 -48
- data/lib/rubocop/config_loader_resolver.rb +41 -14
- 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_store.rb +5 -0
- data/lib/rubocop/config_validator.rb +25 -14
- data/lib/rubocop/cop/autocorrect_logic.rb +53 -28
- data/lib/rubocop/cop/base.rb +7 -1
- 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/gem_filename.rb +0 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +0 -1
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +8 -16
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +8 -3
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +5 -2
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +10 -0
- data/lib/rubocop/cop/gemspec/attribute_assignment.rb +91 -0
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +1 -2
- 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/gemspec/required_ruby_version.rb +0 -2
- 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 +3 -4
- 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 +233 -0
- data/lib/rubocop/cop/internal_affairs/node_type_group.rb +92 -0
- data/lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb +126 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +4 -3
- data/lib/rubocop/cop/internal_affairs/numblock_handler.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +90 -0
- data/lib/rubocop/cop/internal_affairs/operator_keyword.rb +48 -0
- data/lib/rubocop/cop/internal_affairs/plugin.rb +33 -0
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +6 -5
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +3 -1
- data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +5 -4
- data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +0 -2
- data/lib/rubocop/cop/internal_affairs/undefined_config.rb +13 -2
- data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +1 -1
- data/lib/rubocop/cop/internal_affairs.rb +7 -16
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/argument_alignment.rb +2 -9
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/begin_end_alignment.rb +0 -1
- data/lib/rubocop/cop/layout/block_alignment.rb +3 -2
- data/lib/rubocop/cop/layout/block_end_newline.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +45 -10
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -5
- data/lib/rubocop/cop/layout/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 +3 -3
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +34 -20
- data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +101 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +37 -7
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +8 -29
- data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +5 -6
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +1 -0
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +4 -5
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +23 -1
- 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 +10 -11
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +8 -7
- data/lib/rubocop/cop/layout/leading_comment_space.rb +57 -2
- 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 +158 -10
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +25 -0
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +2 -1
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +4 -4
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +11 -8
- data/lib/rubocop/cop/layout/parameter_alignment.rb +3 -4
- data/lib/rubocop/cop/layout/redundant_line_break.rb +19 -46
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +14 -7
- 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 +8 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +31 -21
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -0
- data/lib/rubocop/cop/layout/space_before_brackets.rb +7 -40
- data/lib/rubocop/cop/layout/space_before_comma.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_semicolon.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +18 -3
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +5 -0
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +7 -0
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +0 -1
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +6 -4
- 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 +10 -12
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +4 -1
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +3 -3
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +3 -2
- data/lib/rubocop/cop/lint/constant_reassignment.rb +148 -0
- data/lib/rubocop/cop/lint/cop_directive_syntax.rb +90 -0
- data/lib/rubocop/cop/lint/debugger.rb +3 -5
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +7 -3
- data/lib/rubocop/cop/lint/duplicate_branch.rb +39 -4
- 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 +6 -43
- 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_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/empty_expression.rb +0 -2
- data/lib/rubocop/cop/lint/empty_file.rb +0 -2
- data/lib/rubocop/cop/lint/empty_interpolation.rb +14 -1
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +0 -6
- data/lib/rubocop/cop/lint/float_comparison.rb +51 -18
- data/lib/rubocop/cop/lint/float_out_of_range.rb +2 -4
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +2 -2
- data/lib/rubocop/cop/lint/hash_new_with_keyword_arguments_as_default.rb +55 -0
- data/lib/rubocop/cop/lint/identity_comparison.rb +19 -15
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/interpolation_check.rb +9 -0
- data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +3 -0
- data/lib/rubocop/cop/lint/literal_as_condition.rb +125 -10
- data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +24 -6
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +17 -8
- data/lib/rubocop/cop/lint/missing_super.rb +2 -2
- data/lib/rubocop/cop/lint/mixed_case_range.rb +5 -8
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +10 -6
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
- data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +2 -2
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +12 -3
- 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/number_conversion.rb +0 -1
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +1 -2
- data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +94 -0
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +2 -3
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +3 -2
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -5
- data/lib/rubocop/cop/lint/raise_exception.rb +29 -10
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +1 -1
- 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 +113 -9
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +8 -7
- 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/regexp_as_condition.rb +0 -1
- data/lib/rubocop/cop/lint/require_range_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +2 -5
- data/lib/rubocop/cop/lint/rescue_type.rb +4 -8
- data/lib/rubocop/cop/lint/return_in_void_context.rb +9 -11
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +17 -1
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +5 -1
- data/lib/rubocop/cop/lint/self_assignment.rb +39 -15
- data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
- data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +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 +88 -0
- 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/unused_method_argument.rb +18 -2
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
- 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_defined.rb +55 -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 +2 -2
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +5 -5
- data/lib/rubocop/cop/lint/useless_setter_call.rb +14 -25
- data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +121 -0
- data/lib/rubocop/cop/lint/void.rb +23 -12
- 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 +5 -2
- 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/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +3 -4
- 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_assignment.rb +4 -12
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +22 -12
- data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +49 -0
- data/lib/rubocop/cop/mixin/comments_help.rb +8 -3
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/dig_help.rb +27 -0
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
- data/lib/rubocop/cop/mixin/endless_method_rewriter.rb +24 -0
- data/lib/rubocop/cop/mixin/forbidden_identifiers.rb +20 -0
- data/lib/rubocop/cop/mixin/forbidden_pattern.rb +16 -0
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +4 -3
- 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 +7 -9
- 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 -4
- 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 +17 -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 +20 -16
- data/lib/rubocop/cop/naming/constant_name.rb +6 -7
- data/lib/rubocop/cop/naming/file_name.rb +2 -4
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +12 -13
- data/lib/rubocop/cop/naming/method_name.rb +187 -15
- data/lib/rubocop/cop/naming/predicate_method.rb +319 -0
- data/lib/rubocop/cop/naming/{predicate_name.rb → predicate_prefix.rb} +48 -4
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +6 -14
- data/lib/rubocop/cop/naming/variable_name.rb +50 -6
- data/lib/rubocop/cop/naming/variable_number.rb +2 -3
- data/lib/rubocop/cop/offense.rb +2 -3
- 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/json_load.rb +33 -11
- 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 +114 -34
- data/lib/rubocop/cop/style/accessor_grouping.rb +32 -6
- data/lib/rubocop/cop/style/ambiguous_endless_method_definition.rb +79 -0
- data/lib/rubocop/cop/style/and_or.rb +1 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +57 -44
- data/lib/rubocop/cop/style/array_first_last.rb +18 -2
- data/lib/rubocop/cop/style/array_intersect.rb +115 -39
- data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -0
- data/lib/rubocop/cop/style/bitwise_predicate.rb +107 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +44 -26
- data/lib/rubocop/cop/style/case_like_if.rb +9 -12
- 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 +115 -0
- 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 +20 -3
- 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 +49 -31
- data/lib/rubocop/cop/style/constant_visibility.rb +16 -20
- 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 +89 -0
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +5 -5
- 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 +17 -4
- data/lib/rubocop/cop/style/exponential_notation.rb +6 -5
- data/lib/rubocop/cop/style/fetch_env_var.rb +34 -7
- data/lib/rubocop/cop/style/file_null.rb +89 -0
- data/lib/rubocop/cop/style/file_touch.rb +75 -0
- data/lib/rubocop/cop/style/float_division.rb +23 -5
- data/lib/rubocop/cop/style/for.rb +1 -1
- 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/global_vars.rb +1 -3
- data/lib/rubocop/cop/style/guard_clause.rb +17 -3
- data/lib/rubocop/cop/style/hash_conversion.rb +16 -9
- 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 -14
- 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 +3 -4
- data/lib/rubocop/cop/style/if_with_semicolon.rb +20 -9
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +16 -13
- 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_arguments_merging.rb +67 -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 -4
- data/lib/rubocop/cop/style/line_end_concatenation.rb +10 -4
- data/lib/rubocop/cop/style/map_into_array.rb +11 -3
- 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 +28 -20
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +18 -0
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +8 -11
- 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/missing_respond_to_missing.rb +33 -3
- data/lib/rubocop/cop/style/multiline_block_chain.rb +3 -2
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -0
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -9
- data/lib/rubocop/cop/style/multiple_comparison.rb +52 -51
- data/lib/rubocop/cop/style/mutable_constant.rb +7 -8
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +7 -5
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +5 -4
- data/lib/rubocop/cop/style/next.rb +44 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +9 -7
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/object_then.rb +15 -15
- data/lib/rubocop/cop/style/one_line_conditional.rb +42 -13
- data/lib/rubocop/cop/style/open_struct_use.rb +5 -5
- data/lib/rubocop/cop/style/operator_method_call.rb +5 -6
- data/lib/rubocop/cop/style/or_assignment.rb +3 -6
- data/lib/rubocop/cop/style/parallel_assignment.rb +41 -38
- 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 +15 -13
- 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_assignment.rb +1 -1
- data/lib/rubocop/cop/style/redundant_begin.rb +36 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +95 -23
- 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 +283 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +4 -4
- data/lib/rubocop/cop/style/redundant_initialize.rb +12 -3
- data/lib/rubocop/cop/style/redundant_interpolation.rb +12 -3
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +55 -19
- data/lib/rubocop/cop/style/redundant_parentheses.rb +105 -36
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +8 -0
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +9 -1
- data/lib/rubocop/cop/style/redundant_return.rb +2 -2
- data/lib/rubocop/cop/style/redundant_self.rb +15 -18
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +20 -32
- data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +4 -4
- data/lib/rubocop/cop/style/redundant_sort.rb +3 -3
- 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 +5 -3
- data/lib/rubocop/cop/style/return_nil.rb +2 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +75 -16
- data/lib/rubocop/cop/style/safe_navigation_chain_length.rb +52 -0
- data/lib/rubocop/cop/style/select_by_regexp.rb +5 -2
- data/lib/rubocop/cop/style/self_assignment.rb +11 -17
- data/lib/rubocop/cop/style/semicolon.rb +24 -8
- data/lib/rubocop/cop/style/send_with_literal_method_name.rb +2 -1
- data/lib/rubocop/cop/style/signal_exception.rb +2 -3
- data/lib/rubocop/cop/style/single_argument_dig.rb +9 -5
- data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +15 -4
- 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 +75 -102
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/string_concatenation.rb +21 -17
- data/lib/rubocop/cop/style/string_literals.rb +1 -1
- data/lib/rubocop/cop/style/string_methods.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +8 -1
- data/lib/rubocop/cop/style/super_arguments.rb +66 -19
- data/lib/rubocop/cop/style/swap_values.rb +4 -15
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +3 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +25 -4
- data/lib/rubocop/cop/style/top_level_method_definition.rb +2 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +56 -2
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +47 -6
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +48 -6
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +4 -4
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_else.rb +10 -9
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -2
- 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 +20 -5
- data/lib/rubocop/cop/variable_force/assignment.rb +24 -5
- data/lib/rubocop/cop/variable_force/branch.rb +1 -1
- data/lib/rubocop/cop/variable_force/scope.rb +1 -1
- data/lib/rubocop/cop/variable_force/variable.rb +14 -3
- data/lib/rubocop/cop/variable_force/variable_table.rb +5 -5
- data/lib/rubocop/cop/variable_force.rb +30 -19
- data/lib/rubocop/cops_documentation_generator.rb +54 -28
- 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 +20 -6
- 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 +190 -0
- data/lib/rubocop/lsp/logger.rb +2 -2
- data/lib/rubocop/lsp/routes.rb +66 -26
- data/lib/rubocop/lsp/runtime.rb +18 -50
- data/lib/rubocop/lsp/server.rb +2 -4
- data/lib/rubocop/lsp/stdin_runner.rb +69 -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 +27 -25
- 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 +31 -18
- 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 +14 -9
- data/lib/rubocop/target_ruby.rb +27 -3
- data/lib/rubocop/version.rb +53 -12
- data/lib/rubocop.rb +44 -2
- data/lib/ruby_lsp/rubocop/addon.rb +90 -0
- data/lib/ruby_lsp/rubocop/runtime_adapter.rb +99 -0
- metadata +91 -21
- data/lib/rubocop/cop/utils/regexp_ranges.rb +0 -113
- data/lib/rubocop/rspec/host_environment_simulation_helper.rb +0 -28
data/lib/rubocop/lsp/routes.rb
CHANGED
|
@@ -15,7 +15,12 @@ module RuboCop
|
|
|
15
15
|
module LSP
|
|
16
16
|
# Routes for Language Server Protocol of RuboCop.
|
|
17
17
|
# @api private
|
|
18
|
-
class Routes
|
|
18
|
+
class Routes # rubocop:disable Metrics/ClassLength
|
|
19
|
+
CONFIGURATION_FILE_PATTERNS = [
|
|
20
|
+
RuboCop::ConfigFinder::DOTFILE,
|
|
21
|
+
RuboCop::CLI::Command::AutoGenerateConfig::AUTO_GENERATED_FILE
|
|
22
|
+
].freeze
|
|
23
|
+
|
|
19
24
|
def self.handle(name, &block)
|
|
20
25
|
define_method(:"handle_#{name}", &block)
|
|
21
26
|
end
|
|
@@ -37,6 +42,7 @@ module RuboCop
|
|
|
37
42
|
|
|
38
43
|
handle 'initialize' do |request|
|
|
39
44
|
initialization_options = extract_initialization_options_from(request)
|
|
45
|
+
@position_encoding = initialization_options[:position_encoding]
|
|
40
46
|
|
|
41
47
|
@server.configure(initialization_options)
|
|
42
48
|
|
|
@@ -46,9 +52,10 @@ module RuboCop
|
|
|
46
52
|
capabilities: LanguageServer::Protocol::Interface::ServerCapabilities.new(
|
|
47
53
|
document_formatting_provider: true,
|
|
48
54
|
text_document_sync: LanguageServer::Protocol::Interface::TextDocumentSyncOptions.new(
|
|
49
|
-
change: LanguageServer::Protocol::Constant::TextDocumentSyncKind::
|
|
55
|
+
change: LanguageServer::Protocol::Constant::TextDocumentSyncKind::INCREMENTAL,
|
|
50
56
|
open_close: true
|
|
51
|
-
)
|
|
57
|
+
),
|
|
58
|
+
position_encoding: @position_encoding
|
|
52
59
|
)
|
|
53
60
|
)
|
|
54
61
|
)
|
|
@@ -71,7 +78,12 @@ module RuboCop
|
|
|
71
78
|
|
|
72
79
|
handle 'textDocument/didChange' do |request|
|
|
73
80
|
params = request[:params]
|
|
74
|
-
|
|
81
|
+
file_uri = params[:textDocument][:uri]
|
|
82
|
+
text = @text_cache[file_uri]
|
|
83
|
+
params[:contentChanges].each do |content|
|
|
84
|
+
text = change_text(text, content[:text], content[:range])
|
|
85
|
+
end
|
|
86
|
+
result = diagnostic(file_uri, text)
|
|
75
87
|
@server.write(result)
|
|
76
88
|
end
|
|
77
89
|
|
|
@@ -96,7 +108,7 @@ module RuboCop
|
|
|
96
108
|
|
|
97
109
|
handle 'workspace/didChangeWatchedFiles' do |request|
|
|
98
110
|
changed = request[:params][:changes].any? do |change|
|
|
99
|
-
change[:uri].end_with?(
|
|
111
|
+
CONFIGURATION_FILE_PATTERNS.any? { |path| change[:uri].end_with?(path) }
|
|
100
112
|
end
|
|
101
113
|
|
|
102
114
|
if changed
|
|
@@ -174,14 +186,26 @@ module RuboCop
|
|
|
174
186
|
|
|
175
187
|
def extract_initialization_options_from(request)
|
|
176
188
|
safe_autocorrect = request.dig(:params, :initializationOptions, :safeAutocorrect)
|
|
189
|
+
position_encodings = request.dig(:params, :capabilities, :general, :positionEncodings)
|
|
177
190
|
|
|
178
191
|
{
|
|
179
192
|
safe_autocorrect: safe_autocorrect.nil? || safe_autocorrect == true,
|
|
180
193
|
lint_mode: request.dig(:params, :initializationOptions, :lintMode) == true,
|
|
181
|
-
layout_mode: request.dig(:params, :initializationOptions, :layoutMode) == true
|
|
194
|
+
layout_mode: request.dig(:params, :initializationOptions, :layoutMode) == true,
|
|
195
|
+
position_encoding: position_encoding(position_encodings)
|
|
182
196
|
}
|
|
183
197
|
end
|
|
184
198
|
|
|
199
|
+
def position_encoding(position_encodings)
|
|
200
|
+
if position_encodings&.include?('utf-8')
|
|
201
|
+
'utf-8'
|
|
202
|
+
elsif position_encodings&.include?('utf-32')
|
|
203
|
+
'utf-32'
|
|
204
|
+
else
|
|
205
|
+
'utf-16'
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
185
209
|
def format_file(file_uri, command: nil)
|
|
186
210
|
unless (text = @text_cache[file_uri])
|
|
187
211
|
Logger.log("Format request arrived before text synchronized; skipping: `#{file_uri}'")
|
|
@@ -189,7 +213,7 @@ module RuboCop
|
|
|
189
213
|
return []
|
|
190
214
|
end
|
|
191
215
|
|
|
192
|
-
new_text = @server.format(
|
|
216
|
+
new_text = @server.format(convert_file_uri_to_path(file_uri), text, command: command)
|
|
193
217
|
|
|
194
218
|
return [] if new_text == text
|
|
195
219
|
|
|
@@ -204,39 +228,55 @@ module RuboCop
|
|
|
204
228
|
|
|
205
229
|
def diagnostic(file_uri, text)
|
|
206
230
|
@text_cache[file_uri] = text
|
|
207
|
-
offenses = @server.offenses(remove_file_protocol_from(file_uri), text)
|
|
208
|
-
diagnostics = offenses.map { |offense| to_diagnostic(offense) }
|
|
209
231
|
|
|
210
232
|
{
|
|
211
233
|
method: 'textDocument/publishDiagnostics',
|
|
212
234
|
params: {
|
|
213
235
|
uri: file_uri,
|
|
214
|
-
diagnostics:
|
|
236
|
+
diagnostics: @server.offenses(convert_file_uri_to_path(file_uri),
|
|
237
|
+
text, @position_encoding)
|
|
215
238
|
}
|
|
216
239
|
}
|
|
217
240
|
end
|
|
218
241
|
|
|
219
|
-
def
|
|
220
|
-
|
|
242
|
+
def change_text(orig_text, text, range)
|
|
243
|
+
return text unless range
|
|
244
|
+
|
|
245
|
+
start_pos = text_pos(orig_text, range[:start])
|
|
246
|
+
end_pos = text_pos(orig_text, range[:end])
|
|
247
|
+
orig_text[start_pos...end_pos] = text
|
|
248
|
+
orig_text
|
|
221
249
|
end
|
|
222
250
|
|
|
223
|
-
def
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
251
|
+
def text_pos(text, range)
|
|
252
|
+
line = range[:line]
|
|
253
|
+
char = range[:character]
|
|
254
|
+
pos = 0
|
|
255
|
+
text.each_line.with_index do |l, i|
|
|
256
|
+
if i == line
|
|
257
|
+
pos += line_pos(l, char)
|
|
258
|
+
return pos
|
|
259
|
+
end
|
|
260
|
+
pos += l.size
|
|
261
|
+
end
|
|
262
|
+
pos
|
|
263
|
+
end
|
|
229
264
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
265
|
+
def line_pos(line, char)
|
|
266
|
+
case @position_encoding
|
|
267
|
+
when 'utf-8'
|
|
268
|
+
line.byteslice(0, char).size
|
|
269
|
+
when 'utf-32'
|
|
270
|
+
char
|
|
271
|
+
else # 'utf-16'
|
|
272
|
+
# utf-16 is default position encoding on LSP
|
|
273
|
+
# https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/
|
|
274
|
+
line.encode('utf-16be').byteslice(0, char * 2).size
|
|
275
|
+
end
|
|
233
276
|
end
|
|
234
277
|
|
|
235
|
-
def
|
|
236
|
-
|
|
237
|
-
start: { character: location[:start_column] - 1, line: location[:start_line] - 1 },
|
|
238
|
-
end: { character: location[:last_column], line: location[:last_line] - 1 }
|
|
239
|
-
}
|
|
278
|
+
def convert_file_uri_to_path(uri)
|
|
279
|
+
URI.decode_www_form_component(uri.delete_prefix('file://'))
|
|
240
280
|
end
|
|
241
281
|
end
|
|
242
282
|
end
|
data/lib/rubocop/lsp/runtime.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative 'diagnostic'
|
|
4
|
+
require_relative 'stdin_runner'
|
|
4
5
|
|
|
5
6
|
#
|
|
6
7
|
# This code is based on https://github.com/standardrb/standard.
|
|
@@ -19,59 +20,40 @@ module RuboCop
|
|
|
19
20
|
attr_writer :safe_autocorrect, :lint_mode, :layout_mode
|
|
20
21
|
|
|
21
22
|
def initialize(config_store)
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
RuboCop::LSP.enable
|
|
24
|
+
|
|
25
|
+
@runner = RuboCop::Lsp::StdinRunner.new(config_store)
|
|
26
|
+
@cop_registry = RuboCop::Cop::Registry.global.to_h
|
|
27
|
+
|
|
24
28
|
@safe_autocorrect = true
|
|
25
29
|
@lint_mode = false
|
|
26
30
|
@layout_mode = false
|
|
27
31
|
end
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
# from the `options[:stdin]` that rubocop mutates. This depends on
|
|
31
|
-
# `parallel: false` as well as the fact that RuboCop doesn't otherwise dup
|
|
32
|
-
# or reassign that options object. Risky business!
|
|
33
|
-
#
|
|
34
|
-
# Reassigning `options[:stdin]` is done here:
|
|
35
|
-
# https://github.com/rubocop/rubocop/blob/v1.52.0/lib/rubocop/cop/team.rb#L131
|
|
36
|
-
# Printing `options[:stdin]`
|
|
37
|
-
# https://github.com/rubocop/rubocop/blob/v1.52.0/lib/rubocop/cli/command/execute_runner.rb#L95
|
|
38
|
-
# Setting `parallel: true` would break this here:
|
|
39
|
-
# https://github.com/rubocop/rubocop/blob/v1.52.0/lib/rubocop/runner.rb#L72
|
|
40
|
-
def format(path, text, command:)
|
|
33
|
+
def format(path, text, command:, prism_result: nil)
|
|
41
34
|
safe_autocorrect = if command
|
|
42
35
|
command == 'rubocop.formatAutocorrects'
|
|
43
36
|
else
|
|
44
37
|
@safe_autocorrect
|
|
45
38
|
end
|
|
46
39
|
|
|
47
|
-
formatting_options = {
|
|
48
|
-
stdin: text, force_exclusion: true, autocorrect: true, safe_autocorrect: safe_autocorrect
|
|
49
|
-
}
|
|
40
|
+
formatting_options = { autocorrect: true, safe_autocorrect: safe_autocorrect }
|
|
50
41
|
formatting_options[:only] = config_only_options if @lint_mode || @layout_mode
|
|
51
42
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
formatting_options[:stdin]
|
|
43
|
+
@runner.run(path, text, formatting_options, prism_result: prism_result)
|
|
44
|
+
@runner.formatted_source
|
|
55
45
|
end
|
|
56
46
|
|
|
57
|
-
def offenses(path, text)
|
|
58
|
-
diagnostic_options = {
|
|
59
|
-
stdin: text, force_exclusion: true, formatters: ['json'], format: 'json'
|
|
60
|
-
}
|
|
47
|
+
def offenses(path, text, position_encoding, prism_result: nil)
|
|
48
|
+
diagnostic_options = {}
|
|
61
49
|
diagnostic_options[:only] = config_only_options if @lint_mode || @layout_mode
|
|
62
50
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
Logger.log "Ignoring file, per configuration: #{path}"
|
|
69
|
-
@logged_paths << path
|
|
70
|
-
end
|
|
71
|
-
return []
|
|
51
|
+
@runner.run(path, text, diagnostic_options, prism_result: prism_result)
|
|
52
|
+
@runner.offenses.map do |offense|
|
|
53
|
+
Diagnostic.new(
|
|
54
|
+
position_encoding, offense, path, @cop_registry[offense.cop_name]&.first
|
|
55
|
+
).to_lsp_diagnostic(@runner.config_for_working_directory)
|
|
72
56
|
end
|
|
73
|
-
|
|
74
|
-
results.dig(:files, 0, :offenses)
|
|
75
57
|
end
|
|
76
58
|
|
|
77
59
|
private
|
|
@@ -82,20 +64,6 @@ module RuboCop
|
|
|
82
64
|
only_options << 'Layout' if @layout_mode
|
|
83
65
|
only_options
|
|
84
66
|
end
|
|
85
|
-
|
|
86
|
-
def redirect_stdout(&block)
|
|
87
|
-
stdout = StringIO.new
|
|
88
|
-
|
|
89
|
-
RuboCop::Server::Helper.redirect(stdout: stdout, &block)
|
|
90
|
-
|
|
91
|
-
stdout.string
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def run_rubocop(options, path)
|
|
95
|
-
runner = RuboCop::Runner.new(options, @config_store)
|
|
96
|
-
|
|
97
|
-
runner.run([path])
|
|
98
|
-
end
|
|
99
67
|
end
|
|
100
68
|
end
|
|
101
69
|
end
|
data/lib/rubocop/lsp/server.rb
CHANGED
|
@@ -22,8 +22,6 @@ module RuboCop
|
|
|
22
22
|
def initialize(config_store)
|
|
23
23
|
$PROGRAM_NAME = "rubocop --lsp #{ConfigFinder.project_root}"
|
|
24
24
|
|
|
25
|
-
RuboCop::LSP.enable
|
|
26
|
-
|
|
27
25
|
@reader = LanguageServer::Protocol::Transport::Io::Reader.new($stdin)
|
|
28
26
|
@writer = LanguageServer::Protocol::Transport::Io::Writer.new($stdout)
|
|
29
27
|
@runtime = RuboCop::LSP::Runtime.new(config_store)
|
|
@@ -53,8 +51,8 @@ module RuboCop
|
|
|
53
51
|
@runtime.format(path, text, command: command)
|
|
54
52
|
end
|
|
55
53
|
|
|
56
|
-
def offenses(path, text)
|
|
57
|
-
@runtime.offenses(path, text)
|
|
54
|
+
def offenses(path, text, position_encoding)
|
|
55
|
+
@runtime.offenses(path, text, position_encoding)
|
|
58
56
|
end
|
|
59
57
|
|
|
60
58
|
def configure(options)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# This code is based on https://github.com/standardrb/standard.
|
|
5
|
+
#
|
|
6
|
+
# Copyright (c) 2023 Test Double, Inc.
|
|
7
|
+
#
|
|
8
|
+
# The MIT License (MIT)
|
|
9
|
+
#
|
|
10
|
+
# https://github.com/standardrb/standard/blob/main/LICENSE.txt
|
|
11
|
+
#
|
|
12
|
+
module RuboCop
|
|
13
|
+
module Lsp
|
|
14
|
+
# Originally lifted from:
|
|
15
|
+
# https://github.com/Shopify/ruby-lsp/blob/8d4c17efce4e8ecc8e7c557ab2981db6b22c0b6d/lib/ruby_lsp/requests/support/rubocop_runner.rb#L20
|
|
16
|
+
# @api private
|
|
17
|
+
class StdinRunner < RuboCop::Runner
|
|
18
|
+
class ConfigurationError < StandardError; end
|
|
19
|
+
|
|
20
|
+
attr_reader :offenses, :config_for_working_directory
|
|
21
|
+
|
|
22
|
+
DEFAULT_RUBOCOP_OPTIONS = {
|
|
23
|
+
stderr: true,
|
|
24
|
+
force_exclusion: true,
|
|
25
|
+
formatters: ['RuboCop::Formatter::BaseFormatter'],
|
|
26
|
+
raise_cop_error: true,
|
|
27
|
+
todo_file: nil,
|
|
28
|
+
todo_ignore_files: []
|
|
29
|
+
}.freeze
|
|
30
|
+
|
|
31
|
+
def initialize(config_store)
|
|
32
|
+
@options = {}
|
|
33
|
+
|
|
34
|
+
@offenses = []
|
|
35
|
+
@warnings = []
|
|
36
|
+
@errors = []
|
|
37
|
+
|
|
38
|
+
@config_for_working_directory = config_store.for_pwd
|
|
39
|
+
|
|
40
|
+
super(@options, config_store)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def run(path, contents, options, prism_result: nil)
|
|
44
|
+
@options = options.merge(DEFAULT_RUBOCOP_OPTIONS)
|
|
45
|
+
@options[:stdin] = contents
|
|
46
|
+
|
|
47
|
+
@prism_result = prism_result
|
|
48
|
+
|
|
49
|
+
@offenses = []
|
|
50
|
+
@warnings = []
|
|
51
|
+
@errors = []
|
|
52
|
+
|
|
53
|
+
super([path])
|
|
54
|
+
|
|
55
|
+
raise Interrupt if aborting?
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def formatted_source
|
|
59
|
+
@options[:stdin]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def file_finished(_file, offenses)
|
|
65
|
+
@offenses = offenses
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -80,13 +80,13 @@ module RuboCop
|
|
|
80
80
|
|
|
81
81
|
# Expose the `frozen_string_literal` value coerced to a boolean if possible.
|
|
82
82
|
#
|
|
83
|
-
# @return [Boolean] if value is `true` or `false`
|
|
83
|
+
# @return [Boolean] if value is `true` or `false` in any case
|
|
84
84
|
# @return [nil] if frozen_string_literal comment isn't found
|
|
85
85
|
# @return [String] if comment is found but isn't true or false
|
|
86
86
|
def frozen_string_literal
|
|
87
87
|
return unless (setting = extract_frozen_string_literal)
|
|
88
88
|
|
|
89
|
-
case setting
|
|
89
|
+
case setting.downcase
|
|
90
90
|
when 'true' then true
|
|
91
91
|
when 'false' then false
|
|
92
92
|
else
|
|
@@ -193,6 +193,10 @@ module RuboCop
|
|
|
193
193
|
SEPARATOR = ';'
|
|
194
194
|
OPERATOR = ':'
|
|
195
195
|
|
|
196
|
+
def new_frozen_string_literal(value)
|
|
197
|
+
"# -*- frozen_string_literal: #{value} -*-"
|
|
198
|
+
end
|
|
199
|
+
|
|
196
200
|
private
|
|
197
201
|
|
|
198
202
|
def extract_frozen_string_literal
|
|
@@ -275,6 +279,10 @@ module RuboCop
|
|
|
275
279
|
end
|
|
276
280
|
end
|
|
277
281
|
|
|
282
|
+
def new_frozen_string_literal(value)
|
|
283
|
+
"# frozen_string_literal: #{value}"
|
|
284
|
+
end
|
|
285
|
+
|
|
278
286
|
private
|
|
279
287
|
|
|
280
288
|
# Extract `frozen_string_literal`.
|
|
@@ -283,7 +291,7 @@ module RuboCop
|
|
|
283
291
|
# is the only text in the comment.
|
|
284
292
|
#
|
|
285
293
|
# Case-insensitive and dashes/underscores are acceptable.
|
|
286
|
-
# @see https://github.com/ruby/ruby/blob/
|
|
294
|
+
# @see https://github.com/ruby/ruby/blob/78b95b49f8/parse.y#L7134-L7138
|
|
287
295
|
def extract_frozen_string_literal
|
|
288
296
|
extract(/\A\s*#\s*#{KEYWORDS[:frozen_string_literal]}:\s*#{TOKEN}\s*\z/io)
|
|
289
297
|
end
|
data/lib/rubocop/options.rb
CHANGED
|
@@ -243,6 +243,7 @@ module RuboCop
|
|
|
243
243
|
option(opts, '--init')
|
|
244
244
|
option(opts, '-c', '--config FILE')
|
|
245
245
|
option(opts, '-d', '--debug')
|
|
246
|
+
option(opts, '--plugin FILE') { |f| plugin_feature(f) }
|
|
246
247
|
option(opts, '-r', '--require FILE') { |f| require_feature(f) }
|
|
247
248
|
option(opts, '--[no-]color')
|
|
248
249
|
option(opts, '-v', '--version')
|
|
@@ -299,11 +300,25 @@ module RuboCop
|
|
|
299
300
|
long_opt[2..].sub('[no-]', '').sub(/ .*/, '').tr('-', '_').gsub(/[\[\]]/, '').to_sym
|
|
300
301
|
end
|
|
301
302
|
|
|
302
|
-
def
|
|
303
|
-
# If any features were added on the CLI from `--
|
|
303
|
+
def plugin_feature(file)
|
|
304
|
+
# If any features were added on the CLI from `--plugin`,
|
|
304
305
|
# add them to the config.
|
|
305
|
-
|
|
306
|
-
|
|
306
|
+
ConfigLoaderResolver.new.resolve_plugins(Config.new, file)
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
def require_feature(file)
|
|
310
|
+
if Plugin.plugin_capable?(file)
|
|
311
|
+
# NOTE: Compatibility for before plugins style.
|
|
312
|
+
warn Rainbow(<<~MESSAGE).yellow
|
|
313
|
+
#{file} gem supports plugin, use `--plugin` instead of `--require`.
|
|
314
|
+
MESSAGE
|
|
315
|
+
plugin_feature(file)
|
|
316
|
+
else
|
|
317
|
+
# If any features were added on the CLI from `--require`,
|
|
318
|
+
# add them to the config.
|
|
319
|
+
require file
|
|
320
|
+
ConfigLoader.add_loaded_features(file)
|
|
321
|
+
end
|
|
307
322
|
end
|
|
308
323
|
end
|
|
309
324
|
|
|
@@ -397,7 +412,7 @@ module RuboCop
|
|
|
397
412
|
return if @options[:format] == 'junit'
|
|
398
413
|
|
|
399
414
|
raise OptionArgumentError,
|
|
400
|
-
|
|
415
|
+
'--display-only-failed can only be used together with --format junit.'
|
|
401
416
|
end
|
|
402
417
|
|
|
403
418
|
def validate_display_only_correctable_and_autocorrect
|
|
@@ -415,14 +430,13 @@ module RuboCop
|
|
|
415
430
|
!@options.key?(:display_only_safe_correctable)
|
|
416
431
|
|
|
417
432
|
raise OptionArgumentError,
|
|
418
|
-
|
|
433
|
+
'--display-only-failed cannot be used together with other display options.'
|
|
419
434
|
end
|
|
420
435
|
|
|
421
436
|
def validate_lsp_and_editor_mode
|
|
422
437
|
return if !@options.key?(:lsp) || !@options.key?(:editor_mode)
|
|
423
438
|
|
|
424
|
-
raise OptionArgumentError,
|
|
425
|
-
format('Do not specify `--editor-mode` as it is redundant in `--lsp`.')
|
|
439
|
+
raise OptionArgumentError, 'Do not specify `--editor-mode` as it is redundant in `--lsp`.'
|
|
426
440
|
end
|
|
427
441
|
|
|
428
442
|
def validate_autocorrect
|
|
@@ -436,7 +450,7 @@ module RuboCop
|
|
|
436
450
|
return unless @options.key?(:disable_uncorrectable)
|
|
437
451
|
|
|
438
452
|
raise OptionArgumentError,
|
|
439
|
-
|
|
453
|
+
'--disable-uncorrectable can only be used together with --autocorrect.'
|
|
440
454
|
end
|
|
441
455
|
|
|
442
456
|
def disable_parallel_when_invalid_option_combo
|
|
@@ -504,6 +518,7 @@ module RuboCop
|
|
|
504
518
|
only_guide_cops: ['Run only cops for rules that link to a',
|
|
505
519
|
'style guide.'],
|
|
506
520
|
except: 'Exclude the given cop(s).',
|
|
521
|
+
plugin: 'Load a RuboCop plugin.',
|
|
507
522
|
require: 'Require Ruby file.',
|
|
508
523
|
config: 'Specify configuration file.',
|
|
509
524
|
auto_gen_config: ['Generate a configuration file acting as a',
|
|
@@ -542,8 +557,8 @@ module RuboCop
|
|
|
542
557
|
only_recognized_file_types: ['Inspect files given on the command line only if',
|
|
543
558
|
'they are listed in `AllCops/Include` parameters',
|
|
544
559
|
'of user configuration or default configuration.'],
|
|
545
|
-
ignore_disable_comments: ['
|
|
546
|
-
'
|
|
560
|
+
ignore_disable_comments: ['Report offenses even if they have been manually disabled',
|
|
561
|
+
'with a `rubocop:disable` or `rubocop:todo` directive.'],
|
|
547
562
|
ignore_parent_exclusion: ['Prevent from inheriting `AllCops/Exclude` from',
|
|
548
563
|
'parent folders.'],
|
|
549
564
|
ignore_unrecognized_cops: ['Ignore unrecognized cops or departments in the config.'],
|
|
@@ -579,7 +594,8 @@ module RuboCop
|
|
|
579
594
|
'when combined with --display-only-correctable.'],
|
|
580
595
|
show_cops: ['Shows the given cops, or all cops by',
|
|
581
596
|
'default, and their configurations for the',
|
|
582
|
-
'current directory.'
|
|
597
|
+
'current directory.',
|
|
598
|
+
'You can use `*` as a wildcard.'],
|
|
583
599
|
show_docs_url: ['Display url to documentation for the given',
|
|
584
600
|
'cops, or base url by default.'],
|
|
585
601
|
fail_fast: ['Inspect files in order of modification',
|
data/lib/rubocop/path_util.rb
CHANGED
|
@@ -28,20 +28,27 @@ module RuboCop
|
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
def remote_file?(uri)
|
|
32
|
+
uri.start_with?('http://', 'https://')
|
|
33
|
+
end
|
|
34
|
+
|
|
31
35
|
SMART_PATH_CACHE = {} # rubocop:disable Style/MutableConstant
|
|
32
36
|
private_constant :SMART_PATH_CACHE
|
|
33
37
|
|
|
34
38
|
def smart_path(path)
|
|
35
|
-
SMART_PATH_CACHE[path] ||=
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if path.start_with? base_dir
|
|
40
|
-
relative_path(path, base_dir)
|
|
39
|
+
SMART_PATH_CACHE[path] ||=
|
|
40
|
+
if path.is_a?(RemoteConfig)
|
|
41
|
+
path.uri.to_s
|
|
41
42
|
else
|
|
42
|
-
|
|
43
|
+
# Ideally, we calculate this relative to the project root.
|
|
44
|
+
base_dir = Dir.pwd
|
|
45
|
+
|
|
46
|
+
if path.start_with? base_dir
|
|
47
|
+
relative_path(path, base_dir)
|
|
48
|
+
else
|
|
49
|
+
path
|
|
50
|
+
end
|
|
43
51
|
end
|
|
44
|
-
end
|
|
45
52
|
end
|
|
46
53
|
|
|
47
54
|
# rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
# Reports information about pending cops that are not explicitly configured.
|
|
5
|
+
#
|
|
6
|
+
# This class is responsible for displaying warnings when new cops have been added to RuboCop
|
|
7
|
+
# but have not yet been enabled or disabled in the user's configuration.
|
|
8
|
+
# It provides a centralized way to determine whether such warnings should be shown,
|
|
9
|
+
# based on global flags or configuration settings.
|
|
10
|
+
class PendingCopsReporter
|
|
11
|
+
class << self
|
|
12
|
+
PENDING_BANNER = <<~BANNER
|
|
13
|
+
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
|
|
14
|
+
|
|
15
|
+
Please also note that you can opt-in to new cops by default by adding this to your config:
|
|
16
|
+
AllCops:
|
|
17
|
+
NewCops: enable
|
|
18
|
+
BANNER
|
|
19
|
+
|
|
20
|
+
attr_accessor :disable_pending_cops, :enable_pending_cops
|
|
21
|
+
|
|
22
|
+
def warn_if_needed(config)
|
|
23
|
+
return if possible_new_cops?(config)
|
|
24
|
+
|
|
25
|
+
pending_cops = pending_cops_only_qualified(config.pending_cops)
|
|
26
|
+
warn_on_pending_cops(pending_cops) unless pending_cops.empty?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def pending_cops_only_qualified(pending_cops)
|
|
32
|
+
pending_cops.select { |cop| Cop::Registry.qualified_cop?(cop.name) }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def possible_new_cops?(config)
|
|
36
|
+
disable_pending_cops || enable_pending_cops ||
|
|
37
|
+
config.disabled_new_cops? || config.enabled_new_cops?
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def warn_on_pending_cops(pending_cops)
|
|
41
|
+
warn Rainbow(PENDING_BANNER).yellow
|
|
42
|
+
|
|
43
|
+
pending_cops.each { |cop| warn_pending_cop cop }
|
|
44
|
+
|
|
45
|
+
warn Rainbow('For more information: https://docs.rubocop.org/rubocop/versioning.html').yellow
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def warn_pending_cop(cop)
|
|
49
|
+
version = cop.metadata['VersionAdded'] || 'N/A'
|
|
50
|
+
|
|
51
|
+
warn Rainbow("#{cop.name}: # new in #{version}").yellow
|
|
52
|
+
warn Rainbow(' Enabled: true').yellow
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|