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
@@ -34,7 +34,7 @@ module RuboCop
|
|
34
34
|
exit 0
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
write_version_file
|
38
38
|
|
39
39
|
host = ENV.fetch('RUBOCOP_SERVER_HOST', '127.0.0.1')
|
40
40
|
port = ENV.fetch('RUBOCOP_SERVER_PORT', 0)
|
@@ -42,6 +42,16 @@ module RuboCop
|
|
42
42
|
Server::Core.new.start(host, port, detach: @detach)
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def write_version_file
|
49
|
+
Cache.write_version_file(
|
50
|
+
Cache.restart_key(
|
51
|
+
args_config_file_path: self.class.args_config_file_path
|
52
|
+
)
|
53
|
+
)
|
54
|
+
end
|
45
55
|
end
|
46
56
|
end
|
47
57
|
end
|
@@ -46,7 +46,11 @@ module RuboCop
|
|
46
46
|
hidden_files = all_files.select { |file| file.include?(HIDDEN_PATH_SUBSTRING) }.sort
|
47
47
|
base_dir_config = @config_store.for(base_dir)
|
48
48
|
|
49
|
-
target_files =
|
49
|
+
target_files = if base_dir.include?(HIDDEN_PATH_SUBSTRING)
|
50
|
+
all_files.select { |file| ruby_file?(file) }
|
51
|
+
else
|
52
|
+
all_files.select { |file| to_inspect?(file, hidden_files, base_dir_config) }
|
53
|
+
end
|
50
54
|
|
51
55
|
target_files.sort_by!(&order)
|
52
56
|
end
|
@@ -127,6 +131,7 @@ module RuboCop
|
|
127
131
|
if mode == :only_recognized_file_types || force_exclusion?
|
128
132
|
files.select! { |file| included_file?(file) }
|
129
133
|
end
|
134
|
+
files.reject! { |file| FileTest.directory?(file) }
|
130
135
|
|
131
136
|
force_exclusion? ? without_excluded(files) : files
|
132
137
|
end
|
@@ -174,7 +179,7 @@ module RuboCop
|
|
174
179
|
end
|
175
180
|
|
176
181
|
def ruby_executable?(file)
|
177
|
-
return false
|
182
|
+
return false if !File.extname(file).empty? || !File.exist?(file) || File.empty?(file)
|
178
183
|
|
179
184
|
first_line = File.open(file, &:readline)
|
180
185
|
/#!.*(#{ruby_interpreters(file).join('|')})/.match?(first_line)
|
data/lib/rubocop/target_ruby.rb
CHANGED
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
# The kind of Ruby that code inspected by RuboCop is written in.
|
5
5
|
# @api private
|
6
6
|
class TargetRuby
|
7
|
-
KNOWN_RUBIES = [2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3, 3.4].freeze
|
7
|
+
KNOWN_RUBIES = [2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5].freeze
|
8
8
|
DEFAULT_VERSION = 2.7
|
9
9
|
|
10
10
|
OBSOLETE_RUBIES = {
|
@@ -34,6 +34,20 @@ module RuboCop
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
# The target ruby version may be configured by setting the
|
38
|
+
# `RUBOCOP_TARGET_RUBY_VERSION` environment variable.
|
39
|
+
class RuboCopEnvVar < Source
|
40
|
+
def name
|
41
|
+
'`RUBOCOP_TARGET_RUBY_VERSION` environment variable'
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def find_version
|
47
|
+
ENV.fetch('RUBOCOP_TARGET_RUBY_VERSION', nil)&.to_f
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
37
51
|
# The target ruby version may be configured in RuboCop's config.
|
38
52
|
# @api private
|
39
53
|
class RuboCopConfig < Source
|
@@ -246,6 +260,7 @@ module RuboCop
|
|
246
260
|
end
|
247
261
|
|
248
262
|
SOURCES = [
|
263
|
+
RuboCopEnvVar,
|
249
264
|
RuboCopConfig,
|
250
265
|
GemspecFile,
|
251
266
|
RubyVersionFile,
|
data/lib/rubocop/version.rb
CHANGED
@@ -3,13 +3,15 @@
|
|
3
3
|
module RuboCop
|
4
4
|
# This module holds the RuboCop version information.
|
5
5
|
module Version
|
6
|
-
STRING = '1.
|
6
|
+
STRING = '1.79.2'
|
7
7
|
|
8
8
|
MSG = '%<version>s (using %<parser_version>s, ' \
|
9
9
|
'rubocop-ast %<rubocop_ast_version>s, ' \
|
10
10
|
'analyzing as Ruby %<target_ruby_version>s, ' \
|
11
11
|
'running on %<ruby_engine>s %<ruby_version>s)%<server_mode>s [%<ruby_platform>s]'
|
12
12
|
|
13
|
+
MINIMUM_PARSABLE_PRISM_VERSION = 3.3
|
14
|
+
|
13
15
|
CANONICAL_FEATURE_NAMES = {
|
14
16
|
'Rspec' => 'RSpec', 'Graphql' => 'GraphQL', 'Md' => 'Markdown', 'Factory_bot' => 'FactoryBot',
|
15
17
|
'Thread_safety' => 'ThreadSafety', 'Rspec_rails' => 'RSpecRails'
|
@@ -20,11 +22,14 @@ module RuboCop
|
|
20
22
|
|
21
23
|
# NOTE: Marked as private but used by gems like standard.
|
22
24
|
# @api private
|
25
|
+
# rubocop:disable Metrics/MethodLength
|
23
26
|
def self.version(debug: false, env: nil)
|
24
27
|
if debug
|
25
|
-
|
28
|
+
target_ruby_version = target_ruby_version(env)
|
29
|
+
verbose_version = format(MSG, version: STRING,
|
30
|
+
parser_version: parser_version(target_ruby_version),
|
26
31
|
rubocop_ast_version: RuboCop::AST::Version::STRING,
|
27
|
-
target_ruby_version: target_ruby_version
|
32
|
+
target_ruby_version: target_ruby_version,
|
28
33
|
ruby_engine: RUBY_ENGINE, ruby_version: RUBY_VERSION,
|
29
34
|
server_mode: server_mode,
|
30
35
|
ruby_platform: RUBY_PLATFORM)
|
@@ -41,6 +46,7 @@ module RuboCop
|
|
41
46
|
STRING
|
42
47
|
end
|
43
48
|
end
|
49
|
+
# rubocop:enable Metrics/MethodLength
|
44
50
|
|
45
51
|
# @api private
|
46
52
|
def self.verbose(env: nil)
|
@@ -48,24 +54,37 @@ module RuboCop
|
|
48
54
|
end
|
49
55
|
|
50
56
|
# @api private
|
51
|
-
def self.parser_version
|
57
|
+
def self.parser_version(target_ruby_version)
|
52
58
|
config_path = ConfigFinder.find_config_path(Dir.pwd)
|
53
59
|
yaml = Util.silence_warnings do
|
54
60
|
ConfigLoader.load_yaml_configuration(config_path)
|
55
61
|
end
|
62
|
+
parser_engine = yaml.dig('AllCops', 'ParserEngine')
|
63
|
+
parser_engine_text = ", #{parser_engine}" if parser_engine
|
56
64
|
|
57
|
-
if
|
58
|
-
|
59
|
-
"Prism #{Prism::VERSION}"
|
65
|
+
if target_ruby_version >= MINIMUM_PARSABLE_PRISM_VERSION
|
66
|
+
"Parser #{Parser::VERSION}, Prism #{Prism::VERSION}#{parser_engine_text}"
|
60
67
|
else
|
61
68
|
"Parser #{Parser::VERSION}"
|
62
69
|
end
|
63
70
|
end
|
64
71
|
|
65
72
|
# @api private
|
73
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
66
74
|
def self.extension_versions(env)
|
75
|
+
plugins = config_for_pwd(env).loaded_plugins
|
76
|
+
plugin_versions = plugins.filter_map do |plugin|
|
77
|
+
next if Plugin::BUILTIN_INTERNAL_PLUGINS.key?(plugin.about.name)
|
78
|
+
next unless (plugin_name = plugin.about.name)
|
79
|
+
|
80
|
+
" - #{plugin_name} #{plugin.about.version}"
|
81
|
+
end
|
82
|
+
|
83
|
+
# TODO: It needs to be maintained for a while to ensure compatibility with extensions that
|
84
|
+
# don't support plugins. It should be removed in future once the old style becomes obsolete.
|
67
85
|
features = config_for_pwd(env).loaded_features.sort
|
68
|
-
features.
|
86
|
+
features -= plugins.map { |plugin| plugin.about.name }
|
87
|
+
feature_versions = features.filter_map do |loaded_feature|
|
69
88
|
next unless (match = loaded_feature.match(/rubocop-(?<feature>.*)/))
|
70
89
|
|
71
90
|
# Get the expected name of the folder containing the extension code.
|
@@ -84,7 +103,10 @@ module RuboCop
|
|
84
103
|
|
85
104
|
" - #{loaded_feature} #{feature_version}"
|
86
105
|
end
|
106
|
+
|
107
|
+
plugin_versions + feature_versions
|
87
108
|
end
|
109
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
88
110
|
|
89
111
|
# @api private
|
90
112
|
def self.target_ruby_version(env)
|
data/lib/rubocop.rb
CHANGED
@@ -75,6 +75,8 @@ require_relative 'rubocop/cop/mixin/allowed_identifiers'
|
|
75
75
|
require_relative 'rubocop/cop/mixin/allowed_methods'
|
76
76
|
require_relative 'rubocop/cop/mixin/allowed_pattern'
|
77
77
|
require_relative 'rubocop/cop/mixin/allowed_receivers'
|
78
|
+
require_relative 'rubocop/cop/mixin/forbidden_identifiers'
|
79
|
+
require_relative 'rubocop/cop/mixin/forbidden_pattern'
|
78
80
|
require_relative 'rubocop/cop/mixin/auto_corrector' # rubocop:todo Naming/InclusiveLanguage
|
79
81
|
require_relative 'rubocop/cop/mixin/check_assignment'
|
80
82
|
require_relative 'rubocop/cop/mixin/check_line_breakable'
|
@@ -100,6 +102,7 @@ require_relative 'rubocop/cop/mixin/frozen_string_literal'
|
|
100
102
|
require_relative 'rubocop/cop/mixin/gem_declaration'
|
101
103
|
require_relative 'rubocop/cop/mixin/gemspec_help'
|
102
104
|
require_relative 'rubocop/cop/mixin/hash_alignment_styles'
|
105
|
+
require_relative 'rubocop/cop/mixin/hash_subset'
|
103
106
|
require_relative 'rubocop/cop/mixin/hash_transform_method'
|
104
107
|
require_relative 'rubocop/cop/mixin/integer_node'
|
105
108
|
require_relative 'rubocop/cop/mixin/interpolation'
|
@@ -147,7 +150,6 @@ require_relative 'rubocop/cop/mixin/comments_help' # relies on visibility_help
|
|
147
150
|
require_relative 'rubocop/cop/mixin/def_node' # relies on visibility_help
|
148
151
|
|
149
152
|
require_relative 'rubocop/cop/utils/format_string'
|
150
|
-
require_relative 'rubocop/cop/utils/regexp_ranges'
|
151
153
|
|
152
154
|
require_relative 'rubocop/cop/migration/department_name'
|
153
155
|
|
@@ -178,6 +180,7 @@ require_relative 'rubocop/cop/bundler/insecure_protocol_source'
|
|
178
180
|
require_relative 'rubocop/cop/bundler/ordered_gems'
|
179
181
|
|
180
182
|
require_relative 'rubocop/cop/gemspec/add_runtime_dependency'
|
183
|
+
require_relative 'rubocop/cop/gemspec/attribute_assignment'
|
181
184
|
require_relative 'rubocop/cop/gemspec/dependency_version'
|
182
185
|
require_relative 'rubocop/cop/gemspec/deprecated_attribute_assignment'
|
183
186
|
require_relative 'rubocop/cop/gemspec/development_dependencies'
|
@@ -208,6 +211,7 @@ require_relative 'rubocop/cop/layout/empty_line_after_guard_clause'
|
|
208
211
|
require_relative 'rubocop/cop/layout/empty_line_after_magic_comment'
|
209
212
|
require_relative 'rubocop/cop/layout/empty_line_after_multiline_condition'
|
210
213
|
require_relative 'rubocop/cop/layout/empty_line_between_defs'
|
214
|
+
require_relative 'rubocop/cop/layout/empty_lines_after_module_inclusion'
|
211
215
|
require_relative 'rubocop/cop/layout/empty_lines_around_access_modifier'
|
212
216
|
require_relative 'rubocop/cop/layout/empty_lines_around_arguments'
|
213
217
|
require_relative 'rubocop/cop/layout/empty_lines_around_attribute_accessor'
|
@@ -287,12 +291,14 @@ require_relative 'rubocop/cop/layout/space_inside_string_interpolation'
|
|
287
291
|
require_relative 'rubocop/cop/layout/trailing_empty_lines'
|
288
292
|
require_relative 'rubocop/cop/layout/trailing_whitespace'
|
289
293
|
|
294
|
+
require_relative 'rubocop/cop/lint/utils/nil_receiver_checker'
|
290
295
|
require_relative 'rubocop/cop/lint/ambiguous_assignment'
|
291
296
|
require_relative 'rubocop/cop/lint/ambiguous_block_association'
|
292
297
|
require_relative 'rubocop/cop/lint/ambiguous_operator'
|
293
298
|
require_relative 'rubocop/cop/lint/ambiguous_operator_precedence'
|
294
299
|
require_relative 'rubocop/cop/lint/ambiguous_range'
|
295
300
|
require_relative 'rubocop/cop/lint/ambiguous_regexp_literal'
|
301
|
+
require_relative 'rubocop/cop/lint/array_literal_in_regexp'
|
296
302
|
require_relative 'rubocop/cop/lint/assignment_in_condition'
|
297
303
|
require_relative 'rubocop/cop/lint/big_decimal_new'
|
298
304
|
require_relative 'rubocop/cop/lint/binary_operator_with_identical_operands'
|
@@ -300,7 +306,9 @@ require_relative 'rubocop/cop/lint/boolean_symbol'
|
|
300
306
|
require_relative 'rubocop/cop/lint/circular_argument_reference'
|
301
307
|
require_relative 'rubocop/cop/lint/constant_definition_in_block'
|
302
308
|
require_relative 'rubocop/cop/lint/constant_overwritten_in_rescue'
|
309
|
+
require_relative 'rubocop/cop/lint/constant_reassignment'
|
303
310
|
require_relative 'rubocop/cop/lint/constant_resolution'
|
311
|
+
require_relative 'rubocop/cop/lint/cop_directive_syntax'
|
304
312
|
require_relative 'rubocop/cop/lint/debugger'
|
305
313
|
require_relative 'rubocop/cop/lint/deprecated_class_methods'
|
306
314
|
require_relative 'rubocop/cop/lint/deprecated_constants'
|
@@ -329,6 +337,7 @@ require_relative 'rubocop/cop/lint/empty_in_pattern'
|
|
329
337
|
require_relative 'rubocop/cop/lint/empty_interpolation'
|
330
338
|
require_relative 'rubocop/cop/lint/empty_when'
|
331
339
|
require_relative 'rubocop/cop/lint/ensure_return'
|
340
|
+
require_relative 'rubocop/cop/lint/shared_mutable_default'
|
332
341
|
require_relative 'rubocop/cop/lint/erb_new_arguments'
|
333
342
|
require_relative 'rubocop/cop/lint/flip_flop'
|
334
343
|
require_relative 'rubocop/cop/lint/float_comparison'
|
@@ -380,6 +389,7 @@ require_relative 'rubocop/cop/lint/redundant_require_statement'
|
|
380
389
|
require_relative 'rubocop/cop/lint/redundant_safe_navigation'
|
381
390
|
require_relative 'rubocop/cop/lint/redundant_splat_expansion'
|
382
391
|
require_relative 'rubocop/cop/lint/redundant_string_coercion'
|
392
|
+
require_relative 'rubocop/cop/lint/redundant_type_conversion'
|
383
393
|
require_relative 'rubocop/cop/lint/redundant_with_index'
|
384
394
|
require_relative 'rubocop/cop/lint/redundant_with_object'
|
385
395
|
require_relative 'rubocop/cop/lint/refinement_import_methods'
|
@@ -401,6 +411,7 @@ require_relative 'rubocop/cop/lint/shadowed_exception'
|
|
401
411
|
require_relative 'rubocop/cop/lint/shadowing_outer_local_variable'
|
402
412
|
require_relative 'rubocop/cop/lint/struct_new_override'
|
403
413
|
require_relative 'rubocop/cop/lint/suppressed_exception'
|
414
|
+
require_relative 'rubocop/cop/lint/suppressed_exception_in_number_conversion'
|
404
415
|
require_relative 'rubocop/cop/lint/symbol_conversion'
|
405
416
|
require_relative 'rubocop/cop/lint/syntax'
|
406
417
|
require_relative 'rubocop/cop/lint/to_enum_arguments'
|
@@ -421,10 +432,13 @@ require_relative 'rubocop/cop/lint/uri_escape_unescape'
|
|
421
432
|
require_relative 'rubocop/cop/lint/uri_regexp'
|
422
433
|
require_relative 'rubocop/cop/lint/useless_access_modifier'
|
423
434
|
require_relative 'rubocop/cop/lint/useless_assignment'
|
435
|
+
require_relative 'rubocop/cop/lint/useless_constant_scoping'
|
436
|
+
require_relative 'rubocop/cop/lint/useless_default_value_argument'
|
424
437
|
require_relative 'rubocop/cop/lint/useless_defined'
|
425
438
|
require_relative 'rubocop/cop/lint/useless_else_without_rescue'
|
426
439
|
require_relative 'rubocop/cop/lint/useless_method_definition'
|
427
440
|
require_relative 'rubocop/cop/lint/useless_numeric_operation'
|
441
|
+
require_relative 'rubocop/cop/lint/useless_or'
|
428
442
|
require_relative 'rubocop/cop/lint/useless_rescue'
|
429
443
|
require_relative 'rubocop/cop/lint/useless_ruby2_keywords'
|
430
444
|
require_relative 'rubocop/cop/lint/useless_setter_call'
|
@@ -460,7 +474,8 @@ require_relative 'rubocop/cop/naming/memoized_instance_variable_name'
|
|
460
474
|
require_relative 'rubocop/cop/naming/method_name'
|
461
475
|
require_relative 'rubocop/cop/naming/method_parameter_name'
|
462
476
|
require_relative 'rubocop/cop/naming/binary_operator_parameter_name'
|
463
|
-
require_relative 'rubocop/cop/naming/
|
477
|
+
require_relative 'rubocop/cop/naming/predicate_method'
|
478
|
+
require_relative 'rubocop/cop/naming/predicate_prefix'
|
464
479
|
require_relative 'rubocop/cop/naming/rescued_exceptions_variable_name'
|
465
480
|
require_relative 'rubocop/cop/naming/variable_name'
|
466
481
|
require_relative 'rubocop/cop/naming/variable_number'
|
@@ -495,6 +510,7 @@ require_relative 'rubocop/cop/style/class_methods_definitions'
|
|
495
510
|
require_relative 'rubocop/cop/style/class_vars'
|
496
511
|
require_relative 'rubocop/cop/style/collection_compact'
|
497
512
|
require_relative 'rubocop/cop/style/collection_methods'
|
513
|
+
require_relative 'rubocop/cop/style/collection_querying'
|
498
514
|
require_relative 'rubocop/cop/style/colon_method_call'
|
499
515
|
require_relative 'rubocop/cop/style/colon_method_definition'
|
500
516
|
require_relative 'rubocop/cop/style/combinable_defined'
|
@@ -502,6 +518,7 @@ require_relative 'rubocop/cop/style/combinable_loops'
|
|
502
518
|
require_relative 'rubocop/cop/style/command_literal'
|
503
519
|
require_relative 'rubocop/cop/style/comment_annotation'
|
504
520
|
require_relative 'rubocop/cop/style/commented_keyword'
|
521
|
+
require_relative 'rubocop/cop/style/comparable_between'
|
505
522
|
require_relative 'rubocop/cop/style/comparable_clamp'
|
506
523
|
require_relative 'rubocop/cop/style/concat_array_literals'
|
507
524
|
require_relative 'rubocop/cop/style/conditional_assignment'
|
@@ -528,6 +545,7 @@ require_relative 'rubocop/cop/style/empty_heredoc'
|
|
528
545
|
require_relative 'rubocop/cop/style/empty_lambda_parameter'
|
529
546
|
require_relative 'rubocop/cop/style/empty_literal'
|
530
547
|
require_relative 'rubocop/cop/style/empty_method'
|
548
|
+
require_relative 'rubocop/cop/style/empty_string_inside_interpolation'
|
531
549
|
require_relative 'rubocop/cop/style/endless_method'
|
532
550
|
require_relative 'rubocop/cop/style/encoding'
|
533
551
|
require_relative 'rubocop/cop/style/end_block'
|
@@ -556,7 +574,9 @@ require_relative 'rubocop/cop/style/hash_as_last_array_item'
|
|
556
574
|
require_relative 'rubocop/cop/style/hash_conversion'
|
557
575
|
require_relative 'rubocop/cop/style/hash_each_methods'
|
558
576
|
require_relative 'rubocop/cop/style/hash_except'
|
577
|
+
require_relative 'rubocop/cop/style/hash_fetch_chain'
|
559
578
|
require_relative 'rubocop/cop/style/hash_like_case'
|
579
|
+
require_relative 'rubocop/cop/style/hash_slice'
|
560
580
|
require_relative 'rubocop/cop/style/hash_syntax'
|
561
581
|
require_relative 'rubocop/cop/style/hash_transform_keys'
|
562
582
|
require_relative 'rubocop/cop/style/hash_transform_values'
|
@@ -573,6 +593,8 @@ require_relative 'rubocop/cop/style/inverse_methods'
|
|
573
593
|
require_relative 'rubocop/cop/style/inline_comment'
|
574
594
|
require_relative 'rubocop/cop/style/invertible_unless_condition'
|
575
595
|
require_relative 'rubocop/cop/style/ip_addresses'
|
596
|
+
require_relative 'rubocop/cop/style/it_assignment'
|
597
|
+
require_relative 'rubocop/cop/style/it_block_parameter'
|
576
598
|
require_relative 'rubocop/cop/style/keyword_arguments_merging'
|
577
599
|
require_relative 'rubocop/cop/style/keyword_parameters_order'
|
578
600
|
require_relative 'rubocop/cop/style/lambda'
|
@@ -590,6 +612,7 @@ require_relative 'rubocop/cop/style/numbered_parameters'
|
|
590
612
|
require_relative 'rubocop/cop/style/open_struct_use'
|
591
613
|
require_relative 'rubocop/cop/style/operator_method_call'
|
592
614
|
require_relative 'rubocop/cop/style/redundant_array_constructor'
|
615
|
+
require_relative 'rubocop/cop/style/redundant_array_flatten'
|
593
616
|
require_relative 'rubocop/cop/style/redundant_assignment'
|
594
617
|
require_relative 'rubocop/cop/style/redundant_constant_base'
|
595
618
|
require_relative 'rubocop/cop/style/redundant_current_directory_in_path'
|
@@ -598,6 +621,7 @@ require_relative 'rubocop/cop/style/redundant_each'
|
|
598
621
|
require_relative 'rubocop/cop/style/redundant_fetch_block'
|
599
622
|
require_relative 'rubocop/cop/style/redundant_file_extension_in_require'
|
600
623
|
require_relative 'rubocop/cop/style/redundant_filter_chain'
|
624
|
+
require_relative 'rubocop/cop/style/redundant_format'
|
601
625
|
require_relative 'rubocop/cop/style/redundant_heredoc_delimiter_quotes'
|
602
626
|
require_relative 'rubocop/cop/style/redundant_initialize'
|
603
627
|
require_relative 'rubocop/cop/style/redundant_interpolation_unfreeze'
|
@@ -790,6 +814,7 @@ require_relative 'rubocop/options'
|
|
790
814
|
require_relative 'rubocop/remote_config'
|
791
815
|
require_relative 'rubocop/target_ruby'
|
792
816
|
require_relative 'rubocop/yaml_duplication_checker'
|
817
|
+
require_relative 'rubocop/pending_cops_reporter'
|
793
818
|
|
794
819
|
# rubocop:enable Style/RequireOrder
|
795
820
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../rubocop'
|
4
|
+
require_relative '../../rubocop/lsp/logger'
|
5
|
+
require_relative 'runtime_adapter'
|
6
|
+
|
7
|
+
module RubyLsp
|
8
|
+
module RuboCop
|
9
|
+
# A Ruby LSP add-on for RuboCop.
|
10
|
+
class Addon < RubyLsp::Addon
|
11
|
+
def initializer
|
12
|
+
@runtime_adapter = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def name
|
16
|
+
'RuboCop'
|
17
|
+
end
|
18
|
+
|
19
|
+
def activate(global_state, message_queue)
|
20
|
+
::RuboCop::LSP::Logger.log(
|
21
|
+
"Activating RuboCop LSP addon #{::RuboCop::Version::STRING}.", prefix: '[RuboCop]'
|
22
|
+
)
|
23
|
+
|
24
|
+
@runtime_adapter = RuntimeAdapter.new
|
25
|
+
global_state.register_formatter('rubocop', @runtime_adapter)
|
26
|
+
register_additional_file_watchers(global_state, message_queue)
|
27
|
+
|
28
|
+
::RuboCop::LSP::Logger.log(
|
29
|
+
"Initialized RuboCop LSP addon #{::RuboCop::Version::STRING}.", prefix: '[RuboCop]'
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def deactivate
|
34
|
+
@runtime_adapter = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
# rubocop:disable Metrics/MethodLength
|
38
|
+
def register_additional_file_watchers(global_state, message_queue)
|
39
|
+
return unless global_state.supports_watching_files
|
40
|
+
|
41
|
+
message_queue << Request.new(
|
42
|
+
id: 'rubocop-file-watcher',
|
43
|
+
method: 'client/registerCapability',
|
44
|
+
params: Interface::RegistrationParams.new(
|
45
|
+
registrations: [
|
46
|
+
Interface::Registration.new(
|
47
|
+
id: 'workspace/didChangeWatchedFilesRuboCop',
|
48
|
+
method: 'workspace/didChangeWatchedFiles',
|
49
|
+
register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
|
50
|
+
watchers: [
|
51
|
+
Interface::FileSystemWatcher.new(
|
52
|
+
glob_pattern: '**/.rubocop{,_todo}.yml',
|
53
|
+
kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE
|
54
|
+
)
|
55
|
+
]
|
56
|
+
)
|
57
|
+
)
|
58
|
+
]
|
59
|
+
)
|
60
|
+
)
|
61
|
+
end
|
62
|
+
# rubocop:enable Metrics/MethodLength
|
63
|
+
|
64
|
+
def workspace_did_change_watched_files(changes)
|
65
|
+
return unless changes.any? { |change| change[:uri].end_with?('.rubocop.yml') }
|
66
|
+
|
67
|
+
@runtime_adapter = RuntimeAdapter.new
|
68
|
+
|
69
|
+
::RuboCop::LSP::Logger.log(<<~MESSAGE, prefix: '[RuboCop]')
|
70
|
+
Re-initialized RuboCop LSP addon #{::RuboCop::Version::STRING} due to .rubocop.yml file change.
|
71
|
+
MESSAGE
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../rubocop/lsp/runtime'
|
4
|
+
|
5
|
+
module RubyLsp
|
6
|
+
module RuboCop
|
7
|
+
# Provides an adapter to bridge RuboCop's built-in LSP runtime with Ruby LSP's add-on.
|
8
|
+
# @api private
|
9
|
+
class RuntimeAdapter
|
10
|
+
include RubyLsp::Requests::Support::Formatter
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
config_store = ::RuboCop::ConfigStore.new
|
14
|
+
|
15
|
+
@runtime = ::RuboCop::LSP::Runtime.new(config_store)
|
16
|
+
end
|
17
|
+
|
18
|
+
def run_diagnostic(uri, document)
|
19
|
+
@runtime.offenses(
|
20
|
+
uri_to_path(uri),
|
21
|
+
document.source,
|
22
|
+
document.encoding,
|
23
|
+
prism_result: prism_result(document)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_formatting(uri, document)
|
28
|
+
@runtime.format(
|
29
|
+
uri_to_path(uri),
|
30
|
+
document.source,
|
31
|
+
command: 'rubocop.formatAutocorrects',
|
32
|
+
prism_result: prism_result(document)
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def run_range_formatting(_uri, _partial_source, _base_indentation)
|
37
|
+
# Not yet supported. Should return the formatted version of `partial_source` which is
|
38
|
+
# a partial selection of the entire document. For example, it should not try to add
|
39
|
+
# a frozen_string_literal magic comment and all style corrections should start from
|
40
|
+
# the `base_indentation`.
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
# duplicated from: lib/standard/lsp/routes.rb
|
47
|
+
# modified to incorporate Ruby LSP's to_standardized_path method
|
48
|
+
def uri_to_path(uri)
|
49
|
+
if uri.respond_to?(:to_standardized_path) && (standardized_path = uri.to_standardized_path)
|
50
|
+
standardized_path
|
51
|
+
else
|
52
|
+
uri.to_s.delete_prefix('file://')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def prism_result(document)
|
57
|
+
prism_result = document.parse_result
|
58
|
+
|
59
|
+
# NOTE: `prism_result` must be `Prism::ParseLexResult` compatible object.
|
60
|
+
# This is for compatibility parsed result unsupported.
|
61
|
+
prism_result.is_a?(Prism::ParseLexResult) ? prism_result : nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|