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
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -22,6 +22,14 @@ module RuboCop
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
def self.inherited(_subclass)
|
26
|
+
super
|
27
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
28
|
+
Inheriting from `RuboCop::Cop::Cop` is deprecated. Use `RuboCop::Cop::Base` instead.
|
29
|
+
For more information, see https://docs.rubocop.org/rubocop/v1_upgrade_notes.html.
|
30
|
+
WARNING
|
31
|
+
end
|
32
|
+
|
25
33
|
def self.support_autocorrect?
|
26
34
|
method_defined?(:autocorrect)
|
27
35
|
end
|
@@ -37,16 +45,28 @@ module RuboCop
|
|
37
45
|
|
38
46
|
# @deprecated Use Registry.global
|
39
47
|
def self.registry
|
48
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
49
|
+
`Cop.registry` is deprecated. Use `Registry.global` instead.
|
50
|
+
WARNING
|
51
|
+
|
40
52
|
Registry.global
|
41
53
|
end
|
42
54
|
|
43
55
|
# @deprecated Use Registry.all
|
44
56
|
def self.all
|
57
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
58
|
+
`Cop.all` is deprecated. Use `Registry.all` instead.
|
59
|
+
WARNING
|
60
|
+
|
45
61
|
Registry.all
|
46
62
|
end
|
47
63
|
|
48
64
|
# @deprecated Use Registry.qualified_cop_name
|
49
65
|
def self.qualified_cop_name(name, origin)
|
66
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
67
|
+
`Cop.qualified_cop_name` is deprecated. Use `Registry.qualified_cop_name` instead.
|
68
|
+
WARNING
|
69
|
+
|
50
70
|
Registry.qualified_cop_name(name, origin)
|
51
71
|
end
|
52
72
|
|
@@ -58,7 +78,7 @@ module RuboCop
|
|
58
78
|
# template file, we convert it to location info in the original file.
|
59
79
|
range = range_for_original(range)
|
60
80
|
|
61
|
-
if block.nil? && !support_autocorrect?
|
81
|
+
if block.nil? && !self.class.support_autocorrect?
|
62
82
|
super(range, message: message, severity: severity)
|
63
83
|
else
|
64
84
|
super(range, message: message, severity: severity) do |corrector|
|
@@ -74,13 +94,19 @@ module RuboCop
|
|
74
94
|
|
75
95
|
# @deprecated Use class method
|
76
96
|
def support_autocorrect?
|
77
|
-
|
97
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
98
|
+
`support_autocorrect?` is deprecated. Use `cop.class.support_autocorrect?`.
|
99
|
+
WARNING
|
100
|
+
|
78
101
|
self.class.support_autocorrect?
|
79
102
|
end
|
80
103
|
|
81
104
|
# @deprecated
|
82
105
|
def corrections
|
83
|
-
|
106
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
107
|
+
`Cop#corrections` is deprecated.
|
108
|
+
WARNING
|
109
|
+
|
84
110
|
return [] unless @last_corrector
|
85
111
|
|
86
112
|
Legacy::CorrectionsProxy.new(@last_corrector)
|
@@ -136,7 +162,7 @@ module RuboCop
|
|
136
162
|
end
|
137
163
|
|
138
164
|
def correction_lambda
|
139
|
-
return unless support_autocorrect?
|
165
|
+
return unless self.class.support_autocorrect?
|
140
166
|
|
141
167
|
dedupe_on_node(@v0_argument) { autocorrect(@v0_argument) }
|
142
168
|
end
|
@@ -47,7 +47,7 @@ module RuboCop
|
|
47
47
|
if column_delta.positive? && range.resize(1).source != "\n"
|
48
48
|
corrector.insert_before(range, ' ' * column_delta)
|
49
49
|
elsif /\A[ \t]+\z/.match?(range.source)
|
50
|
-
remove(range
|
50
|
+
corrector.remove(range)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -96,17 +96,6 @@ module RuboCop
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
def remove(range, corrector)
|
100
|
-
original_stderr = $stderr
|
101
|
-
$stderr = StringIO.new # Avoid error messages on console
|
102
|
-
corrector.remove(range)
|
103
|
-
rescue RuntimeError
|
104
|
-
range = range_between(range.begin_pos + 1, range.end_pos + 1)
|
105
|
-
retry if /^ +$/.match?(range.source)
|
106
|
-
ensure
|
107
|
-
$stderr = original_stderr
|
108
|
-
end
|
109
|
-
|
110
99
|
def each_line(expr)
|
111
100
|
line_begin_pos = expr.begin_pos
|
112
101
|
expr.source.each_line do |line|
|
@@ -34,18 +34,14 @@ module RuboCop
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def offending_range
|
37
|
+
begin_range = block_node.source_range.begin
|
38
|
+
|
37
39
|
if block_node.arguments?
|
38
|
-
|
40
|
+
begin_range.join(argument_node.source_range.end)
|
39
41
|
else
|
40
|
-
|
42
|
+
begin_range.join(block_node.loc.begin.end)
|
41
43
|
end
|
42
44
|
end
|
43
|
-
|
44
|
-
def replacement_range(end_pos)
|
45
|
-
Parser::Source::Range.new(block_node.source_range.source_buffer,
|
46
|
-
block_node.source_range.begin_pos,
|
47
|
-
end_pos)
|
48
|
-
end
|
49
45
|
end
|
50
46
|
end
|
51
47
|
end
|
@@ -15,6 +15,8 @@ module RuboCop
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def call(corrector)
|
18
|
+
offending_range = for_node.source_range.begin.join(end_range)
|
19
|
+
|
18
20
|
corrector.replace(offending_range, correction)
|
19
21
|
end
|
20
22
|
|
@@ -40,11 +42,11 @@ module RuboCop
|
|
40
42
|
collection_node.range_type? || collection_node.or_type? || collection_node.and_type?
|
41
43
|
end
|
42
44
|
|
43
|
-
def
|
45
|
+
def end_range
|
44
46
|
if for_node.do?
|
45
|
-
keyword_begin.
|
47
|
+
keyword_begin.end
|
46
48
|
else
|
47
|
-
collection_end.
|
49
|
+
collection_end.end
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
@@ -59,16 +61,6 @@ module RuboCop
|
|
59
61
|
collection_node.source_range
|
60
62
|
end
|
61
63
|
end
|
62
|
-
|
63
|
-
def offending_range
|
64
|
-
replacement_range(end_position)
|
65
|
-
end
|
66
|
-
|
67
|
-
def replacement_range(end_pos)
|
68
|
-
Parser::Source::Range.new(for_node.source_range.source_buffer,
|
69
|
-
for_node.source_range.begin_pos,
|
70
|
-
end_pos)
|
71
|
-
end
|
72
64
|
end
|
73
65
|
end
|
74
66
|
end
|
@@ -51,6 +51,8 @@ module RuboCop
|
|
51
51
|
def semicolon(node)
|
52
52
|
@semicolon ||= {}.compare_by_identity
|
53
53
|
@semicolon[node] ||= processed_source.sorted_tokens.select(&:semicolon?).find do |token|
|
54
|
+
next if token.pos.end_pos <= node.source_range.begin_pos
|
55
|
+
|
54
56
|
same_line?(token, node.body) && trailing_class_definition?(token, node.body)
|
55
57
|
end
|
56
58
|
end
|
@@ -94,6 +94,16 @@ module RuboCop
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def substitute_escaped_delimiters(content, delimiters)
|
97
|
+
if delimiters.first != delimiters.last
|
98
|
+
# With different delimiters (eg. `[]`, `()`), if there are the same
|
99
|
+
# number of each, escaping is not necessary
|
100
|
+
delimiter_counts = delimiters.each_with_object({}) do |delimiter, counts|
|
101
|
+
counts[delimiter] = content.count(delimiter)
|
102
|
+
end
|
103
|
+
|
104
|
+
return content if delimiter_counts[delimiters.first] == delimiter_counts[delimiters.last]
|
105
|
+
end
|
106
|
+
|
97
107
|
delimiters.each { |delim| content.gsub!(delim, "\\#{delim}") }
|
98
108
|
end
|
99
109
|
|
@@ -16,24 +16,51 @@ module RuboCop
|
|
16
16
|
base = department_to_basename(cop_class.department)
|
17
17
|
fragment = cop_class.cop_name.downcase.gsub(/[^a-z]/, '')
|
18
18
|
base_url = base_url_for(cop_class, config)
|
19
|
+
extension = extension_for(cop_class, config)
|
19
20
|
|
20
|
-
"#{base_url}/#{base}
|
21
|
+
"#{base_url}/#{base}#{extension}##{fragment}" if base_url
|
21
22
|
end
|
22
23
|
|
23
24
|
# @api private
|
24
25
|
def base_url_for(cop_class, config)
|
25
|
-
|
26
|
+
if config
|
27
|
+
department_name = cop_class.department.to_s
|
28
|
+
url = config.for_department(department_name)['DocumentationBaseURL']
|
29
|
+
return url if url
|
30
|
+
end
|
26
31
|
|
27
|
-
|
32
|
+
default_base_url if builtin?(cop_class)
|
33
|
+
end
|
34
|
+
|
35
|
+
# @api private
|
36
|
+
def extension_for(cop_class, config)
|
37
|
+
if config
|
38
|
+
department_name = cop_class.department
|
39
|
+
extension = config.for_department(department_name)['DocumentationExtension']
|
40
|
+
return extension if extension
|
41
|
+
end
|
28
42
|
|
29
|
-
|
30
|
-
config.for_all_cops['DocumentationBaseURL']
|
43
|
+
default_extension
|
31
44
|
end
|
32
45
|
|
33
46
|
# @api private
|
34
47
|
def default_base_url
|
35
48
|
'https://docs.rubocop.org/rubocop'
|
36
49
|
end
|
50
|
+
|
51
|
+
# @api private
|
52
|
+
def default_extension
|
53
|
+
'.html'
|
54
|
+
end
|
55
|
+
|
56
|
+
# @api private
|
57
|
+
def builtin?(cop_class)
|
58
|
+
# any custom method will do
|
59
|
+
return false unless (m = cop_class.instance_methods(false).first)
|
60
|
+
|
61
|
+
path, _line = cop_class.instance_method(m).source_location
|
62
|
+
path.start_with?(__dir__)
|
63
|
+
end
|
37
64
|
end
|
38
65
|
end
|
39
66
|
end
|
@@ -8,7 +8,7 @@ module RuboCop
|
|
8
8
|
# The parameter name given is transformed into a method name (eg. `Max`
|
9
9
|
# becomes `self.max=` and `MinDigits` becomes `self.min_digits=`).
|
10
10
|
def exclude_limit(parameter_name, method_name: transform(parameter_name))
|
11
|
-
define_method("#{method_name}=") do |value|
|
11
|
+
define_method(:"#{method_name}=") do |value|
|
12
12
|
cfg = config_to_allow_offenses
|
13
13
|
cfg[:exclude_limit] ||= {}
|
14
14
|
current_max = cfg[:exclude_limit][parameter_name]
|
data/lib/rubocop/cop/force.rb
CHANGED
@@ -4,6 +4,16 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
# A scaffold for concrete forces.
|
6
6
|
class Force
|
7
|
+
# @api private
|
8
|
+
class HookError < StandardError
|
9
|
+
attr_reader :joining_cop
|
10
|
+
|
11
|
+
def initialize(joining_cop)
|
12
|
+
super
|
13
|
+
@joining_cop = joining_cop
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
7
17
|
attr_reader :cops
|
8
18
|
|
9
19
|
def self.all
|
@@ -32,6 +42,8 @@ module RuboCop
|
|
32
42
|
next unless cop.respond_to?(method_name)
|
33
43
|
|
34
44
|
cop.public_send(method_name, *args)
|
45
|
+
rescue StandardError
|
46
|
+
raise HookError, cop
|
35
47
|
end
|
36
48
|
end
|
37
49
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Gemspec
|
6
|
+
# Prefer `add_dependency` over `add_runtime_dependency` as the latter is
|
7
|
+
# considered soft-deprecated.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# Gem::Specification.new do |spec|
|
13
|
+
# spec.add_runtime_dependency('rubocop')
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# Gem::Specification.new do |spec|
|
18
|
+
# spec.add_dependency('rubocop')
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
class AddRuntimeDependency < Base
|
22
|
+
extend AutoCorrector
|
23
|
+
|
24
|
+
MSG = 'Use `add_dependency` instead of `add_runtime_dependency`.'
|
25
|
+
|
26
|
+
RESTRICT_ON_SEND = %i[add_runtime_dependency].freeze
|
27
|
+
|
28
|
+
def on_send(node)
|
29
|
+
return if !node.receiver || node.arguments.empty?
|
30
|
+
|
31
|
+
add_offense(node.loc.selector) do |corrector|
|
32
|
+
corrector.replace(node.loc.selector, 'add_dependency')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -101,13 +101,11 @@ module RuboCop
|
|
101
101
|
Array(cop_config['AllowedGems'])
|
102
102
|
end
|
103
103
|
|
104
|
-
def message(
|
105
|
-
gem_specification = range.source
|
106
|
-
|
104
|
+
def message(_range)
|
107
105
|
if required_style?
|
108
|
-
|
106
|
+
REQUIRED_MSG
|
109
107
|
elsif forbidden_style?
|
110
|
-
|
108
|
+
FORBIDDEN_MSG
|
111
109
|
end
|
112
110
|
end
|
113
111
|
|
@@ -31,8 +31,8 @@ module RuboCop
|
|
31
31
|
#
|
32
32
|
# # good
|
33
33
|
# Gem::Specification.new do |spec|
|
34
|
-
# spec.
|
35
|
-
# spec.
|
34
|
+
# spec.add_dependency('parallel', '~> 1.10')
|
35
|
+
# spec.add_dependency('parser', '>= 2.3.3.1', '< 3.0')
|
36
36
|
# end
|
37
37
|
class DuplicatedAssignment < Base
|
38
38
|
include RangeHelp
|
@@ -76,7 +76,9 @@ module RuboCop
|
|
76
76
|
PATTERN
|
77
77
|
|
78
78
|
def on_new_investigation
|
79
|
-
|
79
|
+
return if processed_source.ast && required_ruby_version?(processed_source.ast)
|
80
|
+
|
81
|
+
add_global_offense(MISSING_MSG)
|
80
82
|
end
|
81
83
|
|
82
84
|
def on_send(node)
|
@@ -110,6 +112,8 @@ module RuboCop
|
|
110
112
|
end
|
111
113
|
end
|
112
114
|
|
115
|
+
return unless required_ruby_version
|
116
|
+
|
113
117
|
required_ruby_version.str_content.scan(/\d/).first(2).join('.')
|
114
118
|
end
|
115
119
|
|
@@ -14,15 +14,15 @@ module RuboCop
|
|
14
14
|
# # bad
|
15
15
|
# Gem::Specification.new do |spec|
|
16
16
|
# if RUBY_VERSION >= '3.0'
|
17
|
-
# spec.
|
17
|
+
# spec.add_dependency 'gem_a'
|
18
18
|
# else
|
19
|
-
# spec.
|
19
|
+
# spec.add_dependency 'gem_b'
|
20
20
|
# end
|
21
21
|
# end
|
22
22
|
#
|
23
23
|
# # good
|
24
24
|
# Gem::Specification.new do |spec|
|
25
|
-
# spec.
|
25
|
+
# spec.add_dependency 'gem_a'
|
26
26
|
# end
|
27
27
|
#
|
28
28
|
class RubyVersionGlobalsUsage < Base
|
@@ -38,7 +38,8 @@ module RuboCop
|
|
38
38
|
CORRECTION_EXPECTATION_METHODS = %i[expect_correction expect_no_corrections].freeze
|
39
39
|
|
40
40
|
def on_send(node)
|
41
|
-
return unless (next_sibling = node.right_sibling)
|
41
|
+
return unless (next_sibling = node.right_sibling)
|
42
|
+
return unless next_sibling.respond_to?(:send_type?) && next_sibling.send_type?
|
42
43
|
|
43
44
|
method_name = next_sibling.method_name
|
44
45
|
return unless CORRECTION_EXPECTATION_METHODS.include?(method_name)
|
@@ -45,7 +45,8 @@ module RuboCop
|
|
45
45
|
EXPECT_OFFENSE_DESCRIPTION_MAPPING = {
|
46
46
|
/\A(does not|doesn't) (register|find|flag|report)/ => 'registers',
|
47
47
|
/\A(does not|doesn't) add (a|an|any )?offense/ => 'registers an offense',
|
48
|
-
/\
|
48
|
+
/\Aregisters no offense/ => 'registers an offense',
|
49
|
+
/\A(accepts|register)\b/ => 'registers'
|
49
50
|
}.freeze
|
50
51
|
|
51
52
|
EXPECT_NO_CORRECTIONS_DESCRIPTION_MAPPING = {
|
@@ -63,10 +64,10 @@ module RuboCop
|
|
63
64
|
expect_correction: EXPECT_CORRECTION_DESCRIPTION_MAPPING
|
64
65
|
}.freeze
|
65
66
|
|
66
|
-
# @!method offense_example
|
67
|
-
def_node_matcher :offense_example
|
67
|
+
# @!method offense_example(node)
|
68
|
+
def_node_matcher :offense_example, <<~PATTERN
|
68
69
|
(block
|
69
|
-
(send _ {:it :specify}
|
70
|
+
(send _ {:it :specify} $...)
|
70
71
|
_args
|
71
72
|
`(send nil? %RESTRICT_ON_SEND ...)
|
72
73
|
)
|
@@ -74,7 +75,7 @@ module RuboCop
|
|
74
75
|
|
75
76
|
def on_send(node)
|
76
77
|
parent = node.each_ancestor(:block).first
|
77
|
-
return unless parent && (current_description = offense_example
|
78
|
+
return unless parent && (current_description = offense_example(parent)&.first)
|
78
79
|
|
79
80
|
method_name = node.method_name
|
80
81
|
message = format(MSG, method_name: method_name)
|
@@ -30,6 +30,7 @@ module RuboCop
|
|
30
30
|
extend AutoCorrector
|
31
31
|
|
32
32
|
MSG = 'Use `%<method_name>s` instead of `%<method_suffix>s`.'
|
33
|
+
RESTRICT_ON_SEND = %i[end_with?].freeze
|
33
34
|
SUGGEST_METHOD_FOR_SUFFIX = {
|
34
35
|
'=' => 'assignment_method?',
|
35
36
|
'!' => 'bang_method?',
|
@@ -51,14 +52,15 @@ module RuboCop
|
|
51
52
|
|
52
53
|
def on_send(node)
|
53
54
|
method_name_end_with?(node) do |method_name_node, end_with_arg|
|
55
|
+
next unless method_name_node.receiver
|
56
|
+
|
57
|
+
preferred_method = SUGGEST_METHOD_FOR_SUFFIX[end_with_arg.value]
|
54
58
|
range = range(method_name_node, node)
|
55
|
-
message = format(
|
56
|
-
MSG,
|
57
|
-
method_name: SUGGEST_METHOD_FOR_SUFFIX[end_with_arg.value],
|
58
|
-
method_suffix: range.source
|
59
|
-
)
|
59
|
+
message = format(MSG, method_name: preferred_method, method_suffix: range.source)
|
60
60
|
|
61
|
-
add_offense(range, message: message)
|
61
|
+
add_offense(range, message: message) do |corrector|
|
62
|
+
corrector.replace(range, preferred_method)
|
63
|
+
end
|
62
64
|
end
|
63
65
|
end
|
64
66
|
alias on_csend on_send
|