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
@@ -0,0 +1,174 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# Checks for redundant argument forwarding when calling super with arguments identical to
|
7
|
+
# the method definition.
|
8
|
+
#
|
9
|
+
# Using zero arity `super` within a `define_method` block results in `RuntimeError`:
|
10
|
+
#
|
11
|
+
# [source,ruby]
|
12
|
+
# ----
|
13
|
+
# def m
|
14
|
+
# define_method(:foo) { super() } # => OK
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# def m
|
18
|
+
# define_method(:foo) { super } # => RuntimeError
|
19
|
+
# end
|
20
|
+
# ----
|
21
|
+
#
|
22
|
+
# Furthermore, any arguments accompanied by a block may potentially be delegating to
|
23
|
+
# `define_method`, therefore, `super` used within these blocks will be allowed.
|
24
|
+
# This approach might result in false negatives, yet ensuring safe detection takes precedence.
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# # bad
|
28
|
+
# def method(*args, **kwargs)
|
29
|
+
# super(*args, **kwargs)
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # good - implicitly passing all arguments
|
33
|
+
# def method(*args, **kwargs)
|
34
|
+
# super
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# # good - forwarding a subset of the arguments
|
38
|
+
# def method(*args, **kwargs)
|
39
|
+
# super(*args)
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# # good - forwarding no arguments
|
43
|
+
# def method(*args, **kwargs)
|
44
|
+
# super()
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# # good - assigning to the block variable before calling super
|
48
|
+
# def method(&block)
|
49
|
+
# # Assigning to the block variable would pass the old value to super,
|
50
|
+
# # under this circumstance the block must be referenced explicitly.
|
51
|
+
# block ||= proc { 'fallback behavior' }
|
52
|
+
# super(&block)
|
53
|
+
# end
|
54
|
+
class SuperArguments < Base
|
55
|
+
extend AutoCorrector
|
56
|
+
|
57
|
+
DEF_TYPES = %i[def defs].freeze
|
58
|
+
ASSIGN_TYPES = %i[or_asgn lvasgn].freeze
|
59
|
+
|
60
|
+
MSG = 'Call `super` without arguments and parentheses when the signature is identical.'
|
61
|
+
|
62
|
+
def on_super(super_node)
|
63
|
+
def_node = super_node.ancestors.find do |node|
|
64
|
+
# When defining dynamic methods, implicitly calling `super` is not possible.
|
65
|
+
# Since there is a possibility of delegation to `define_method`,
|
66
|
+
# `super` used within the block is always allowed.
|
67
|
+
break if node.block_type?
|
68
|
+
|
69
|
+
break node if DEF_TYPES.include?(node.type)
|
70
|
+
end
|
71
|
+
return unless def_node
|
72
|
+
return unless arguments_identical?(def_node, def_node.arguments.argument_list,
|
73
|
+
super_node.arguments)
|
74
|
+
|
75
|
+
add_offense(super_node) { |corrector| corrector.replace(super_node, 'super') }
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
81
|
+
def arguments_identical?(def_node, def_args, super_args)
|
82
|
+
super_args = preprocess_super_args(super_args)
|
83
|
+
return false if def_args.size != super_args.size
|
84
|
+
|
85
|
+
def_args.zip(super_args).each do |def_arg, super_arg|
|
86
|
+
next if positional_arg_same?(def_arg, super_arg)
|
87
|
+
next if positional_rest_arg_same(def_arg, super_arg)
|
88
|
+
next if keyword_arg_same?(def_arg, super_arg)
|
89
|
+
next if keyword_rest_arg_same?(def_arg, super_arg)
|
90
|
+
next if block_arg_same?(def_node, def_arg, super_arg)
|
91
|
+
next if forward_arg_same?(def_arg, super_arg)
|
92
|
+
|
93
|
+
return false
|
94
|
+
end
|
95
|
+
true
|
96
|
+
end
|
97
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
98
|
+
|
99
|
+
def positional_arg_same?(def_arg, super_arg)
|
100
|
+
return false unless def_arg.arg_type? || def_arg.optarg_type?
|
101
|
+
return false unless super_arg.lvar_type?
|
102
|
+
|
103
|
+
def_arg.name == super_arg.children.first
|
104
|
+
end
|
105
|
+
|
106
|
+
def positional_rest_arg_same(def_arg, super_arg)
|
107
|
+
return false unless def_arg.restarg_type?
|
108
|
+
# anonymous forwarding
|
109
|
+
return true if def_arg.name.nil? && super_arg.forwarded_restarg_type?
|
110
|
+
return false unless super_arg.splat_type?
|
111
|
+
return false unless (lvar_node = super_arg.children.first).lvar_type?
|
112
|
+
|
113
|
+
def_arg.name == lvar_node.children.first
|
114
|
+
end
|
115
|
+
|
116
|
+
def keyword_arg_same?(def_arg, super_arg)
|
117
|
+
return false unless def_arg.kwarg_type? || def_arg.kwoptarg_type?
|
118
|
+
return false unless (pair_node = super_arg).pair_type?
|
119
|
+
return false unless (sym_node = pair_node.key).sym_type?
|
120
|
+
return false unless (lvar_node = pair_node.value).lvar_type?
|
121
|
+
return false unless sym_node.source == lvar_node.source
|
122
|
+
|
123
|
+
def_arg.name == sym_node.value
|
124
|
+
end
|
125
|
+
|
126
|
+
def keyword_rest_arg_same?(def_arg, super_arg)
|
127
|
+
return false unless def_arg.kwrestarg_type?
|
128
|
+
# anonymous forwarding
|
129
|
+
return true if def_arg.name.nil? && super_arg.forwarded_kwrestarg_type?
|
130
|
+
return false unless super_arg.kwsplat_type?
|
131
|
+
return false unless (lvar_node = super_arg.children.first).lvar_type?
|
132
|
+
|
133
|
+
def_arg.name == lvar_node.children.first
|
134
|
+
end
|
135
|
+
|
136
|
+
def block_arg_same?(def_node, def_arg, super_arg)
|
137
|
+
return false unless def_arg.blockarg_type? && super_arg.block_pass_type?
|
138
|
+
# anonymous forwarding
|
139
|
+
return true if (block_pass_child = super_arg.children.first).nil? && def_arg.name.nil?
|
140
|
+
|
141
|
+
block_arg_name = block_pass_child.children.first
|
142
|
+
def_arg.name == block_arg_name && !block_reassigned?(def_node, block_arg_name)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Reassigning the block argument will still pass along the original block to super
|
146
|
+
# https://bugs.ruby-lang.org/issues/20505
|
147
|
+
def block_reassigned?(def_node, block_arg_name)
|
148
|
+
def_node.each_node(*ASSIGN_TYPES).any? do |assign_node|
|
149
|
+
# TODO: Since `Symbol#name` is supported from Ruby 3.0, the inheritance check for
|
150
|
+
# `AST::Node` can be removed when requiring Ruby 3.0+.
|
151
|
+
lhs = assign_node.node_parts[0]
|
152
|
+
next if lhs.is_a?(AST::Node) && !lhs.respond_to?(:name)
|
153
|
+
|
154
|
+
assign_node.name == block_arg_name
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def forward_arg_same?(def_arg, super_arg)
|
159
|
+
def_arg.forward_arg_type? && super_arg.forwarded_args_type?
|
160
|
+
end
|
161
|
+
|
162
|
+
def preprocess_super_args(super_args)
|
163
|
+
super_args.flat_map do |node|
|
164
|
+
if node.hash_type? && !node.braces?
|
165
|
+
node.children
|
166
|
+
else
|
167
|
+
node
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -37,6 +37,42 @@ module RuboCop
|
|
37
37
|
# # ArgumentError: wrong number of arguments (given 1, expected 0)
|
38
38
|
# ----
|
39
39
|
#
|
40
|
+
# It is also unsafe because `Symbol#to_proc` does not work with
|
41
|
+
# `protected` methods which would otherwise be accessible.
|
42
|
+
#
|
43
|
+
# For example:
|
44
|
+
#
|
45
|
+
# [source,ruby]
|
46
|
+
# ----
|
47
|
+
# class Box
|
48
|
+
# def initialize
|
49
|
+
# @secret = rand
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# def normal_matches?(*others)
|
53
|
+
# others.map { |other| other.secret }.any?(secret)
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# def symbol_to_proc_matches?(*others)
|
57
|
+
# others.map(&:secret).any?(secret)
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# protected
|
61
|
+
#
|
62
|
+
# attr_reader :secret
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# boxes = [Box.new, Box.new]
|
66
|
+
# Box.new.normal_matches?(*boxes)
|
67
|
+
# # => false
|
68
|
+
# boxes.first.normal_matches?(*boxes)
|
69
|
+
# # => true
|
70
|
+
# Box.new.symbol_to_proc_matches?(*boxes)
|
71
|
+
# # => NoMethodError: protected method `secret' called for #<Box...>
|
72
|
+
# boxes.first.symbol_to_proc_matches?(*boxes)
|
73
|
+
# # => NoMethodError: protected method `secret' called for #<Box...>
|
74
|
+
# ----
|
75
|
+
#
|
40
76
|
# @example
|
41
77
|
# # bad
|
42
78
|
# something.map { |s| s.upcase }
|
@@ -84,6 +120,23 @@ module RuboCop
|
|
84
120
|
# # good
|
85
121
|
# something.map { |s| s.upcase }
|
86
122
|
#
|
123
|
+
# @example AllCops:ActiveSupportExtensionsEnabled: false (default)
|
124
|
+
# # bad
|
125
|
+
# ->(x) { x.foo }
|
126
|
+
# proc { |x| x.foo }
|
127
|
+
# Proc.new { |x| x.foo }
|
128
|
+
#
|
129
|
+
# # good
|
130
|
+
# lambda(&:foo)
|
131
|
+
# proc(&:foo)
|
132
|
+
# Proc.new(&:foo)
|
133
|
+
#
|
134
|
+
# @example AllCops:ActiveSupportExtensionsEnabled: true
|
135
|
+
# # good
|
136
|
+
# ->(x) { x.foo }
|
137
|
+
# proc { |x| x.foo }
|
138
|
+
# Proc.new { |x| x.foo }
|
139
|
+
#
|
87
140
|
class SymbolProc < Base
|
88
141
|
include CommentsHelp
|
89
142
|
include RangeHelp
|
@@ -93,6 +146,7 @@ module RuboCop
|
|
93
146
|
|
94
147
|
MSG = 'Pass `&:%<method>s` as an argument to `%<block_method>s` instead of a block.'
|
95
148
|
SUPER_TYPES = %i[super zsuper].freeze
|
149
|
+
LAMBDA_OR_PROC = %i[lambda proc].freeze
|
96
150
|
|
97
151
|
# @!method proc_node?(node)
|
98
152
|
def_node_matcher :proc_node?, '(send (const {nil? cbase} :Proc) :new)'
|
@@ -115,13 +169,12 @@ module RuboCop
|
|
115
169
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
116
170
|
def on_block(node)
|
117
171
|
symbol_proc?(node) do |dispatch_node, arguments_node, method_name|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
172
|
+
if active_support_extensions_enabled?
|
173
|
+
return if proc_node?(dispatch_node)
|
174
|
+
return if LAMBDA_OR_PROC.include?(dispatch_node.method_name)
|
175
|
+
end
|
122
176
|
return if unsafe_hash_usage?(dispatch_node)
|
123
177
|
return if unsafe_array_usage?(dispatch_node)
|
124
|
-
return if %i[lambda proc].include?(dispatch_node.method_name)
|
125
178
|
return if allowed_method_name?(dispatch_node.method_name)
|
126
179
|
return if allow_if_method_has_argument?(node.send_node)
|
127
180
|
return if node.block_type? && destructuring_block_argument?(arguments_node)
|
@@ -170,6 +223,15 @@ module RuboCop
|
|
170
223
|
end
|
171
224
|
|
172
225
|
def autocorrect_without_args(corrector, node)
|
226
|
+
if node.send_node.lambda_literal?
|
227
|
+
if node.send_node.loc.selector.source == '->'
|
228
|
+
corrector.replace(node, "lambda(&:#{node.body.method_name})")
|
229
|
+
return
|
230
|
+
else
|
231
|
+
autocorrect_lambda_block(corrector, node)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
173
235
|
corrector.replace(block_range_with_space(node), "(&:#{node.body.method_name})")
|
174
236
|
end
|
175
237
|
|
@@ -182,6 +244,14 @@ module RuboCop
|
|
182
244
|
corrector.remove(block_range_with_space(node))
|
183
245
|
end
|
184
246
|
|
247
|
+
def autocorrect_lambda_block(corrector, node)
|
248
|
+
send_node_loc = node.send_node.loc
|
249
|
+
corrector.replace(send_node_loc.selector, 'lambda')
|
250
|
+
|
251
|
+
range = range_between(send_node_loc.selector.end_pos, node.loc.begin.end_pos - 2)
|
252
|
+
corrector.remove(range)
|
253
|
+
end
|
254
|
+
|
185
255
|
def block_range_with_space(node)
|
186
256
|
block_range = range_between(begin_pos_for_replacement(node), node.loc.end.end_pos)
|
187
257
|
range_with_surrounding_space(block_range, side: :left)
|
@@ -75,7 +75,7 @@ module RuboCop
|
|
75
75
|
|
76
76
|
message = message(node)
|
77
77
|
|
78
|
-
add_offense(node
|
78
|
+
add_offense(node, message: message) do |corrector|
|
79
79
|
autocorrect(corrector, node)
|
80
80
|
end
|
81
81
|
end
|
@@ -171,9 +171,7 @@ module RuboCop
|
|
171
171
|
end
|
172
172
|
|
173
173
|
def unsafe_autocorrect?(condition)
|
174
|
-
condition.children.any?
|
175
|
-
unparenthesized_method_call?(child) || below_ternary_precedence?(child)
|
176
|
-
end
|
174
|
+
condition.children.any? { |child| below_ternary_precedence?(child) }
|
177
175
|
end
|
178
176
|
|
179
177
|
def unparenthesized_method_call?(child)
|
@@ -192,7 +190,7 @@ module RuboCop
|
|
192
190
|
# @!method method_name(node)
|
193
191
|
def_node_matcher :method_name, <<~PATTERN
|
194
192
|
{($:defined? _ ...)
|
195
|
-
(
|
193
|
+
(call {_ nil?} $_ _ ...)}
|
196
194
|
PATTERN
|
197
195
|
|
198
196
|
def correct_parenthesized(corrector, condition)
|
@@ -203,16 +201,39 @@ module RuboCop
|
|
203
201
|
# If we remove the parentheses, we need to add a space or we'll
|
204
202
|
# generate invalid code.
|
205
203
|
corrector.insert_after(condition.loc.end, ' ') unless whitespace_after?(condition)
|
204
|
+
|
205
|
+
if (send_node = condition.child_nodes.last) && node_args_need_parens?(send_node)
|
206
|
+
parenthesize_condition_arguments(corrector, send_node)
|
207
|
+
end
|
206
208
|
end
|
207
209
|
|
208
210
|
def correct_unparenthesized(corrector, condition)
|
209
211
|
corrector.wrap(condition, '(', ')')
|
210
212
|
end
|
211
213
|
|
214
|
+
def parenthesize_condition_arguments(corrector, send_node)
|
215
|
+
range_start = send_node.defined_type? ? send_node.loc.keyword : send_node.loc.selector
|
216
|
+
opening_range = range_start.end.join(send_node.first_argument.source_range.begin)
|
217
|
+
|
218
|
+
corrector.replace(opening_range, '(')
|
219
|
+
corrector.insert_after(send_node.last_argument, ')')
|
220
|
+
end
|
221
|
+
|
212
222
|
def whitespace_after?(node)
|
213
223
|
last_token = processed_source.last_token_of(node)
|
214
224
|
last_token.space_after?
|
215
225
|
end
|
226
|
+
|
227
|
+
def node_args_need_parens?(send_node)
|
228
|
+
return false unless node_with_args?(send_node)
|
229
|
+
return false if send_node.arguments.none? || send_node.parenthesized?
|
230
|
+
|
231
|
+
send_node.dot? || send_node.safe_navigation? || unparenthesized_method_call?(send_node)
|
232
|
+
end
|
233
|
+
|
234
|
+
def node_with_args?(node)
|
235
|
+
node.call_type? || node.defined_type?
|
236
|
+
end
|
216
237
|
end
|
217
238
|
end
|
218
239
|
end
|
@@ -48,14 +48,19 @@ module RuboCop
|
|
48
48
|
check_nonzero_length_comparison(node)
|
49
49
|
end
|
50
50
|
|
51
|
+
def on_csend(node)
|
52
|
+
check_zero_length_predicate(node)
|
53
|
+
check_zero_length_comparison(node)
|
54
|
+
end
|
55
|
+
|
51
56
|
private
|
52
57
|
|
53
58
|
def check_zero_length_predicate(node)
|
54
|
-
return unless
|
59
|
+
return unless zero_length_predicate?(node.parent)
|
55
60
|
return if non_polymorphic_collection?(node.parent)
|
56
61
|
|
57
62
|
offense = node.loc.selector.join(node.parent.source_range.end)
|
58
|
-
message = format(ZERO_MSG, current:
|
63
|
+
message = format(ZERO_MSG, current: offense.source)
|
59
64
|
|
60
65
|
add_offense(offense, message: message) do |corrector|
|
61
66
|
corrector.replace(offense, 'empty?')
|
@@ -92,44 +97,47 @@ module RuboCop
|
|
92
97
|
end
|
93
98
|
end
|
94
99
|
|
95
|
-
# @!method zero_length_predicate(node)
|
96
|
-
def_node_matcher :zero_length_predicate
|
97
|
-
(
|
100
|
+
# @!method zero_length_predicate?(node)
|
101
|
+
def_node_matcher :zero_length_predicate?, <<~PATTERN
|
102
|
+
(call (call (...) {:length :size}) :zero?)
|
98
103
|
PATTERN
|
99
104
|
|
100
105
|
# @!method zero_length_comparison(node)
|
101
106
|
def_node_matcher :zero_length_comparison, <<~PATTERN
|
102
|
-
{(
|
103
|
-
(
|
104
|
-
(
|
105
|
-
(
|
107
|
+
{(call (call (...) ${:length :size}) $:== (int $0))
|
108
|
+
(call (int $0) $:== (call (...) ${:length :size}))
|
109
|
+
(call (call (...) ${:length :size}) $:< (int $1))
|
110
|
+
(call (int $1) $:> (call (...) ${:length :size}))}
|
106
111
|
PATTERN
|
107
112
|
|
108
113
|
# @!method nonzero_length_comparison(node)
|
109
114
|
def_node_matcher :nonzero_length_comparison, <<~PATTERN
|
110
|
-
{(
|
111
|
-
(
|
115
|
+
{(call (call (...) ${:length :size}) ${:> :!=} (int $0))
|
116
|
+
(call (int $0) ${:< :!=} (call (...) ${:length :size}))}
|
112
117
|
PATTERN
|
113
118
|
|
114
119
|
def replacement(node)
|
115
|
-
|
116
|
-
|
120
|
+
length_node = zero_length_node(node)
|
121
|
+
if length_node&.receiver
|
122
|
+
return "#{length_node.receiver.source}#{length_node.loc.dot.source}empty?"
|
123
|
+
end
|
117
124
|
|
118
|
-
|
125
|
+
other_length_node = other_length_node(node)
|
126
|
+
"!#{other_length_node.receiver.source}#{other_length_node.loc.dot.source}empty?"
|
119
127
|
end
|
120
128
|
|
121
|
-
# @!method
|
122
|
-
def_node_matcher :
|
123
|
-
{(send (
|
124
|
-
(send (int 0) :== (
|
125
|
-
(send (
|
126
|
-
(send (int 1) :> (
|
129
|
+
# @!method zero_length_node(node)
|
130
|
+
def_node_matcher :zero_length_node, <<~PATTERN
|
131
|
+
{(send $(call _ _) :== (int 0))
|
132
|
+
(send (int 0) :== $(call _ _))
|
133
|
+
(send $(call _ _) :< (int 1))
|
134
|
+
(send (int 1) :> $(call _ _))}
|
127
135
|
PATTERN
|
128
136
|
|
129
|
-
# @!method
|
130
|
-
def_node_matcher :
|
131
|
-
{(
|
132
|
-
(
|
137
|
+
# @!method other_length_node(node)
|
138
|
+
def_node_matcher :other_length_node, <<~PATTERN
|
139
|
+
{(call $(call _ _) _ _)
|
140
|
+
(call _ _ $(call _ _))}
|
133
141
|
PATTERN
|
134
142
|
|
135
143
|
# Some collection like objects in the Ruby standard library
|
data/lib/rubocop/cop/team.rb
CHANGED
@@ -9,11 +9,17 @@ module RuboCop
|
|
9
9
|
# For performance reasons, Team will first dispatch cops & forces in two groups,
|
10
10
|
# first the ones needed for autocorrection (if any), then the rest
|
11
11
|
# (unless autocorrections happened).
|
12
|
+
# rubocop:disable Metrics/ClassLength
|
12
13
|
class Team
|
13
14
|
# @return [Team]
|
14
15
|
def self.new(cop_or_classes, config, options = {})
|
15
16
|
# Support v0 api:
|
16
|
-
|
17
|
+
if cop_or_classes.first.is_a?(Class)
|
18
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
19
|
+
`Team.new` with cop classes is deprecated. Use `Team.mobilize` instead.
|
20
|
+
WARNING
|
21
|
+
return mobilize(cop_or_classes, config, options)
|
22
|
+
end
|
17
23
|
|
18
24
|
super
|
19
25
|
end
|
@@ -74,6 +80,10 @@ module RuboCop
|
|
74
80
|
# @deprecated. Use investigate
|
75
81
|
# @return Array<offenses>
|
76
82
|
def inspect_file(processed_source)
|
83
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
84
|
+
`inspect_file` is deprecated. Use `investigate` instead.
|
85
|
+
WARNING
|
86
|
+
|
77
87
|
investigate(processed_source).offenses
|
78
88
|
end
|
79
89
|
|
@@ -108,12 +118,20 @@ module RuboCop
|
|
108
118
|
|
109
119
|
# @deprecated
|
110
120
|
def forces
|
121
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
122
|
+
`forces` is deprecated.
|
123
|
+
WARNING
|
124
|
+
|
111
125
|
@forces ||= self.class.forces_for(cops)
|
112
126
|
end
|
113
127
|
|
114
128
|
def external_dependency_checksum
|
115
|
-
|
116
|
-
|
129
|
+
# The external dependency checksums are cached per RuboCop team so that
|
130
|
+
# the checksums don't need to be recomputed for each file.
|
131
|
+
@external_dependency_checksum ||= begin
|
132
|
+
keys = cops.filter_map(&:external_dependency_checksum)
|
133
|
+
Digest::SHA1.hexdigest(keys.join)
|
134
|
+
end
|
117
135
|
end
|
118
136
|
|
119
137
|
private
|
@@ -174,6 +192,9 @@ module RuboCop
|
|
174
192
|
end
|
175
193
|
|
176
194
|
def support_target_rails_version?(cop)
|
195
|
+
# In this case, the rails version was already checked by `#excluded_file?`
|
196
|
+
return true if defined?(RuboCop::Rails::TargetRailsVersion::USES_REQUIRES_GEM_API)
|
197
|
+
|
177
198
|
return true unless cop.class.respond_to?(:support_target_rails_version?)
|
178
199
|
|
179
200
|
cop.class.support_target_rails_version?(cop.target_rails_version)
|
@@ -237,6 +258,8 @@ module RuboCop
|
|
237
258
|
|
238
259
|
if cause.is_a?(Warning)
|
239
260
|
handle_warning(cause, location)
|
261
|
+
elsif cause.is_a?(Force::HookError)
|
262
|
+
handle_error(cause.cause, location, cause.joining_cop)
|
240
263
|
else
|
241
264
|
handle_error(cause, location, error.cop)
|
242
265
|
end
|
@@ -262,5 +285,6 @@ module RuboCop
|
|
262
285
|
end
|
263
286
|
end
|
264
287
|
end
|
288
|
+
# rubocop:enable Metrics/ClassLength
|
265
289
|
end
|
266
290
|
end
|
data/lib/rubocop/cop/util.rb
CHANGED
@@ -20,6 +20,10 @@ module RuboCop
|
|
20
20
|
|
21
21
|
# @deprecated Use `ProcessedSource#line_with_comment?`, `contains_comment?` or similar
|
22
22
|
def comment_lines?(node)
|
23
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
24
|
+
`comment_lines?` is deprecated. Use `ProcessedSource#line_with_comment?`, `contains_comment?` or similar instead.
|
25
|
+
WARNING
|
26
|
+
|
23
27
|
processed_source[line_range(node)].any? { |line| comment_line?(line) }
|
24
28
|
end
|
25
29
|
|
@@ -28,7 +32,7 @@ module RuboCop
|
|
28
32
|
end
|
29
33
|
|
30
34
|
def parentheses?(node)
|
31
|
-
node.loc.respond_to?(:end) && node.loc.end
|
35
|
+
node.loc.respond_to?(:end) && node.loc.end&.is?(')')
|
32
36
|
end
|
33
37
|
|
34
38
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
@@ -173,7 +177,9 @@ module RuboCop
|
|
173
177
|
def same_line?(node1, node2)
|
174
178
|
line1 = line(node1)
|
175
179
|
line2 = line(node2)
|
176
|
-
|
180
|
+
return false unless line1 && line2
|
181
|
+
|
182
|
+
line1 == line2
|
177
183
|
end
|
178
184
|
|
179
185
|
def indent(node, offset: 0)
|
@@ -9,9 +9,10 @@ module RuboCop
|
|
9
9
|
|
10
10
|
MULTIPLE_LEFT_HAND_SIDE_TYPE = :mlhs
|
11
11
|
|
12
|
-
attr_reader :node, :variable, :referenced, :references
|
12
|
+
attr_reader :node, :variable, :referenced, :references, :reassigned
|
13
13
|
|
14
14
|
alias referenced? referenced
|
15
|
+
alias reassigned? reassigned
|
15
16
|
|
16
17
|
def initialize(node, variable)
|
17
18
|
unless VARIABLE_ASSIGNMENT_TYPES.include?(node.type)
|
@@ -24,6 +25,7 @@ module RuboCop
|
|
24
25
|
@variable = variable
|
25
26
|
@referenced = false
|
26
27
|
@references = []
|
28
|
+
@reassigned = false
|
27
29
|
end
|
28
30
|
|
29
31
|
def name
|
@@ -39,8 +41,14 @@ module RuboCop
|
|
39
41
|
@referenced = true
|
40
42
|
end
|
41
43
|
|
44
|
+
def reassigned!
|
45
|
+
return if referenced?
|
46
|
+
|
47
|
+
@reassigned = true
|
48
|
+
end
|
49
|
+
|
42
50
|
def used?
|
43
|
-
@variable.captured_by_block? || @referenced
|
51
|
+
(!reassigned? && @variable.captured_by_block?) || @referenced
|
44
52
|
end
|
45
53
|
|
46
54
|
def regexp_named_capture?
|
@@ -102,6 +110,7 @@ module RuboCop
|
|
102
110
|
end
|
103
111
|
|
104
112
|
def multiple_assignment_node
|
113
|
+
return nil unless node.parent&.mlhs_type?
|
105
114
|
return nil unless (grandparent_node = node.parent&.parent)
|
106
115
|
if (node = find_multiple_assignment_node(grandparent_node))
|
107
116
|
return node
|
@@ -119,7 +128,13 @@ module RuboCop
|
|
119
128
|
end
|
120
129
|
|
121
130
|
def for_assignment_node
|
122
|
-
node.
|
131
|
+
return unless (parent_node = node.parent)
|
132
|
+
return parent_node if parent_node.for_type?
|
133
|
+
|
134
|
+
grandparent_node = parent_node.parent
|
135
|
+
return grandparent_node if parent_node.mlhs_type? && grandparent_node&.for_type?
|
136
|
+
|
137
|
+
nil
|
123
138
|
end
|
124
139
|
|
125
140
|
def find_multiple_assignment_node(grandparent_node)
|