rubocop 1.72.1 → 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/README.md +22 -18
- data/config/default.yml +240 -65
- data/config/internal_affairs.yml +20 -0
- data/config/obsoletion.yml +8 -3
- data/exe/rubocop +1 -8
- data/lib/rubocop/cli/command/auto_generate_config.rb +2 -2
- data/lib/rubocop/cli.rb +19 -4
- data/lib/rubocop/config.rb +35 -6
- data/lib/rubocop/config_loader.rb +8 -40
- data/lib/rubocop/config_loader_resolver.rb +9 -7
- 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 +7 -6
- data/lib/rubocop/cop/autocorrect_logic.rb +22 -14
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +7 -4
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -2
- 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/internal_affairs/example_description.rb +9 -5
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +4 -4
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +6 -2
- data/lib/rubocop/cop/internal_affairs/node_type_group.rb +92 -0
- data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +6 -5
- data/lib/rubocop/cop/internal_affairs/undefined_config.rb +6 -1
- data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +1 -1
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/block_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/block_end_newline.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +36 -1
- 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 +1 -1
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +32 -14
- data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +101 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +34 -4
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +8 -29
- 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/first_argument_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/hash_alignment.rb +4 -7
- 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_length.rb +43 -10
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +9 -5
- data/lib/rubocop/cop/layout/redundant_line_break.rb +9 -5
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +11 -5
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +10 -0
- data/lib/rubocop/cop/layout/space_around_keyword.rb +6 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +12 -1
- 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_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 +1 -1
- data/lib/rubocop/cop/lint/ambiguous_range.rb +5 -0
- data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +2 -3
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -5
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +3 -2
- data/lib/rubocop/cop/lint/cop_directive_syntax.rb +13 -7
- data/lib/rubocop/cop/lint/debugger.rb +2 -4
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +5 -2
- data/lib/rubocop/cop/lint/duplicate_methods.rb +111 -23
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +14 -64
- data/lib/rubocop/cop/lint/empty_interpolation.rb +14 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +0 -6
- data/lib/rubocop/cop/lint/float_comparison.rb +32 -10
- data/lib/rubocop/cop/lint/identity_comparison.rb +19 -15
- data/lib/rubocop/cop/lint/literal_as_condition.rb +124 -10
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +17 -8
- data/lib/rubocop/cop/lint/mixed_case_range.rb +2 -2
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -3
- data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +1 -0
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
- data/lib/rubocop/cop/lint/raise_exception.rb +29 -10
- data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
- 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_type_conversion.rb +43 -13
- 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/require_range_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -4
- 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 +4 -4
- data/lib/rubocop/cop/lint/self_assignment.rb +31 -5
- data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +13 -1
- data/lib/rubocop/cop/lint/shared_mutable_default.rb +12 -1
- data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -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/unexpected_block_arity.rb +2 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_loop.rb +5 -5
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +30 -4
- data/lib/rubocop/cop/lint/useless_assignment.rb +2 -0
- data/lib/rubocop/cop/lint/useless_constant_scoping.rb +9 -12
- data/lib/rubocop/cop/lint/useless_default_value_argument.rb +90 -0
- data/lib/rubocop/cop/lint/useless_numeric_operation.rb +1 -0
- 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 +3 -3
- data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +121 -0
- data/lib/rubocop/cop/lint/void.rb +16 -2
- 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/method_length.rb +1 -0
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +4 -4
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -3
- data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +2 -2
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- 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/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_subset.rb +19 -4
- data/lib/rubocop/cop/mixin/line_length_help.rb +24 -8
- data/lib/rubocop/cop/mixin/method_complexity.rb +1 -0
- 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/range_help.rb +12 -0
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +1 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +18 -2
- data/lib/rubocop/cop/naming/block_forwarding.rb +3 -3
- 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 +187 -15
- data/lib/rubocop/cop/naming/predicate_method.rb +319 -0
- data/lib/rubocop/cop/naming/{predicate_name.rb → predicate_prefix.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/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/style/access_modifier_declarations.rb +32 -10
- data/lib/rubocop/cop/style/accessor_grouping.rb +32 -6
- data/lib/rubocop/cop/style/arguments_forwarding.rb +21 -24
- data/lib/rubocop/cop/style/array_intersect.rb +113 -38
- data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -0
- data/lib/rubocop/cop/style/bitwise_predicate.rb +8 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +3 -2
- data/lib/rubocop/cop/style/case_like_if.rb +1 -1
- data/lib/rubocop/cop/style/class_and_module_children.rb +48 -10
- data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -1
- data/lib/rubocop/cop/style/collection_methods.rb +1 -0
- data/lib/rubocop/cop/style/collection_querying.rb +167 -0
- data/lib/rubocop/cop/style/combinable_loops.rb +1 -0
- 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/conditional_assignment.rb +26 -8
- data/lib/rubocop/cop/style/constant_visibility.rb +14 -9
- 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 +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +3 -3
- data/lib/rubocop/cop/style/empty_literal.rb +4 -0
- data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +100 -0
- data/lib/rubocop/cop/style/endless_method.rb +176 -18
- data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -7
- data/lib/rubocop/cop/style/explicit_block_argument.rb +3 -3
- data/lib/rubocop/cop/style/exponential_notation.rb +5 -4
- data/lib/rubocop/cop/style/fetch_env_var.rb +32 -6
- data/lib/rubocop/cop/style/float_division.rb +15 -1
- 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 +3 -2
- data/lib/rubocop/cop/style/hash_fetch_chain.rb +104 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -1
- 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 +3 -3
- data/lib/rubocop/cop/style/if_inside_else.rb +10 -13
- data/lib/rubocop/cop/style/if_unless_modifier.rb +35 -8
- 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 +1 -1
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +10 -6
- 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 +69 -12
- data/lib/rubocop/cop/style/it_block_parameter.rb +121 -0
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +13 -7
- data/lib/rubocop/cop/style/lambda.rb +1 -0
- data/lib/rubocop/cop/style/lambda_call.rb +7 -2
- data/lib/rubocop/cop/style/line_end_concatenation.rb +10 -4
- data/lib/rubocop/cop/style/map_into_array.rb +4 -1
- data/lib/rubocop/cop/style/map_to_hash.rb +12 -3
- data/lib/rubocop/cop/style/map_to_set.rb +1 -3
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +9 -8
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +16 -0
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -1
- data/lib/rubocop/cop/style/min_max_comparison.rb +13 -5
- data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -1
- 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/next.rb +44 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +9 -7
- data/lib/rubocop/cop/style/object_then.rb +1 -0
- data/lib/rubocop/cop/style/one_line_conditional.rb +17 -9
- data/lib/rubocop/cop/style/parallel_assignment.rb +32 -20
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -0
- data/lib/rubocop/cop/style/raise_args.rb +8 -8
- data/lib/rubocop/cop/style/redundant_array_flatten.rb +50 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +35 -0
- data/lib/rubocop/cop/style/redundant_condition.rb +57 -0
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +14 -4
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -9
- data/lib/rubocop/cop/style/redundant_format.rb +79 -18
- data/lib/rubocop/cop/style/redundant_freeze.rb +2 -2
- data/lib/rubocop/cop/style/redundant_interpolation.rb +12 -3
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +1 -4
- data/lib/rubocop/cop/style/redundant_parentheses.rb +73 -18
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +4 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -0
- data/lib/rubocop/cop/style/redundant_self.rb +9 -5
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/redundant_sort_by.rb +17 -1
- 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 +61 -14
- data/lib/rubocop/cop/style/select_by_regexp.rb +4 -1
- data/lib/rubocop/cop/style/semicolon.rb +23 -7
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +3 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +10 -7
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +75 -101
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/string_concatenation.rb +18 -15
- data/lib/rubocop/cop/style/struct_inheritance.rb +8 -1
- data/lib/rubocop/cop/style/super_arguments.rb +1 -2
- 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/top_level_method_definition.rb +1 -0
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +52 -1
- 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/unless_else.rb +10 -9
- data/lib/rubocop/cop/team.rb +1 -1
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/utils/format_string.rb +15 -2
- 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 +3 -8
- data/lib/rubocop/cop/variable_force.rb +26 -9
- data/lib/rubocop/cops_documentation_generator.rb +23 -7
- data/lib/rubocop/directive_comment.rb +1 -1
- data/lib/rubocop/ext/regexp_node.rb +0 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +19 -5
- 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 +25 -24
- data/lib/rubocop/lsp/routes.rb +65 -9
- data/lib/rubocop/lsp/runtime.rb +5 -5
- data/lib/rubocop/lsp/server.rb +2 -2
- data/lib/rubocop/lsp/stdin_runner.rb +3 -17
- data/lib/rubocop/magic_comment.rb +8 -0
- data/lib/rubocop/pending_cops_reporter.rb +56 -0
- data/lib/rubocop/plugin/configuration_integrator.rb +2 -0
- data/lib/rubocop/plugin/load_error.rb +1 -1
- data/lib/rubocop/plugin.rb +9 -2
- data/lib/rubocop/result_cache.rb +14 -12
- data/lib/rubocop/rspec/cop_helper.rb +6 -1
- data/lib/rubocop/rspec/expect_offense.rb +9 -3
- data/lib/rubocop/rspec/shared_contexts.rb +34 -0
- data/lib/rubocop/rspec/support.rb +3 -0
- data/lib/rubocop/runner.rb +10 -4
- data/lib/rubocop/server/cache.rb +17 -12
- 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 +13 -9
- data/lib/rubocop/target_ruby.rb +11 -2
- data/lib/rubocop/version.rb +14 -7
- data/lib/rubocop.rb +17 -2
- data/lib/ruby_lsp/rubocop/addon.rb +25 -10
- data/lib/ruby_lsp/rubocop/runtime_adapter.rb +57 -5
- metadata +24 -8
- data/lib/rubocop/cop/utils/regexp_ranges.rb +0 -113
data/lib/rubocop/server/cache.rb
CHANGED
|
@@ -46,13 +46,16 @@ module RuboCop
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
# rubocop:disable Metrics/AbcSize
|
|
49
|
-
def restart_key
|
|
49
|
+
def restart_key(args_config_file_path: nil)
|
|
50
50
|
lockfile_path = LOCKFILE_NAMES.map do |lockfile_name|
|
|
51
51
|
Pathname(project_dir).join(lockfile_name)
|
|
52
52
|
end.find(&:exist?)
|
|
53
53
|
version_data = lockfile_path&.read || RuboCop::Version::STRING
|
|
54
|
-
config_data = Pathname(
|
|
55
|
-
|
|
54
|
+
config_data = Pathname(
|
|
55
|
+
args_config_file_path || ConfigFinder.find_config_path(Dir.pwd)
|
|
56
|
+
).read
|
|
57
|
+
yaml = load_erb_templated_yaml(config_data)
|
|
58
|
+
|
|
56
59
|
inherit_from_data = inherit_from_data(yaml)
|
|
57
60
|
require_data = require_data(yaml)
|
|
58
61
|
|
|
@@ -76,7 +79,6 @@ module RuboCop
|
|
|
76
79
|
File.expand_path(File.join(cache_root_dir, 'server'))
|
|
77
80
|
end
|
|
78
81
|
|
|
79
|
-
# rubocop:disable Metrics/MethodLength
|
|
80
82
|
def cache_root_dir_from_config
|
|
81
83
|
CacheConfig.root_dir do
|
|
82
84
|
# `RuboCop::ConfigStore` has heavy dependencies, this is a lightweight implementation
|
|
@@ -87,13 +89,7 @@ module RuboCop
|
|
|
87
89
|
# Returns early if `CacheRootDirectory` is not used before requiring `erb` or `yaml`.
|
|
88
90
|
next unless file_contents.include?('CacheRootDirectory')
|
|
89
91
|
|
|
90
|
-
|
|
91
|
-
yaml_code = ERB.new(file_contents).result
|
|
92
|
-
|
|
93
|
-
require 'yaml'
|
|
94
|
-
config_yaml = YAML.safe_load(
|
|
95
|
-
yaml_code, permitted_classes: [Regexp, Symbol], aliases: true
|
|
96
|
-
)
|
|
92
|
+
config_yaml = load_erb_templated_yaml(file_contents)
|
|
97
93
|
|
|
98
94
|
# For compatibility with Ruby 3.0 or lower.
|
|
99
95
|
if Gem::Version.new(Psych::VERSION) < Gem::Version.new('4.0.0')
|
|
@@ -103,7 +99,6 @@ module RuboCop
|
|
|
103
99
|
config_yaml&.dig('AllCops', 'CacheRootDirectory')
|
|
104
100
|
end
|
|
105
101
|
end
|
|
106
|
-
# rubocop:enable Metrics/MethodLength
|
|
107
102
|
|
|
108
103
|
def port_path
|
|
109
104
|
dir.join('port')
|
|
@@ -197,6 +192,16 @@ module RuboCop
|
|
|
197
192
|
path.exist? ? path.read : ''
|
|
198
193
|
end.join
|
|
199
194
|
end
|
|
195
|
+
|
|
196
|
+
private
|
|
197
|
+
|
|
198
|
+
def load_erb_templated_yaml(content)
|
|
199
|
+
require 'erb'
|
|
200
|
+
yaml_code = ERB.new(content).result
|
|
201
|
+
|
|
202
|
+
require 'yaml'
|
|
203
|
+
YAML.safe_load(yaml_code, permitted_classes: [Regexp, Symbol], aliases: true)
|
|
204
|
+
end
|
|
200
205
|
end
|
|
201
206
|
end
|
|
202
207
|
end
|
|
@@ -38,6 +38,16 @@ module RuboCop
|
|
|
38
38
|
warn 'RuboCop server is not running.' unless running
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
|
+
|
|
42
|
+
class << self
|
|
43
|
+
def args_config_file_path
|
|
44
|
+
first_args_config_key_index = ARGV.index { |value| ['-c', '--config'].include?(value) }
|
|
45
|
+
|
|
46
|
+
return if first_args_config_key_index.nil?
|
|
47
|
+
|
|
48
|
+
ARGV[first_args_config_key_index + 1]
|
|
49
|
+
end
|
|
50
|
+
end
|
|
41
51
|
end
|
|
42
52
|
end
|
|
43
53
|
end
|
|
@@ -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
|
|
@@ -42,11 +42,13 @@ module RuboCop
|
|
|
42
42
|
# Support Windows: Backslashes from command-line -> forward slashes
|
|
43
43
|
base_dir = base_dir.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
|
44
44
|
all_files = find_files(base_dir, File::FNM_DOTMATCH)
|
|
45
|
-
# use file.include? for performance optimization
|
|
46
|
-
hidden_files = all_files.select { |file| file.include?(HIDDEN_PATH_SUBSTRING) }.sort
|
|
47
45
|
base_dir_config = @config_store.for(base_dir)
|
|
48
46
|
|
|
49
|
-
target_files =
|
|
47
|
+
target_files = if hidden_path?(base_dir)
|
|
48
|
+
all_files.select { |file| ruby_file?(file) }
|
|
49
|
+
else
|
|
50
|
+
all_files.select { |file| to_inspect?(file, base_dir_config) }
|
|
51
|
+
end
|
|
50
52
|
|
|
51
53
|
target_files.sort_by!(&order)
|
|
52
54
|
end
|
|
@@ -70,18 +72,20 @@ module RuboCop
|
|
|
70
72
|
|
|
71
73
|
private
|
|
72
74
|
|
|
73
|
-
def to_inspect?(file,
|
|
75
|
+
def to_inspect?(file, base_dir_config)
|
|
74
76
|
return false if base_dir_config.file_to_exclude?(file)
|
|
75
|
-
return true if !
|
|
76
|
-
file <=> hidden_file
|
|
77
|
-
end && ruby_file?(file)
|
|
77
|
+
return true if !hidden_path?(file) && ruby_file?(file)
|
|
78
78
|
|
|
79
79
|
base_dir_config.file_to_include?(file)
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
+
def hidden_path?(path)
|
|
83
|
+
path.include?(HIDDEN_PATH_SUBSTRING)
|
|
84
|
+
end
|
|
85
|
+
|
|
82
86
|
def wanted_dir_patterns(base_dir, exclude_pattern, flags)
|
|
83
87
|
# Escape glob characters in base_dir to avoid unwanted behavior.
|
|
84
|
-
base_dir = base_dir.gsub(/[
|
|
88
|
+
base_dir = base_dir.gsub(/[\\{}\[\]*?]/) do |reserved_glob_character|
|
|
85
89
|
"\\#{reserved_glob_character}"
|
|
86
90
|
end
|
|
87
91
|
|
|
@@ -175,7 +179,7 @@ module RuboCop
|
|
|
175
179
|
end
|
|
176
180
|
|
|
177
181
|
def ruby_executable?(file)
|
|
178
|
-
return false
|
|
182
|
+
return false if !File.extname(file).empty? || !File.exist?(file) || File.empty?(file)
|
|
179
183
|
|
|
180
184
|
first_line = File.open(file, &:readline)
|
|
181
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 = {
|
|
@@ -110,8 +110,17 @@ module RuboCop
|
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
def version_from_gemspec_file(file)
|
|
113
|
+
# When using parser_prism, we need to use a Ruby version that Prism supports (3.3+)
|
|
114
|
+
# for parsing the gemspec file. This doesn't affect the detected Ruby version,
|
|
115
|
+
# it's just for the parsing step.
|
|
116
|
+
ruby_version_for_parsing = if @config.parser_engine == :parser_prism
|
|
117
|
+
3.3
|
|
118
|
+
else
|
|
119
|
+
DEFAULT_VERSION
|
|
120
|
+
end
|
|
121
|
+
|
|
113
122
|
processed_source = ProcessedSource.from_file(
|
|
114
|
-
file,
|
|
123
|
+
file, ruby_version_for_parsing, parser_engine: @config.parser_engine
|
|
115
124
|
)
|
|
116
125
|
return unless processed_source.valid_syntax?
|
|
117
126
|
|
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.81.7'
|
|
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,15 +54,16 @@ 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
|
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'
|
|
@@ -148,7 +150,6 @@ require_relative 'rubocop/cop/mixin/comments_help' # relies on visibility_help
|
|
|
148
150
|
require_relative 'rubocop/cop/mixin/def_node' # relies on visibility_help
|
|
149
151
|
|
|
150
152
|
require_relative 'rubocop/cop/utils/format_string'
|
|
151
|
-
require_relative 'rubocop/cop/utils/regexp_ranges'
|
|
152
153
|
|
|
153
154
|
require_relative 'rubocop/cop/migration/department_name'
|
|
154
155
|
|
|
@@ -179,6 +180,7 @@ require_relative 'rubocop/cop/bundler/insecure_protocol_source'
|
|
|
179
180
|
require_relative 'rubocop/cop/bundler/ordered_gems'
|
|
180
181
|
|
|
181
182
|
require_relative 'rubocop/cop/gemspec/add_runtime_dependency'
|
|
183
|
+
require_relative 'rubocop/cop/gemspec/attribute_assignment'
|
|
182
184
|
require_relative 'rubocop/cop/gemspec/dependency_version'
|
|
183
185
|
require_relative 'rubocop/cop/gemspec/deprecated_attribute_assignment'
|
|
184
186
|
require_relative 'rubocop/cop/gemspec/development_dependencies'
|
|
@@ -209,6 +211,7 @@ require_relative 'rubocop/cop/layout/empty_line_after_guard_clause'
|
|
|
209
211
|
require_relative 'rubocop/cop/layout/empty_line_after_magic_comment'
|
|
210
212
|
require_relative 'rubocop/cop/layout/empty_line_after_multiline_condition'
|
|
211
213
|
require_relative 'rubocop/cop/layout/empty_line_between_defs'
|
|
214
|
+
require_relative 'rubocop/cop/layout/empty_lines_after_module_inclusion'
|
|
212
215
|
require_relative 'rubocop/cop/layout/empty_lines_around_access_modifier'
|
|
213
216
|
require_relative 'rubocop/cop/layout/empty_lines_around_arguments'
|
|
214
217
|
require_relative 'rubocop/cop/layout/empty_lines_around_attribute_accessor'
|
|
@@ -288,6 +291,7 @@ require_relative 'rubocop/cop/layout/space_inside_string_interpolation'
|
|
|
288
291
|
require_relative 'rubocop/cop/layout/trailing_empty_lines'
|
|
289
292
|
require_relative 'rubocop/cop/layout/trailing_whitespace'
|
|
290
293
|
|
|
294
|
+
require_relative 'rubocop/cop/lint/utils/nil_receiver_checker'
|
|
291
295
|
require_relative 'rubocop/cop/lint/ambiguous_assignment'
|
|
292
296
|
require_relative 'rubocop/cop/lint/ambiguous_block_association'
|
|
293
297
|
require_relative 'rubocop/cop/lint/ambiguous_operator'
|
|
@@ -429,10 +433,12 @@ require_relative 'rubocop/cop/lint/uri_regexp'
|
|
|
429
433
|
require_relative 'rubocop/cop/lint/useless_access_modifier'
|
|
430
434
|
require_relative 'rubocop/cop/lint/useless_assignment'
|
|
431
435
|
require_relative 'rubocop/cop/lint/useless_constant_scoping'
|
|
436
|
+
require_relative 'rubocop/cop/lint/useless_default_value_argument'
|
|
432
437
|
require_relative 'rubocop/cop/lint/useless_defined'
|
|
433
438
|
require_relative 'rubocop/cop/lint/useless_else_without_rescue'
|
|
434
439
|
require_relative 'rubocop/cop/lint/useless_method_definition'
|
|
435
440
|
require_relative 'rubocop/cop/lint/useless_numeric_operation'
|
|
441
|
+
require_relative 'rubocop/cop/lint/useless_or'
|
|
436
442
|
require_relative 'rubocop/cop/lint/useless_rescue'
|
|
437
443
|
require_relative 'rubocop/cop/lint/useless_ruby2_keywords'
|
|
438
444
|
require_relative 'rubocop/cop/lint/useless_setter_call'
|
|
@@ -468,7 +474,8 @@ require_relative 'rubocop/cop/naming/memoized_instance_variable_name'
|
|
|
468
474
|
require_relative 'rubocop/cop/naming/method_name'
|
|
469
475
|
require_relative 'rubocop/cop/naming/method_parameter_name'
|
|
470
476
|
require_relative 'rubocop/cop/naming/binary_operator_parameter_name'
|
|
471
|
-
require_relative 'rubocop/cop/naming/
|
|
477
|
+
require_relative 'rubocop/cop/naming/predicate_method'
|
|
478
|
+
require_relative 'rubocop/cop/naming/predicate_prefix'
|
|
472
479
|
require_relative 'rubocop/cop/naming/rescued_exceptions_variable_name'
|
|
473
480
|
require_relative 'rubocop/cop/naming/variable_name'
|
|
474
481
|
require_relative 'rubocop/cop/naming/variable_number'
|
|
@@ -482,6 +489,7 @@ require_relative 'rubocop/cop/style/arguments_forwarding'
|
|
|
482
489
|
require_relative 'rubocop/cop/style/array_coercion'
|
|
483
490
|
require_relative 'rubocop/cop/style/array_first_last'
|
|
484
491
|
require_relative 'rubocop/cop/style/array_intersect'
|
|
492
|
+
require_relative 'rubocop/cop/style/array_intersect_with_single_element'
|
|
485
493
|
require_relative 'rubocop/cop/style/array_join'
|
|
486
494
|
require_relative 'rubocop/cop/style/ascii_comments'
|
|
487
495
|
require_relative 'rubocop/cop/style/attr'
|
|
@@ -503,6 +511,7 @@ require_relative 'rubocop/cop/style/class_methods_definitions'
|
|
|
503
511
|
require_relative 'rubocop/cop/style/class_vars'
|
|
504
512
|
require_relative 'rubocop/cop/style/collection_compact'
|
|
505
513
|
require_relative 'rubocop/cop/style/collection_methods'
|
|
514
|
+
require_relative 'rubocop/cop/style/collection_querying'
|
|
506
515
|
require_relative 'rubocop/cop/style/colon_method_call'
|
|
507
516
|
require_relative 'rubocop/cop/style/colon_method_definition'
|
|
508
517
|
require_relative 'rubocop/cop/style/combinable_defined'
|
|
@@ -510,6 +519,7 @@ require_relative 'rubocop/cop/style/combinable_loops'
|
|
|
510
519
|
require_relative 'rubocop/cop/style/command_literal'
|
|
511
520
|
require_relative 'rubocop/cop/style/comment_annotation'
|
|
512
521
|
require_relative 'rubocop/cop/style/commented_keyword'
|
|
522
|
+
require_relative 'rubocop/cop/style/comparable_between'
|
|
513
523
|
require_relative 'rubocop/cop/style/comparable_clamp'
|
|
514
524
|
require_relative 'rubocop/cop/style/concat_array_literals'
|
|
515
525
|
require_relative 'rubocop/cop/style/conditional_assignment'
|
|
@@ -536,6 +546,7 @@ require_relative 'rubocop/cop/style/empty_heredoc'
|
|
|
536
546
|
require_relative 'rubocop/cop/style/empty_lambda_parameter'
|
|
537
547
|
require_relative 'rubocop/cop/style/empty_literal'
|
|
538
548
|
require_relative 'rubocop/cop/style/empty_method'
|
|
549
|
+
require_relative 'rubocop/cop/style/empty_string_inside_interpolation'
|
|
539
550
|
require_relative 'rubocop/cop/style/endless_method'
|
|
540
551
|
require_relative 'rubocop/cop/style/encoding'
|
|
541
552
|
require_relative 'rubocop/cop/style/end_block'
|
|
@@ -564,6 +575,7 @@ require_relative 'rubocop/cop/style/hash_as_last_array_item'
|
|
|
564
575
|
require_relative 'rubocop/cop/style/hash_conversion'
|
|
565
576
|
require_relative 'rubocop/cop/style/hash_each_methods'
|
|
566
577
|
require_relative 'rubocop/cop/style/hash_except'
|
|
578
|
+
require_relative 'rubocop/cop/style/hash_fetch_chain'
|
|
567
579
|
require_relative 'rubocop/cop/style/hash_like_case'
|
|
568
580
|
require_relative 'rubocop/cop/style/hash_slice'
|
|
569
581
|
require_relative 'rubocop/cop/style/hash_syntax'
|
|
@@ -583,6 +595,7 @@ require_relative 'rubocop/cop/style/inline_comment'
|
|
|
583
595
|
require_relative 'rubocop/cop/style/invertible_unless_condition'
|
|
584
596
|
require_relative 'rubocop/cop/style/ip_addresses'
|
|
585
597
|
require_relative 'rubocop/cop/style/it_assignment'
|
|
598
|
+
require_relative 'rubocop/cop/style/it_block_parameter'
|
|
586
599
|
require_relative 'rubocop/cop/style/keyword_arguments_merging'
|
|
587
600
|
require_relative 'rubocop/cop/style/keyword_parameters_order'
|
|
588
601
|
require_relative 'rubocop/cop/style/lambda'
|
|
@@ -600,6 +613,7 @@ require_relative 'rubocop/cop/style/numbered_parameters'
|
|
|
600
613
|
require_relative 'rubocop/cop/style/open_struct_use'
|
|
601
614
|
require_relative 'rubocop/cop/style/operator_method_call'
|
|
602
615
|
require_relative 'rubocop/cop/style/redundant_array_constructor'
|
|
616
|
+
require_relative 'rubocop/cop/style/redundant_array_flatten'
|
|
603
617
|
require_relative 'rubocop/cop/style/redundant_assignment'
|
|
604
618
|
require_relative 'rubocop/cop/style/redundant_constant_base'
|
|
605
619
|
require_relative 'rubocop/cop/style/redundant_current_directory_in_path'
|
|
@@ -801,6 +815,7 @@ require_relative 'rubocop/options'
|
|
|
801
815
|
require_relative 'rubocop/remote_config'
|
|
802
816
|
require_relative 'rubocop/target_ruby'
|
|
803
817
|
require_relative 'rubocop/yaml_duplication_checker'
|
|
818
|
+
require_relative 'rubocop/pending_cops_reporter'
|
|
804
819
|
|
|
805
820
|
# rubocop:enable Style/RequireOrder
|
|
806
821
|
|
|
@@ -8,7 +8,10 @@ module RubyLsp
|
|
|
8
8
|
module RuboCop
|
|
9
9
|
# A Ruby LSP add-on for RuboCop.
|
|
10
10
|
class Addon < RubyLsp::Addon
|
|
11
|
-
|
|
11
|
+
RESTART_WATCHERS = %w[.rubocop.yml .rubocop_todo.yml .rubocop].freeze
|
|
12
|
+
|
|
13
|
+
def initialize
|
|
14
|
+
super
|
|
12
15
|
@runtime_adapter = nil
|
|
13
16
|
end
|
|
14
17
|
|
|
@@ -16,12 +19,16 @@ module RubyLsp
|
|
|
16
19
|
'RuboCop'
|
|
17
20
|
end
|
|
18
21
|
|
|
22
|
+
def version
|
|
23
|
+
::RuboCop::Version::STRING
|
|
24
|
+
end
|
|
25
|
+
|
|
19
26
|
def activate(global_state, message_queue)
|
|
20
27
|
::RuboCop::LSP::Logger.log(
|
|
21
28
|
"Activating RuboCop LSP addon #{::RuboCop::Version::STRING}.", prefix: '[RuboCop]'
|
|
22
29
|
)
|
|
23
30
|
|
|
24
|
-
@runtime_adapter = RuntimeAdapter.new
|
|
31
|
+
@runtime_adapter = RuntimeAdapter.new(message_queue)
|
|
25
32
|
global_state.register_formatter('rubocop', @runtime_adapter)
|
|
26
33
|
register_additional_file_watchers(global_state, message_queue)
|
|
27
34
|
|
|
@@ -34,7 +41,7 @@ module RubyLsp
|
|
|
34
41
|
@runtime_adapter = nil
|
|
35
42
|
end
|
|
36
43
|
|
|
37
|
-
# rubocop:disable
|
|
44
|
+
# rubocop:disable Metrics/MethodLength
|
|
38
45
|
def register_additional_file_watchers(global_state, message_queue)
|
|
39
46
|
return unless global_state.supports_watching_files
|
|
40
47
|
|
|
@@ -49,7 +56,7 @@ module RubyLsp
|
|
|
49
56
|
register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
|
|
50
57
|
watchers: [
|
|
51
58
|
Interface::FileSystemWatcher.new(
|
|
52
|
-
glob_pattern:
|
|
59
|
+
glob_pattern: "**/{#{RESTART_WATCHERS.join(',')}}",
|
|
53
60
|
kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE
|
|
54
61
|
)
|
|
55
62
|
]
|
|
@@ -59,16 +66,24 @@ module RubyLsp
|
|
|
59
66
|
)
|
|
60
67
|
)
|
|
61
68
|
end
|
|
62
|
-
# rubocop:enable
|
|
69
|
+
# rubocop:enable Metrics/MethodLength
|
|
63
70
|
|
|
64
71
|
def workspace_did_change_watched_files(changes)
|
|
65
|
-
|
|
72
|
+
if (changed_config_file = changed_config_file(changes))
|
|
73
|
+
@runtime_adapter.reload_config
|
|
74
|
+
|
|
75
|
+
::RuboCop::LSP::Logger.log(<<~MESSAGE, prefix: '[RuboCop]')
|
|
76
|
+
Re-initialized RuboCop LSP addon #{::RuboCop::Version::STRING} due to #{changed_config_file} change.
|
|
77
|
+
MESSAGE
|
|
78
|
+
end
|
|
79
|
+
end
|
|
66
80
|
|
|
67
|
-
|
|
81
|
+
private
|
|
68
82
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
83
|
+
def changed_config_file(changes)
|
|
84
|
+
RESTART_WATCHERS.find do |file_name|
|
|
85
|
+
changes.any? { |change| change[:uri].end_with?(file_name) }
|
|
86
|
+
end
|
|
72
87
|
end
|
|
73
88
|
end
|
|
74
89
|
end
|
|
@@ -7,20 +7,45 @@ module RubyLsp
|
|
|
7
7
|
# Provides an adapter to bridge RuboCop's built-in LSP runtime with Ruby LSP's add-on.
|
|
8
8
|
# @api private
|
|
9
9
|
class RuntimeAdapter
|
|
10
|
-
|
|
10
|
+
def initialize(message_queue)
|
|
11
|
+
@message_queue = message_queue
|
|
12
|
+
reload_config
|
|
13
|
+
end
|
|
11
14
|
|
|
12
|
-
def
|
|
13
|
-
|
|
15
|
+
def reload_config
|
|
16
|
+
@runtime = nil
|
|
17
|
+
options, _paths = ::RuboCop::Options.new.parse([])
|
|
14
18
|
|
|
19
|
+
config_store = ::RuboCop::ConfigStore.new
|
|
20
|
+
config_store.apply_options!(options)
|
|
15
21
|
@runtime = ::RuboCop::LSP::Runtime.new(config_store)
|
|
22
|
+
rescue ::RuboCop::Error => e
|
|
23
|
+
@message_queue << Notification.window_show_message(
|
|
24
|
+
"RuboCop configuration error: #{e.message}. Formatting will not be available.",
|
|
25
|
+
type: Constant::MessageType::ERROR
|
|
26
|
+
)
|
|
16
27
|
end
|
|
17
28
|
|
|
18
29
|
def run_diagnostic(uri, document)
|
|
19
|
-
|
|
30
|
+
with_error_handling do
|
|
31
|
+
@runtime.offenses(
|
|
32
|
+
uri_to_path(uri),
|
|
33
|
+
document.source,
|
|
34
|
+
document.encoding,
|
|
35
|
+
prism_result: prism_result(document)
|
|
36
|
+
)
|
|
37
|
+
end
|
|
20
38
|
end
|
|
21
39
|
|
|
22
40
|
def run_formatting(uri, document)
|
|
23
|
-
|
|
41
|
+
with_error_handling do
|
|
42
|
+
@runtime.format(
|
|
43
|
+
uri_to_path(uri),
|
|
44
|
+
document.source,
|
|
45
|
+
command: 'rubocop.formatAutocorrects',
|
|
46
|
+
prism_result: prism_result(document)
|
|
47
|
+
)
|
|
48
|
+
end
|
|
24
49
|
end
|
|
25
50
|
|
|
26
51
|
def run_range_formatting(_uri, _partial_source, _base_indentation)
|
|
@@ -33,6 +58,25 @@ module RubyLsp
|
|
|
33
58
|
|
|
34
59
|
private
|
|
35
60
|
|
|
61
|
+
def with_error_handling
|
|
62
|
+
return unless @runtime
|
|
63
|
+
|
|
64
|
+
yield
|
|
65
|
+
rescue StandardError => e
|
|
66
|
+
::RuboCop::LSP::Logger.log(e.full_message, prefix: '[RuboCop]')
|
|
67
|
+
|
|
68
|
+
message = if e.is_a?(::RuboCop::ErrorWithAnalyzedFileLocation)
|
|
69
|
+
"for the #{e.cop.name} cop"
|
|
70
|
+
else
|
|
71
|
+
"- #{e.message}"
|
|
72
|
+
end
|
|
73
|
+
raise Requests::Formatting::Error, <<~MSG
|
|
74
|
+
An internal error occurred #{message}.
|
|
75
|
+
Updating to a newer version of RuboCop may solve this.
|
|
76
|
+
For more details, run RuboCop on the command line.
|
|
77
|
+
MSG
|
|
78
|
+
end
|
|
79
|
+
|
|
36
80
|
# duplicated from: lib/standard/lsp/routes.rb
|
|
37
81
|
# modified to incorporate Ruby LSP's to_standardized_path method
|
|
38
82
|
def uri_to_path(uri)
|
|
@@ -42,6 +86,14 @@ module RubyLsp
|
|
|
42
86
|
uri.to_s.delete_prefix('file://')
|
|
43
87
|
end
|
|
44
88
|
end
|
|
89
|
+
|
|
90
|
+
def prism_result(document)
|
|
91
|
+
prism_result = document.parse_result
|
|
92
|
+
|
|
93
|
+
# NOTE: `prism_result` must be `Prism::ParseLexResult` compatible object.
|
|
94
|
+
# This is for compatibility parsed result unsupported.
|
|
95
|
+
prism_result.is_a?(Prism::ParseLexResult) ? prism_result : nil
|
|
96
|
+
end
|
|
45
97
|
end
|
|
46
98
|
end
|
|
47
99
|
end
|