rubocop 1.59.0 → 1.68.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +69 -70
- data/assets/output.css.erb +159 -0
- data/assets/output.html.erb +1 -160
- data/config/default.yml +165 -24
- data/config/internal_affairs.yml +11 -0
- data/exe/rubocop +4 -3
- data/lib/rubocop/cached_data.rb +21 -5
- data/lib/rubocop/cli/command/auto_generate_config.rb +18 -10
- data/lib/rubocop/cli/command/execute_runner.rb +1 -1
- data/lib/rubocop/cli/command/lsp.rb +4 -4
- data/lib/rubocop/cli/command/show_docs_url.rb +2 -2
- data/lib/rubocop/cli/command/version.rb +2 -2
- data/lib/rubocop/cli.rb +10 -1
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +41 -13
- data/lib/rubocop/config_finder.rb +12 -2
- data/lib/rubocop/config_loader.rb +15 -10
- data/lib/rubocop/config_loader_resolver.rb +13 -8
- data/lib/rubocop/config_obsoletion.rb +1 -1
- data/lib/rubocop/config_validator.rb +17 -9
- data/lib/rubocop/cop/autocorrect_logic.rb +28 -3
- data/lib/rubocop/cop/base.rb +73 -18
- data/lib/rubocop/cop/bundler/gem_version.rb +4 -5
- data/lib/rubocop/cop/cop.rb +30 -4
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +1 -12
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +4 -8
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +5 -13
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -0
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +10 -0
- data/lib/rubocop/cop/documentation.rb +32 -5
- data/lib/rubocop/cop/exclude_limit.rb +1 -1
- data/lib/rubocop/cop/force.rb +12 -0
- data/lib/rubocop/cop/gemspec/add_runtime_dependency.rb +38 -0
- data/lib/rubocop/cop/gemspec/dependency_version.rb +3 -5
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +5 -1
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +3 -3
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +0 -4
- data/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb +2 -1
- data/lib/rubocop/cop/internal_affairs/example_description.rb +6 -5
- data/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +8 -6
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +123 -29
- data/lib/rubocop/cop/internal_affairs/redundant_expect_offense_arguments.rb +34 -0
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +6 -21
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +8 -1
- data/lib/rubocop/cop/internal_affairs/undefined_config.rb +11 -1
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +0 -5
- data/lib/rubocop/cop/internal_affairs.rb +17 -0
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/assignment_indentation.rb +3 -2
- data/lib/rubocop/cop/layout/block_alignment.rb +30 -12
- data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/condition_position.rb +0 -4
- data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_comment.rb +3 -1
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +14 -7
- data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +8 -3
- data/lib/rubocop/cop/layout/end_alignment.rb +8 -2
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +18 -4
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +8 -0
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +5 -6
- data/lib/rubocop/cop/layout/leading_comment_space.rb +56 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +20 -20
- data/lib/rubocop/cop/layout/redundant_line_break.rb +14 -2
- data/lib/rubocop/cop/layout/space_around_operators.rb +3 -0
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +19 -10
- data/lib/rubocop/cop/layout/space_before_brackets.rb +5 -5
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +4 -0
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +3 -4
- data/lib/rubocop/cop/legacy/corrector.rb +12 -2
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +0 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +0 -2
- data/lib/rubocop/cop/lint/ambiguous_range.rb +4 -1
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +0 -2
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +2 -2
- data/lib/rubocop/cop/lint/big_decimal_new.rb +4 -7
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -3
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +0 -13
- data/lib/rubocop/cop/lint/debugger.rb +27 -6
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +0 -10
- data/lib/rubocop/cop/lint/duplicate_branch.rb +39 -4
- data/lib/rubocop/cop/lint/duplicate_case_condition.rb +1 -5
- data/lib/rubocop/cop/lint/duplicate_hash_key.rb +0 -4
- data/lib/rubocop/cop/lint/duplicate_methods.rb +0 -10
- data/lib/rubocop/cop/lint/duplicate_set_element.rb +74 -0
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +0 -4
- data/lib/rubocop/cop/lint/else_layout.rb +0 -2
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +29 -8
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -11
- data/lib/rubocop/cop/lint/empty_interpolation.rb +0 -4
- data/lib/rubocop/cop/lint/empty_when.rb +1 -3
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -9
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +21 -14
- data/lib/rubocop/cop/lint/float_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/float_out_of_range.rb +0 -4
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +0 -10
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +23 -12
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +0 -7
- data/lib/rubocop/cop/lint/interpolation_check.rb +0 -4
- data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +5 -14
- data/lib/rubocop/cop/lint/literal_as_condition.rb +1 -1
- data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +13 -6
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +25 -6
- data/lib/rubocop/cop/lint/loop.rb +6 -12
- data/lib/rubocop/cop/lint/mixed_case_range.rb +9 -4
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -7
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +0 -4
- data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +0 -5
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +7 -0
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +5 -6
- data/lib/rubocop/cop/lint/percent_string_array.rb +0 -4
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +0 -4
- data/lib/rubocop/cop/lint/rand_one.rb +0 -4
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +3 -1
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +14 -9
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +0 -4
- data/lib/rubocop/cop/lint/redundant_with_index.rb +4 -0
- data/lib/rubocop/cop/lint/require_parentheses.rb +0 -4
- data/lib/rubocop/cop/lint/rescue_exception.rb +0 -4
- data/lib/rubocop/cop/lint/rescue_type.rb +1 -3
- data/lib/rubocop/cop/lint/return_in_void_context.rb +0 -2
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +9 -4
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +107 -41
- data/lib/rubocop/cop/lint/script_permission.rb +3 -3
- data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +6 -10
- data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/syntax.rb +6 -3
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -3
- data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +88 -0
- data/lib/rubocop/cop/lint/unified_integer.rb +0 -4
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +4 -7
- data/lib/rubocop/cop/lint/unreachable_loop.rb +8 -2
- data/lib/rubocop/cop/lint/uri_regexp.rb +25 -7
- data/lib/rubocop/cop/lint/useless_assignment.rb +19 -16
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +0 -4
- data/lib/rubocop/cop/lint/useless_numeric_operation.rb +77 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +0 -4
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +41 -9
- data/lib/rubocop/cop/metrics/block_length.rb +6 -5
- data/lib/rubocop/cop/metrics/block_nesting.rb +19 -7
- data/lib/rubocop/cop/metrics/class_length.rb +6 -5
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +4 -1
- data/lib/rubocop/cop/metrics/method_length.rb +6 -5
- data/lib/rubocop/cop/metrics/module_length.rb +6 -5
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +5 -5
- data/lib/rubocop/cop/mixin/alignment.rb +5 -1
- data/lib/rubocop/cop/mixin/allowed_methods.rb +7 -1
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +15 -3
- data/lib/rubocop/cop/mixin/annotation_comment.rb +0 -2
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +10 -0
- data/lib/rubocop/cop/mixin/code_length.rb +12 -1
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -0
- data/lib/rubocop/cop/mixin/configurable_max.rb +5 -1
- data/lib/rubocop/cop/mixin/endless_method_rewriter.rb +24 -0
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +22 -10
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +9 -2
- data/lib/rubocop/cop/mixin/line_length_help.rb +7 -2
- data/lib/rubocop/cop/mixin/method_complexity.rb +15 -6
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/percent_array.rb +1 -1
- data/lib/rubocop/cop/mixin/rescue_node.rb +4 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -2
- data/lib/rubocop/cop/mixin/string_literals_help.rb +12 -0
- data/lib/rubocop/cop/naming/accessor_method_name.rb +5 -0
- data/lib/rubocop/cop/naming/block_forwarding.rb +33 -6
- data/lib/rubocop/cop/naming/file_name.rb +2 -2
- data/lib/rubocop/cop/naming/inclusive_language.rb +13 -5
- data/lib/rubocop/cop/naming/predicate_name.rb +55 -29
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -1
- data/lib/rubocop/cop/offense.rb +4 -5
- data/lib/rubocop/cop/registry.rb +1 -1
- data/lib/rubocop/cop/security/compound_hash.rb +2 -2
- data/lib/rubocop/cop/security/open.rb +2 -2
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +62 -2
- data/lib/rubocop/cop/style/accessor_grouping.rb +10 -2
- data/lib/rubocop/cop/style/alias.rb +2 -1
- data/lib/rubocop/cop/style/ambiguous_endless_method_definition.rb +79 -0
- data/lib/rubocop/cop/style/arguments_forwarding.rb +141 -24
- data/lib/rubocop/cop/style/bitwise_predicate.rb +100 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +31 -3
- data/lib/rubocop/cop/style/case_like_if.rb +1 -1
- data/lib/rubocop/cop/style/class_vars.rb +3 -3
- data/lib/rubocop/cop/style/collection_compact.rb +19 -10
- data/lib/rubocop/cop/style/combinable_defined.rb +115 -0
- data/lib/rubocop/cop/style/combinable_loops.rb +7 -0
- data/lib/rubocop/cop/style/commented_keyword.rb +12 -3
- data/lib/rubocop/cop/style/conditional_assignment.rb +7 -8
- data/lib/rubocop/cop/style/copyright.rb +31 -21
- data/lib/rubocop/cop/style/data_inheritance.rb +1 -1
- data/lib/rubocop/cop/style/def_with_parentheses.rb +0 -2
- data/lib/rubocop/cop/style/documentation.rb +24 -24
- data/lib/rubocop/cop/style/documentation_method.rb +20 -0
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +7 -8
- data/lib/rubocop/cop/style/empty_else.rb +6 -5
- data/lib/rubocop/cop/style/empty_heredoc.rb +1 -14
- data/lib/rubocop/cop/style/empty_literal.rb +31 -22
- data/lib/rubocop/cop/style/endless_method.rb +1 -14
- data/lib/rubocop/cop/style/eval_with_location.rb +16 -24
- data/lib/rubocop/cop/style/exact_regexp_match.rb +2 -1
- data/lib/rubocop/cop/style/file_read.rb +2 -5
- data/lib/rubocop/cop/style/file_write.rb +2 -5
- data/lib/rubocop/cop/style/for.rb +2 -0
- data/lib/rubocop/cop/style/format_string.rb +9 -9
- data/lib/rubocop/cop/style/format_string_token.rb +2 -2
- data/lib/rubocop/cop/style/global_std_stream.rb +7 -1
- data/lib/rubocop/cop/style/guard_clause.rb +17 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +35 -8
- data/lib/rubocop/cop/style/hash_except.rb +8 -5
- data/lib/rubocop/cop/style/hash_syntax.rb +26 -4
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +5 -2
- data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +5 -4
- data/lib/rubocop/cop/style/if_with_semicolon.rb +49 -6
- data/lib/rubocop/cop/style/in_pattern_then.rb +6 -2
- data/lib/rubocop/cop/style/inverse_methods.rb +8 -8
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +46 -4
- data/lib/rubocop/cop/style/keyword_arguments_merging.rb +67 -0
- data/lib/rubocop/cop/style/lambda.rb +1 -1
- data/lib/rubocop/cop/style/magic_comment_format.rb +1 -1
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +81 -50
- data/lib/rubocop/cop/style/map_into_array.rb +233 -0
- data/lib/rubocop/cop/style/map_to_hash.rb +10 -6
- data/lib/rubocop/cop/style/map_to_set.rb +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +29 -11
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/missing_else.rb +0 -4
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/multiline_method_signature.rb +10 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +5 -3
- data/lib/rubocop/cop/style/multiline_when_then.rb +0 -4
- data/lib/rubocop/cop/style/multiple_comparison.rb +28 -47
- data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
- data/lib/rubocop/cop/style/nil_comparison.rb +2 -0
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +12 -4
- data/lib/rubocop/cop/style/object_then.rb +5 -3
- data/lib/rubocop/cop/style/one_line_conditional.rb +6 -2
- data/lib/rubocop/cop/style/operator_method_call.rb +25 -6
- data/lib/rubocop/cop/style/parallel_assignment.rb +8 -9
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -0
- data/lib/rubocop/cop/style/quoted_symbols.rb +1 -3
- data/lib/rubocop/cop/style/raise_args.rb +4 -1
- data/lib/rubocop/cop/style/redundant_argument.rb +25 -2
- data/lib/rubocop/cop/style/redundant_assignment.rb +10 -2
- data/lib/rubocop/cop/style/redundant_begin.rb +5 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +4 -4
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +5 -4
- data/lib/rubocop/cop/style/redundant_each.rb +7 -4
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -1
- data/lib/rubocop/cop/style/redundant_filter_chain.rb +1 -1
- data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +46 -0
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +40 -7
- data/lib/rubocop/cop/style/redundant_parentheses.rb +27 -13
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +4 -1
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -24
- data/lib/rubocop/cop/style/redundant_return.rb +6 -0
- data/lib/rubocop/cop/style/require_order.rb +2 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +13 -1
- data/lib/rubocop/cop/style/return_nil_in_predicate_method_definition.rb +54 -12
- data/lib/rubocop/cop/style/safe_navigation.rb +106 -52
- data/lib/rubocop/cop/style/safe_navigation_chain_length.rb +52 -0
- data/lib/rubocop/cop/style/sample.rb +1 -3
- data/lib/rubocop/cop/style/select_by_regexp.rb +9 -6
- data/lib/rubocop/cop/style/semicolon.rb +1 -1
- data/lib/rubocop/cop/style/send.rb +4 -4
- data/lib/rubocop/cop/style/send_with_literal_method_name.rb +104 -0
- data/lib/rubocop/cop/style/slicing_with_range.rb +76 -10
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +21 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -2
- data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
- data/lib/rubocop/cop/style/super_arguments.rb +174 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +75 -5
- data/lib/rubocop/cop/style/ternary_parentheses.rb +26 -5
- data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/while_until_do.rb +0 -2
- data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +32 -24
- data/lib/rubocop/cop/team.rb +27 -3
- data/lib/rubocop/cop/util.rb +8 -2
- data/lib/rubocop/cop/utils/regexp_ranges.rb +1 -1
- data/lib/rubocop/cop/variable_force/assignment.rb +18 -3
- data/lib/rubocop/cop/variable_force/branch.rb +1 -1
- data/lib/rubocop/cop/variable_force/variable.rb +5 -1
- data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
- data/lib/rubocop/cop/variable_force.rb +13 -1
- data/lib/rubocop/cops_documentation_generator.rb +96 -43
- data/lib/rubocop/core_ext/string.rb +2 -6
- data/lib/rubocop/directive_comment.rb +10 -8
- data/lib/rubocop/ext/regexp_node.rb +18 -35
- data/lib/rubocop/ext/regexp_parser.rb +4 -21
- data/lib/rubocop/file_finder.rb +9 -4
- data/lib/rubocop/formatter/clang_style_formatter.rb +3 -7
- data/lib/rubocop/formatter/disabled_config_formatter.rb +24 -9
- data/lib/rubocop/formatter/formatter_set.rb +7 -1
- data/lib/rubocop/formatter/html_formatter.rb +32 -10
- data/lib/rubocop/formatter/json_formatter.rb +0 -1
- data/lib/rubocop/formatter/junit_formatter.rb +70 -23
- data/lib/rubocop/formatter/offense_count_formatter.rb +12 -2
- data/lib/rubocop/formatter/tap_formatter.rb +3 -7
- data/lib/rubocop/formatter.rb +1 -1
- data/lib/rubocop/lockfile.rb +58 -7
- data/lib/rubocop/lsp/logger.rb +1 -1
- data/lib/rubocop/lsp/routes.rb +12 -15
- data/lib/rubocop/lsp/runtime.rb +3 -1
- data/lib/rubocop/lsp/server.rb +6 -2
- data/lib/rubocop/lsp/severity.rb +1 -1
- data/lib/rubocop/lsp.rb +36 -0
- data/lib/rubocop/magic_comment.rb +1 -1
- data/lib/rubocop/options.rb +17 -12
- data/lib/rubocop/path_util.rb +6 -2
- data/lib/rubocop/rake_task.rb +1 -1
- data/lib/rubocop/remote_config.rb +5 -1
- data/lib/rubocop/result_cache.rb +2 -8
- data/lib/rubocop/rspec/cop_helper.rb +8 -2
- data/lib/rubocop/rspec/expect_offense.rb +17 -8
- data/lib/rubocop/rspec/shared_contexts.rb +75 -18
- data/lib/rubocop/rspec/support.rb +3 -0
- data/lib/rubocop/runner.rb +31 -9
- data/lib/rubocop/server/cache.rb +16 -2
- data/lib/rubocop/server/client_command/exec.rb +2 -3
- data/lib/rubocop/server/client_command/start.rb +1 -1
- data/lib/rubocop/server/core.rb +5 -0
- data/lib/rubocop/server/server_command/exec.rb +0 -1
- data/lib/rubocop/target_finder.rb +84 -78
- data/lib/rubocop/target_ruby.rb +87 -81
- data/lib/rubocop/version.rb +45 -9
- data/lib/rubocop/yaml_duplication_checker.rb +20 -26
- data/lib/rubocop.rb +21 -1
- metadata +33 -35
- /data/lib/rubocop/formatter/{git_hub_actions_formatter.rb → github_actions_formatter.rb} +0 -0
@@ -12,7 +12,11 @@ module RuboCop
|
|
12
12
|
CACHE_LIFETIME = 24 * 60 * 60
|
13
13
|
|
14
14
|
def initialize(url, base_dir)
|
15
|
-
|
15
|
+
begin
|
16
|
+
@uri = URI.parse(url)
|
17
|
+
rescue URI::InvalidURIError
|
18
|
+
raise ConfigNotFoundError, "Failed to resolve configuration: '#{url}' is not a valid URI"
|
19
|
+
end
|
16
20
|
@base_dir = base_dir
|
17
21
|
end
|
18
22
|
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -222,19 +222,13 @@ module RuboCop
|
|
222
222
|
options.to_s.gsub(/[^a-z]+/i, '_')
|
223
223
|
end
|
224
224
|
|
225
|
-
# The external dependency checksums are cached per RuboCop team so that
|
226
|
-
# the checksums don't need to be recomputed for each file.
|
227
|
-
def team_checksum(team)
|
228
|
-
@checksum_by_team ||= {}.compare_by_identity
|
229
|
-
@checksum_by_team[team] ||= team.external_dependency_checksum
|
230
|
-
end
|
231
|
-
|
232
225
|
# We combine team and options into a single "context" checksum to avoid
|
233
226
|
# making file names that are too long for some filesystems to handle.
|
234
227
|
# This context is for anything that's not (1) the RuboCop executable
|
235
228
|
# checksum or (2) the inspected file checksum.
|
236
229
|
def context_checksum(team, options)
|
237
|
-
|
230
|
+
keys = [team.external_dependency_checksum, relevant_options_digest(options)]
|
231
|
+
Digest::SHA1.hexdigest(keys.join)
|
238
232
|
end
|
239
233
|
end
|
240
234
|
end
|
@@ -6,7 +6,11 @@ require 'tempfile'
|
|
6
6
|
module CopHelper
|
7
7
|
extend RSpec::SharedContext
|
8
8
|
|
9
|
-
let(:ruby_version)
|
9
|
+
let(:ruby_version) do
|
10
|
+
# The minimum version Prism can parse is 3.3.
|
11
|
+
ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : RuboCop::TargetRuby::DEFAULT_VERSION
|
12
|
+
end
|
13
|
+
let(:parser_engine) { ENV.fetch('PARSER_ENGINE', :parser_whitequark).to_sym }
|
10
14
|
let(:rails_version) { false }
|
11
15
|
|
12
16
|
def inspect_source(source, file = nil)
|
@@ -28,7 +32,9 @@ module CopHelper
|
|
28
32
|
file = file.path
|
29
33
|
end
|
30
34
|
|
31
|
-
processed_source = RuboCop::ProcessedSource.new(
|
35
|
+
processed_source = RuboCop::ProcessedSource.new(
|
36
|
+
source, ruby_version, file, parser_engine: parser_engine
|
37
|
+
)
|
32
38
|
processed_source.config = configuration
|
33
39
|
processed_source.registry = registry
|
34
40
|
processed_source
|
@@ -111,6 +111,7 @@ module RuboCop
|
|
111
111
|
source
|
112
112
|
end
|
113
113
|
|
114
|
+
# rubocop:disable Metrics/AbcSize
|
114
115
|
def expect_offense(source, file = nil, severity: nil, chomp: false, **replacements)
|
115
116
|
expected_annotations = parse_annotations(source, **replacements)
|
116
117
|
source = expected_annotations.plain_source
|
@@ -123,10 +124,17 @@ module RuboCop
|
|
123
124
|
expect(actual_annotations).to eq(expected_annotations), ''
|
124
125
|
expect(@offenses.map(&:severity).uniq).to eq([severity]) if severity
|
125
126
|
|
127
|
+
# Validate that all offenses have a range that formatters can display
|
128
|
+
expect do
|
129
|
+
@offenses.each { |offense| offense.location.source_line }
|
130
|
+
end.not_to raise_error, 'One of the offenses has a misconstructed range, for ' \
|
131
|
+
'example if the offense is on line 1 and the source is empty'
|
132
|
+
|
126
133
|
@offenses
|
127
134
|
end
|
135
|
+
# rubocop:enable Metrics/AbcSize
|
128
136
|
|
129
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
|
137
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
|
130
138
|
def expect_correction(correction, loop: true, source: nil)
|
131
139
|
if source
|
132
140
|
expected_annotations = parse_annotations(source, raise_error: false)
|
@@ -148,7 +156,6 @@ module RuboCop
|
|
148
156
|
|
149
157
|
break corrected_source unless loop
|
150
158
|
break corrected_source if @last_corrector.empty?
|
151
|
-
break corrected_source if corrected_source == @processed_source.buffer.source
|
152
159
|
|
153
160
|
if iteration > RuboCop::Runner::MAX_ITERATIONS
|
154
161
|
raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [@offenses])
|
@@ -162,20 +169,22 @@ module RuboCop
|
|
162
169
|
raise 'Expected correction but no corrections were made' if new_source == source
|
163
170
|
|
164
171
|
expect(new_source).to eq(correction)
|
172
|
+
expect(@processed_source).to be_valid_syntax, 'Expected correction to be valid syntax'
|
165
173
|
end
|
166
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
|
174
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
|
167
175
|
|
168
176
|
def expect_no_corrections
|
169
177
|
raise '`expect_no_corrections` must follow `expect_offense`' unless @processed_source
|
170
178
|
|
171
179
|
return if @last_corrector.empty?
|
172
180
|
|
173
|
-
#
|
174
|
-
# we need to run the actual corrections
|
175
|
-
|
181
|
+
# This is just here for a pretty diff if the source actually got changed
|
176
182
|
new_source = @last_corrector.rewrite
|
177
|
-
|
178
183
|
expect(new_source).to eq(@processed_source.buffer.source)
|
184
|
+
|
185
|
+
# There is an infinite loop if a corrector is present that did not make
|
186
|
+
# any changes. It will cause the same offense/correction on the next loop.
|
187
|
+
raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [@offenses])
|
179
188
|
end
|
180
189
|
|
181
190
|
def expect_no_offenses(source, file = nil)
|
@@ -212,7 +221,7 @@ module RuboCop
|
|
212
221
|
|
213
222
|
# Parsed representation of code annotated with the `^^^ Message` style
|
214
223
|
class AnnotatedSource
|
215
|
-
ANNOTATION_PATTERN = /\A\s*(\^+|\^{})
|
224
|
+
ANNOTATION_PATTERN = /\A\s*(\^+|\^{}) ?/.freeze
|
216
225
|
ABBREV = "[...]\n"
|
217
226
|
|
218
227
|
# @param annotated_source [String] string passed to the matchers
|
@@ -50,6 +50,26 @@ RSpec.shared_context 'isolated environment' do # rubocop:disable Metrics/BlockLe
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
# Workaround for https://github.com/rubocop/rubocop/issues/12978,
|
54
|
+
# there should already be no gemfile in the temp directory
|
55
|
+
RSpec.shared_context 'isolated bundler' do
|
56
|
+
around do |example|
|
57
|
+
# No bundler env and reset cached gemfile path
|
58
|
+
Bundler.with_unbundled_env do
|
59
|
+
old_values = Bundler.instance_variables.to_h do |name|
|
60
|
+
[name, Bundler.instance_variable_get(name)]
|
61
|
+
end
|
62
|
+
Bundler.instance_variables.each { |name| Bundler.remove_instance_variable(name) }
|
63
|
+
example.call
|
64
|
+
ensure
|
65
|
+
Bundler.instance_variables.each { |name| Bundler.remove_instance_variable(name) }
|
66
|
+
old_values.each do |name, value|
|
67
|
+
Bundler.instance_variable_set(name, value)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
53
73
|
RSpec.shared_context 'maintain registry' do
|
54
74
|
around(:each) { |example| RuboCop::Cop::Registry.with_temporary_global { example.run } }
|
55
75
|
|
@@ -66,9 +86,9 @@ RSpec.shared_context 'config' do # rubocop:disable Metrics/BlockLength
|
|
66
86
|
|
67
87
|
let(:cop_class) do
|
68
88
|
unless described_class.is_a?(Class) && described_class < RuboCop::Cop::Base
|
69
|
-
raise 'Specify which cop class to use (e.g `let(:cop_class) { RuboCop::Cop::Base }
|
70
|
-
'or RuboCop::Cop::Cop for legacy)'
|
89
|
+
raise 'Specify which cop class to use (e.g `let(:cop_class) { RuboCop::Cop::Base }`)'
|
71
90
|
end
|
91
|
+
|
72
92
|
described_class
|
73
93
|
end
|
74
94
|
|
@@ -100,17 +120,29 @@ RSpec.shared_context 'config' do # rubocop:disable Metrics/BlockLength
|
|
100
120
|
let(:cur_cop_config) do
|
101
121
|
RuboCop::ConfigLoader
|
102
122
|
.default_configuration.for_cop(cop_class)
|
103
|
-
.merge(
|
104
|
-
|
105
|
-
|
106
|
-
|
123
|
+
.merge(
|
124
|
+
'Enabled' => true, # in case it is 'pending'
|
125
|
+
'AutoCorrect' => 'always' # in case defaults set it to 'disabled' or false
|
126
|
+
)
|
107
127
|
.merge(cop_config)
|
108
128
|
end
|
109
129
|
|
110
130
|
let(:config) do
|
111
131
|
hash = { 'AllCops' => all_cops_config, cop_class.cop_name => cur_cop_config }.merge!(other_cops)
|
112
132
|
|
113
|
-
RuboCop::Config.new(hash, "#{Dir.pwd}/.rubocop.yml")
|
133
|
+
config = RuboCop::Config.new(hash, "#{Dir.pwd}/.rubocop.yml")
|
134
|
+
|
135
|
+
rails_version_in_gemfile = Gem::Version.new(
|
136
|
+
rails_version || RuboCop::Config::DEFAULT_RAILS_VERSION
|
137
|
+
)
|
138
|
+
|
139
|
+
allow(config).to receive(:gem_versions_in_target).and_return(
|
140
|
+
{
|
141
|
+
'railties' => rails_version_in_gemfile
|
142
|
+
}
|
143
|
+
)
|
144
|
+
|
145
|
+
config
|
114
146
|
end
|
115
147
|
|
116
148
|
let(:cop) { cop_class.new(config, cop_options) }
|
@@ -128,50 +160,75 @@ RSpec.shared_context 'mock console output' do
|
|
128
160
|
end
|
129
161
|
end
|
130
162
|
|
163
|
+
RSpec.shared_context 'lsp' do
|
164
|
+
before do
|
165
|
+
RuboCop::LSP.enable
|
166
|
+
end
|
167
|
+
|
168
|
+
after do
|
169
|
+
RuboCop::LSP.disable
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
131
173
|
RSpec.shared_context 'ruby 2.0' do
|
132
|
-
|
174
|
+
# Prism supports parsing Ruby 3.3+.
|
175
|
+
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 2.0 }
|
133
176
|
end
|
134
177
|
|
135
178
|
RSpec.shared_context 'ruby 2.1' do
|
136
|
-
|
179
|
+
# Prism supports parsing Ruby 3.3+.
|
180
|
+
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 2.1 }
|
137
181
|
end
|
138
182
|
|
139
183
|
RSpec.shared_context 'ruby 2.2' do
|
140
|
-
|
184
|
+
# Prism supports parsing Ruby 3.3+.
|
185
|
+
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 2.2 }
|
141
186
|
end
|
142
187
|
|
143
188
|
RSpec.shared_context 'ruby 2.3' do
|
144
|
-
|
189
|
+
# Prism supports parsing Ruby 3.3+.
|
190
|
+
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 2.3 }
|
145
191
|
end
|
146
192
|
|
147
193
|
RSpec.shared_context 'ruby 2.4' do
|
148
|
-
|
194
|
+
# Prism supports parsing Ruby 3.3+.
|
195
|
+
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 2.4 }
|
149
196
|
end
|
150
197
|
|
151
198
|
RSpec.shared_context 'ruby 2.5' do
|
152
|
-
|
199
|
+
# Prism supports parsing Ruby 3.3+.
|
200
|
+
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 2.5 }
|
153
201
|
end
|
154
202
|
|
155
203
|
RSpec.shared_context 'ruby 2.6' do
|
156
|
-
|
204
|
+
# Prism supports parsing Ruby 3.3+.
|
205
|
+
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 2.6 }
|
157
206
|
end
|
158
207
|
|
159
208
|
RSpec.shared_context 'ruby 2.7' do
|
160
|
-
|
209
|
+
# Prism supports parsing Ruby 3.3+.
|
210
|
+
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 2.7 }
|
161
211
|
end
|
162
212
|
|
163
213
|
RSpec.shared_context 'ruby 3.0' do
|
164
|
-
|
214
|
+
# Prism supports parsing Ruby 3.3+.
|
215
|
+
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 3.0 }
|
165
216
|
end
|
166
217
|
|
167
218
|
RSpec.shared_context 'ruby 3.1' do
|
168
|
-
|
219
|
+
# Prism supports parsing Ruby 3.3+.
|
220
|
+
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 3.1 }
|
169
221
|
end
|
170
222
|
|
171
223
|
RSpec.shared_context 'ruby 3.2' do
|
172
|
-
|
224
|
+
# Prism supports parsing Ruby 3.3+.
|
225
|
+
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : 3.2 }
|
173
226
|
end
|
174
227
|
|
175
228
|
RSpec.shared_context 'ruby 3.3' do
|
176
229
|
let(:ruby_version) { 3.3 }
|
177
230
|
end
|
231
|
+
|
232
|
+
RSpec.shared_context 'ruby 3.4' do
|
233
|
+
let(:ruby_version) { 3.4 }
|
234
|
+
end
|
@@ -13,6 +13,8 @@ RSpec.configure do |config|
|
|
13
13
|
config.include HostEnvironmentSimulatorHelper
|
14
14
|
config.include_context 'config', :config
|
15
15
|
config.include_context 'isolated environment', :isolated_environment
|
16
|
+
config.include_context 'isolated bundler', :isolated_bundler
|
17
|
+
config.include_context 'lsp', :lsp
|
16
18
|
config.include_context 'maintain registry', :restore_registry
|
17
19
|
config.include_context 'ruby 2.0', :ruby20
|
18
20
|
config.include_context 'ruby 2.1', :ruby21
|
@@ -26,4 +28,5 @@ RSpec.configure do |config|
|
|
26
28
|
config.include_context 'ruby 3.1', :ruby31
|
27
29
|
config.include_context 'ruby 3.2', :ruby32
|
28
30
|
config.include_context 'ruby 3.3', :ruby33
|
31
|
+
config.include_context 'ruby 3.4', :ruby34
|
29
32
|
end
|
data/lib/rubocop/runner.rb
CHANGED
@@ -20,7 +20,11 @@ module RuboCop
|
|
20
20
|
message = 'Infinite loop detected'
|
21
21
|
message += " in #{path}" if path
|
22
22
|
message += " and caused by #{root_cause}" if root_cause
|
23
|
-
|
23
|
+
message += "\n"
|
24
|
+
hint = 'Hint: Please update to the latest RuboCop version if not already in use, ' \
|
25
|
+
"and report a bug if the issue still occurs on this version.\n" \
|
26
|
+
'Please check the latest version at https://rubygems.org/gems/rubocop.'
|
27
|
+
super(Rainbow(message).red + Rainbow(hint).yellow)
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
@@ -135,7 +139,7 @@ module RuboCop
|
|
135
139
|
offenses = process_file(file)
|
136
140
|
yield file
|
137
141
|
|
138
|
-
if offenses.any? { |o| considered_failure?(o) }
|
142
|
+
if offenses.any? { |o| considered_failure?(o) && offense_displayed?(o) }
|
139
143
|
break false if @options[:fail_fast]
|
140
144
|
|
141
145
|
next false
|
@@ -358,6 +362,13 @@ module RuboCop
|
|
358
362
|
self.class.ruby_extractors.find do |ruby_extractor|
|
359
363
|
result = ruby_extractor.call(processed_source)
|
360
364
|
break result if result
|
365
|
+
rescue StandardError
|
366
|
+
location = if ruby_extractor.is_a?(Proc)
|
367
|
+
ruby_extractor.source_location
|
368
|
+
else
|
369
|
+
ruby_extractor.method(:call).source_location
|
370
|
+
end
|
371
|
+
raise Error, "Ruby extractor #{location[0]} failed to process #{processed_source.path}."
|
361
372
|
end
|
362
373
|
end
|
363
374
|
|
@@ -429,18 +440,22 @@ module RuboCop
|
|
429
440
|
!offense.corrected? && offense.severity >= minimum_severity_to_fail
|
430
441
|
end
|
431
442
|
|
432
|
-
def
|
443
|
+
def offense_displayed?(offense)
|
433
444
|
if @options[:display_only_fail_level_offenses]
|
434
|
-
|
445
|
+
considered_failure?(offense)
|
435
446
|
elsif @options[:display_only_safe_correctable]
|
436
|
-
|
447
|
+
supports_safe_autocorrect?(offense)
|
437
448
|
elsif @options[:display_only_correctable]
|
438
|
-
|
449
|
+
offense.correctable?
|
439
450
|
else
|
440
|
-
|
451
|
+
true
|
441
452
|
end
|
442
453
|
end
|
443
454
|
|
455
|
+
def offenses_to_report(offenses)
|
456
|
+
offenses.select { |o| offense_displayed?(o) }
|
457
|
+
end
|
458
|
+
|
444
459
|
def supports_safe_autocorrect?(offense)
|
445
460
|
cop_class = Cop::Registry.global.find_by_cop_name(offense.cop_name)
|
446
461
|
default_cfg = default_config(offense.cop_name)
|
@@ -467,15 +482,21 @@ module RuboCop
|
|
467
482
|
end
|
468
483
|
end
|
469
484
|
|
485
|
+
# rubocop:disable Metrics/MethodLength
|
470
486
|
def get_processed_source(file)
|
471
487
|
config = @config_store.for_file(file)
|
472
488
|
ruby_version = config.target_ruby_version
|
489
|
+
parser_engine = config.parser_engine
|
473
490
|
|
474
491
|
processed_source = if @options[:stdin]
|
475
|
-
ProcessedSource.new(
|
492
|
+
ProcessedSource.new(
|
493
|
+
@options[:stdin], ruby_version, file, parser_engine: parser_engine
|
494
|
+
)
|
476
495
|
else
|
477
496
|
begin
|
478
|
-
ProcessedSource.from_file(
|
497
|
+
ProcessedSource.from_file(
|
498
|
+
file, ruby_version, parser_engine: parser_engine
|
499
|
+
)
|
479
500
|
rescue Errno::ENOENT
|
480
501
|
raise RuboCop::Error, "No such file or directory: #{file}"
|
481
502
|
end
|
@@ -484,6 +505,7 @@ module RuboCop
|
|
484
505
|
processed_source.registry = mobilized_cop_classes(config)
|
485
506
|
processed_source
|
486
507
|
end
|
508
|
+
# rubocop:enable Metrics/MethodLength
|
487
509
|
|
488
510
|
# A Cop::Team instance is stateful and may change when inspecting.
|
489
511
|
# The "standby" team for a given config is an initialized but
|
data/lib/rubocop/server/cache.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'digest'
|
4
4
|
require 'pathname'
|
5
5
|
require_relative '../cache_config'
|
6
6
|
require_relative '../config_finder'
|
@@ -20,6 +20,7 @@ module RuboCop
|
|
20
20
|
# @api private
|
21
21
|
class Cache
|
22
22
|
GEMFILE_NAMES = %w[Gemfile gems.rb].freeze
|
23
|
+
LOCKFILE_NAMES = %w[Gemfile.lock gems.locked].freeze
|
23
24
|
|
24
25
|
class << self
|
25
26
|
attr_accessor :cache_root_path
|
@@ -42,6 +43,19 @@ module RuboCop
|
|
42
43
|
@project_dir_cache_key ||= project_dir[1..].tr('/', '+')
|
43
44
|
end
|
44
45
|
|
46
|
+
# rubocop:disable Metrics/AbcSize
|
47
|
+
def restart_key
|
48
|
+
lockfile_path = LOCKFILE_NAMES.map do |lockfile_name|
|
49
|
+
Pathname(project_dir).join(lockfile_name)
|
50
|
+
end.find(&:exist?)
|
51
|
+
version_data = lockfile_path&.read || RuboCop::Version::STRING
|
52
|
+
config_data = Pathname(ConfigFinder.find_config_path(Dir.pwd)).read
|
53
|
+
todo_data = (rubocop_todo = Pathname('.rubocop_todo.yml')).exist? ? rubocop_todo.read : ''
|
54
|
+
|
55
|
+
Digest::SHA1.hexdigest(version_data + config_data + todo_data)
|
56
|
+
end
|
57
|
+
# rubocop:enable Metrics/AbcSize
|
58
|
+
|
45
59
|
def dir
|
46
60
|
Pathname.new(File.join(cache_path, project_dir_cache_key)).tap do |d|
|
47
61
|
d.mkpath unless d.exist?
|
@@ -117,7 +131,7 @@ module RuboCop
|
|
117
131
|
|
118
132
|
def pid_running?
|
119
133
|
Process.kill(0, pid_path.read.to_i) == 1
|
120
|
-
rescue Errno::ESRCH, Errno::ENOENT, Errno::EACCES
|
134
|
+
rescue Errno::ESRCH, Errno::ENOENT, Errno::EACCES, Errno::EROFS, Errno::ENAMETOOLONG
|
121
135
|
false
|
122
136
|
end
|
123
137
|
|
@@ -17,7 +17,6 @@ module RuboCop
|
|
17
17
|
class Exec < Base
|
18
18
|
def run
|
19
19
|
ensure_server!
|
20
|
-
Cache.status_path.delete if Cache.status_path.file?
|
21
20
|
read_stdin = ARGV.include?('-s') || ARGV.include?('--stdin')
|
22
21
|
send_request(
|
23
22
|
command: 'exec',
|
@@ -42,7 +41,7 @@ module RuboCop
|
|
42
41
|
end
|
43
42
|
|
44
43
|
def incompatible_version?
|
45
|
-
Cache.version_path.read !=
|
44
|
+
Cache.version_path.read != Cache.restart_key
|
46
45
|
end
|
47
46
|
|
48
47
|
def stderr
|
@@ -55,7 +54,7 @@ module RuboCop
|
|
55
54
|
end
|
56
55
|
|
57
56
|
status = Cache.status_path.read
|
58
|
-
raise "RuboCop server: '#{status}' is not a valid status!"
|
57
|
+
raise "RuboCop server: '#{status}' is not a valid status!" unless /\A\d+\z/.match?(status)
|
59
58
|
|
60
59
|
status.to_i
|
61
60
|
end
|
data/lib/rubocop/server/core.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'securerandom'
|
4
4
|
require 'socket'
|
5
|
+
require 'stringio'
|
5
6
|
|
6
7
|
#
|
7
8
|
# This code is based on https://github.com/fohte/rubocop-daemon.
|
@@ -44,6 +45,10 @@ module RuboCop
|
|
44
45
|
write_port_and_token_files
|
45
46
|
|
46
47
|
pid = fork do
|
48
|
+
if defined?(RubyVM::YJIT.enable)
|
49
|
+
RubyVM::YJIT.enable
|
50
|
+
end
|
51
|
+
|
47
52
|
Process.daemon(true)
|
48
53
|
$stderr.reopen(Cache.stderr_path, 'w')
|
49
54
|
process_input
|
@@ -16,7 +16,6 @@ module RuboCop
|
|
16
16
|
# @api private
|
17
17
|
class Exec < Base
|
18
18
|
def run
|
19
|
-
Cache.status_path.delete if Cache.status_path.file?
|
20
19
|
# RuboCop output is colorized by default where there is a TTY.
|
21
20
|
# We must pass the --color option to preserve this behavior.
|
22
21
|
@args.unshift('--color') unless %w[--color --no-color].any? { |f| @args.include?(f) }
|