rubocop 1.69.2 → 1.75.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +4 -4
- data/config/default.yml +183 -41
- data/config/internal_affairs.yml +20 -0
- data/config/obsoletion.yml +3 -1
- data/lib/rubocop/cli/command/execute_runner.rb +3 -3
- data/lib/rubocop/cli/command/show_cops.rb +24 -2
- data/lib/rubocop/cli/command/suggest_extensions.rb +7 -1
- data/lib/rubocop/cli.rb +1 -1
- data/lib/rubocop/comment_config.rb +2 -2
- data/lib/rubocop/config.rb +52 -10
- data/lib/rubocop/config_loader.rb +52 -9
- data/lib/rubocop/config_loader_resolver.rb +36 -10
- data/lib/rubocop/config_obsoletion/extracted_cop.rb +4 -3
- data/lib/rubocop/config_obsoletion/renamed_cop.rb +18 -3
- data/lib/rubocop/config_obsoletion.rb +46 -2
- data/lib/rubocop/config_validator.rb +25 -14
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
- data/lib/rubocop/cop/base.rb +6 -0
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/cop_enabled.rb +85 -0
- data/lib/rubocop/cop/internal_affairs/example_description.rb +8 -4
- data/lib/rubocop/cop/internal_affairs/location_exists.rb +116 -0
- data/lib/rubocop/cop/internal_affairs/location_expression.rb +2 -1
- data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +3 -2
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +63 -0
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +131 -0
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +230 -0
- data/lib/rubocop/cop/internal_affairs/node_type_group.rb +91 -0
- data/lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb +126 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +4 -3
- data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +90 -0
- data/lib/rubocop/cop/internal_affairs/plugin.rb +33 -0
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +6 -5
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +3 -1
- data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +5 -4
- data/lib/rubocop/cop/internal_affairs/undefined_config.rb +13 -2
- data/lib/rubocop/cop/internal_affairs.rb +6 -16
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/argument_alignment.rb +2 -8
- data/lib/rubocop/cop/layout/block_alignment.rb +3 -1
- data/lib/rubocop/cop/layout/block_end_newline.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +9 -9
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +4 -4
- data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +2 -2
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +7 -11
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +28 -1
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +1 -0
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +22 -2
- data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +3 -8
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -7
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +2 -7
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +7 -5
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -0
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +7 -1
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/line_length.rb +9 -4
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +25 -0
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +4 -4
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/redundant_line_break.rb +16 -11
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -5
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_colon.rb +2 -2
- data/lib/rubocop/cop/layout/space_after_comma.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -0
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +7 -4
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -0
- data/lib/rubocop/cop/layout/space_before_comma.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_semicolon.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -0
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +5 -3
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
- data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +119 -0
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -3
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +1 -1
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -5
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +3 -3
- data/lib/rubocop/cop/lint/constant_reassignment.rb +148 -0
- data/lib/rubocop/cop/lint/cop_directive_syntax.rb +84 -0
- data/lib/rubocop/cop/lint/debugger.rb +3 -3
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -17
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_set_element.rb +20 -7
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +14 -64
- data/lib/rubocop/cop/lint/empty_expression.rb +0 -2
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +0 -6
- data/lib/rubocop/cop/lint/float_comparison.rb +6 -8
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +2 -2
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/literal_as_condition.rb +117 -9
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +24 -6
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -1
- data/lib/rubocop/cop/lint/missing_super.rb +2 -2
- data/lib/rubocop/cop/lint/mixed_case_range.rb +3 -3
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +9 -5
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +4 -3
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -3
- data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +18 -31
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +2 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -5
- data/lib/rubocop/cop/lint/raise_exception.rb +29 -10
- data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +0 -21
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_type_conversion.rb +261 -0
- data/lib/rubocop/cop/lint/redundant_with_index.rb +3 -0
- data/lib/rubocop/cop/lint/redundant_with_object.rb +3 -0
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/return_in_void_context.rb +9 -11
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +8 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +8 -1
- data/lib/rubocop/cop/lint/shared_mutable_default.rb +76 -0
- data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/suppressed_exception_in_number_conversion.rb +111 -0
- data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/syntax.rb +4 -1
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
- data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +1 -4
- data/lib/rubocop/cop/lint/unexpected_block_arity.rb +3 -1
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +2 -1
- data/lib/rubocop/cop/lint/unreachable_loop.rb +6 -6
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +5 -4
- data/lib/rubocop/cop/lint/useless_assignment.rb +1 -1
- data/lib/rubocop/cop/lint/useless_constant_scoping.rb +71 -0
- data/lib/rubocop/cop/lint/useless_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/useless_numeric_operation.rb +2 -1
- data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +2 -2
- data/lib/rubocop/cop/lint/void.rb +12 -9
- data/lib/rubocop/cop/message_annotator.rb +7 -3
- data/lib/rubocop/cop/metrics/block_length.rb +1 -0
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
- data/lib/rubocop/cop/metrics/collection_literal_length.rb +7 -0
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/method_length.rb +9 -1
- data/lib/rubocop/cop/metrics/module_length.rb +1 -1
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +7 -7
- data/lib/rubocop/cop/mixin/alignment.rb +2 -2
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +4 -4
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +13 -13
- data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +2 -2
- data/lib/rubocop/cop/mixin/comments_help.rb +4 -2
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/dig_help.rb +1 -1
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
- data/lib/rubocop/cop/mixin/forbidden_identifiers.rb +20 -0
- data/lib/rubocop/cop/mixin/forbidden_pattern.rb +16 -0
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +0 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +22 -22
- data/lib/rubocop/cop/mixin/hash_subset.rb +203 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +74 -74
- data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
- data/lib/rubocop/cop/mixin/percent_literal.rb +1 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +48 -24
- data/lib/rubocop/cop/mixin/range_help.rb +15 -3
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +8 -3
- data/lib/rubocop/cop/mixin/string_help.rb +2 -2
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +1 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +16 -4
- data/lib/rubocop/cop/naming/block_forwarding.rb +19 -15
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +64 -8
- data/lib/rubocop/cop/naming/predicate_name.rb +44 -0
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +3 -3
- data/lib/rubocop/cop/naming/variable_name.rb +51 -6
- data/lib/rubocop/cop/registry.rb +9 -6
- data/lib/rubocop/cop/security/compound_hash.rb +1 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +34 -5
- data/lib/rubocop/cop/style/accessor_grouping.rb +19 -5
- data/lib/rubocop/cop/style/and_or.rb +1 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +44 -28
- data/lib/rubocop/cop/style/array_first_last.rb +18 -2
- data/lib/rubocop/cop/style/array_intersect.rb +39 -28
- data/lib/rubocop/cop/style/block_delimiters.rb +9 -21
- data/lib/rubocop/cop/style/class_and_module_children.rb +52 -11
- data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -1
- data/lib/rubocop/cop/style/collection_methods.rb +2 -1
- data/lib/rubocop/cop/style/combinable_defined.rb +1 -1
- data/lib/rubocop/cop/style/combinable_loops.rb +3 -2
- data/lib/rubocop/cop/style/commented_keyword.rb +12 -5
- data/lib/rubocop/cop/style/comparable_between.rb +75 -0
- data/lib/rubocop/cop/style/concat_array_literals.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +20 -6
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +4 -4
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +4 -7
- data/lib/rubocop/cop/style/each_with_object.rb +2 -3
- data/lib/rubocop/cop/style/empty_else.rb +4 -2
- data/lib/rubocop/cop/style/empty_literal.rb +5 -1
- data/lib/rubocop/cop/style/empty_method.rb +1 -1
- data/lib/rubocop/cop/style/endless_method.rb +163 -18
- data/lib/rubocop/cop/style/eval_with_location.rb +4 -4
- data/lib/rubocop/cop/style/exact_regexp_match.rb +3 -10
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -7
- data/lib/rubocop/cop/style/explicit_block_argument.rb +16 -3
- data/lib/rubocop/cop/style/exponential_notation.rb +3 -3
- data/lib/rubocop/cop/style/fetch_env_var.rb +1 -1
- data/lib/rubocop/cop/style/float_division.rb +8 -4
- data/lib/rubocop/cop/style/for.rb +1 -0
- data/lib/rubocop/cop/style/format_string_token.rb +38 -11
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -2
- data/lib/rubocop/cop/style/global_std_stream.rb +3 -0
- data/lib/rubocop/cop/style/guard_clause.rb +2 -1
- data/lib/rubocop/cop/style/hash_each_methods.rb +6 -8
- data/lib/rubocop/cop/style/hash_except.rb +24 -148
- data/lib/rubocop/cop/style/hash_fetch_chain.rb +104 -0
- data/lib/rubocop/cop/style/hash_slice.rb +80 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +9 -3
- data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +22 -3
- data/lib/rubocop/cop/style/if_inside_else.rb +10 -13
- data/lib/rubocop/cop/style/if_unless_modifier.rb +5 -5
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -2
- data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -2
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +15 -11
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +2 -2
- data/lib/rubocop/cop/style/ip_addresses.rb +2 -2
- data/lib/rubocop/cop/style/it_assignment.rb +36 -0
- data/lib/rubocop/cop/style/it_block_parameter.rb +100 -0
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +14 -8
- data/lib/rubocop/cop/style/lambda.rb +1 -0
- data/lib/rubocop/cop/style/lambda_call.rb +7 -2
- data/lib/rubocop/cop/style/line_end_concatenation.rb +10 -4
- data/lib/rubocop/cop/style/map_into_array.rb +5 -2
- data/lib/rubocop/cop/style/map_to_hash.rb +1 -1
- data/lib/rubocop/cop/style/map_to_set.rb +3 -2
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +23 -16
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -0
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -1
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +3 -4
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/missing_else.rb +2 -0
- data/lib/rubocop/cop/style/multiline_block_chain.rb +3 -2
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -9
- data/lib/rubocop/cop/style/multiple_comparison.rb +26 -20
- data/lib/rubocop/cop/style/mutable_constant.rb +3 -3
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -1
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
- data/lib/rubocop/cop/style/next.rb +44 -0
- data/lib/rubocop/cop/style/object_then.rb +14 -15
- data/lib/rubocop/cop/style/open_struct_use.rb +5 -5
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -5
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -2
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +2 -2
- data/lib/rubocop/cop/style/quoted_symbols.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +14 -12
- data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
- data/lib/rubocop/cop/style/redundant_begin.rb +2 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +59 -2
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +16 -5
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +6 -10
- data/lib/rubocop/cop/style/redundant_each.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +2 -2
- data/lib/rubocop/cop/style/redundant_format.rb +257 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +3 -3
- data/lib/rubocop/cop/style/redundant_initialize.rb +12 -3
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +34 -16
- data/lib/rubocop/cop/style/redundant_parentheses.rb +48 -16
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +3 -0
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self.rb +1 -0
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +14 -28
- data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
- data/lib/rubocop/cop/style/redundant_sort_by.rb +17 -1
- data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +3 -0
- data/lib/rubocop/cop/style/return_nil.rb +2 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +20 -5
- data/lib/rubocop/cop/style/select_by_regexp.rb +4 -1
- data/lib/rubocop/cop/style/semicolon.rb +1 -1
- data/lib/rubocop/cop/style/send_with_literal_method_name.rb +2 -1
- data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +4 -3
- data/lib/rubocop/cop/style/single_line_methods.rb +6 -7
- data/lib/rubocop/cop/style/slicing_with_range.rb +40 -11
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +41 -106
- data/lib/rubocop/cop/style/string_concatenation.rb +2 -2
- data/lib/rubocop/cop/style/string_literals.rb +1 -1
- data/lib/rubocop/cop/style/string_methods.rb +1 -1
- data/lib/rubocop/cop/style/super_arguments.rb +66 -19
- data/lib/rubocop/cop/style/symbol_proc.rb +2 -0
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/top_level_method_definition.rb +2 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +11 -2
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +47 -6
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +48 -6
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +8 -4
- data/lib/rubocop/cop/style/yoda_expression.rb +2 -1
- data/lib/rubocop/cop/util.rb +12 -5
- data/lib/rubocop/cop/utils/format_string.rb +10 -5
- data/lib/rubocop/cop/variable_force/scope.rb +1 -1
- data/lib/rubocop/cop/variable_force/variable.rb +10 -3
- data/lib/rubocop/cop/variable_force/variable_table.rb +3 -3
- data/lib/rubocop/cop/variable_force.rb +1 -1
- data/lib/rubocop/cops_documentation_generator.rb +31 -16
- data/lib/rubocop/directive_comment.rb +45 -11
- data/lib/rubocop/ext/regexp_node.rb +0 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +1 -1
- data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
- data/lib/rubocop/lsp/diagnostic.rb +189 -0
- data/lib/rubocop/lsp/logger.rb +2 -2
- data/lib/rubocop/lsp/routes.rb +7 -23
- data/lib/rubocop/lsp/runtime.rb +18 -50
- data/lib/rubocop/lsp/server.rb +0 -2
- data/lib/rubocop/lsp/stdin_runner.rb +85 -0
- data/lib/rubocop/magic_comment.rb +8 -0
- data/lib/rubocop/options.rb +28 -12
- data/lib/rubocop/path_util.rb +15 -8
- data/lib/rubocop/plugin/configuration_integrator.rb +143 -0
- data/lib/rubocop/plugin/load_error.rb +26 -0
- data/lib/rubocop/plugin/loader.rb +100 -0
- data/lib/rubocop/plugin/not_supported_error.rb +29 -0
- data/lib/rubocop/plugin.rb +46 -0
- data/lib/rubocop/rake_task.rb +4 -1
- data/lib/rubocop/result_cache.rb +13 -13
- data/lib/rubocop/rspec/cop_helper.rb +13 -1
- data/lib/rubocop/rspec/expect_offense.rb +6 -2
- data/lib/rubocop/rspec/shared_contexts.rb +38 -1
- data/lib/rubocop/rspec/support.rb +4 -2
- data/lib/rubocop/runner.rb +10 -7
- data/lib/rubocop/server/cache.rb +47 -11
- data/lib/rubocop/server/cli.rb +2 -2
- data/lib/rubocop/target_finder.rb +7 -2
- data/lib/rubocop/target_ruby.rb +16 -1
- data/lib/rubocop/version.rb +30 -8
- data/lib/rubocop.rb +16 -1
- data/lib/ruby_lsp/rubocop/addon.rb +75 -0
- data/lib/ruby_lsp/rubocop/runtime_adapter.rb +65 -0
- metadata +59 -16
- data/lib/rubocop/cop/utils/regexp_ranges.rb +0 -113
- data/lib/rubocop/rspec/host_environment_simulation_helper.rb +0 -28
data/config/obsoletion.yml
CHANGED
@@ -43,7 +43,9 @@ renamed:
|
|
43
43
|
Style/MethodCallParentheses: Style/MethodCallWithoutArgsParentheses
|
44
44
|
Style/MethodName: Naming/MethodName
|
45
45
|
Style/OpMethod: Naming/BinaryOperatorParameterName
|
46
|
-
Style/PredicateName:
|
46
|
+
Style/PredicateName:
|
47
|
+
new_name: Naming/PredicateName
|
48
|
+
severity: warning
|
47
49
|
Style/SingleSpaceBeforeFirstArg: Layout/SpaceBeforeFirstArg
|
48
50
|
Style/UnneededCapitalW: Style/RedundantCapitalW
|
49
51
|
Style/UnneededCondition: Style/RedundantCondition
|
@@ -71,11 +71,11 @@ module RuboCop
|
|
71
71
|
|
72
72
|
warn Rainbow("\n#{pluralize(errors.size, 'error')} occurred:").red
|
73
73
|
|
74
|
-
errors.each { |error| warn error }
|
74
|
+
errors.each { |error| warn Rainbow(error).red }
|
75
75
|
|
76
|
-
warn <<~WARNING
|
76
|
+
warn Rainbow(<<~WARNING.strip).yellow
|
77
77
|
Errors are usually caused by RuboCop bugs.
|
78
|
-
Please,
|
78
|
+
Please, update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version.
|
79
79
|
#{bug_tracker_uri}
|
80
80
|
Mention the following information in the issue report:
|
81
81
|
#{RuboCop::Version.verbose}
|
@@ -9,11 +9,31 @@ module RuboCop
|
|
9
9
|
class ShowCops < Base
|
10
10
|
self.command_name = :show_cops
|
11
11
|
|
12
|
+
ExactMatcher = Struct.new(:pattern) do
|
13
|
+
def match?(name)
|
14
|
+
name == pattern
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
WildcardMatcher = Struct.new(:pattern) do
|
19
|
+
def match?(name)
|
20
|
+
File.fnmatch(pattern, name, File::FNM_PATHNAME)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
12
24
|
def initialize(env)
|
13
25
|
super
|
14
26
|
|
15
27
|
# Load the configs so the require()s are done for custom cops
|
16
28
|
@config = @config_store.for(Dir.pwd)
|
29
|
+
|
30
|
+
@cop_matchers = @options[:show_cops].map do |pattern|
|
31
|
+
if pattern.include?('*')
|
32
|
+
WildcardMatcher.new(pattern)
|
33
|
+
else
|
34
|
+
ExactMatcher.new(pattern)
|
35
|
+
end
|
36
|
+
end
|
17
37
|
end
|
18
38
|
|
19
39
|
def run
|
@@ -24,7 +44,7 @@ module RuboCop
|
|
24
44
|
|
25
45
|
def print_available_cops
|
26
46
|
registry = Cop::Registry.global
|
27
|
-
show_all = @
|
47
|
+
show_all = @cop_matchers.empty?
|
28
48
|
|
29
49
|
puts "# Available cops (#{registry.length}) + config for #{Dir.pwd}: " if show_all
|
30
50
|
|
@@ -56,7 +76,9 @@ module RuboCop
|
|
56
76
|
|
57
77
|
def selected_cops_of_department(cops, department)
|
58
78
|
cops_of_department(cops, department).select do |cop|
|
59
|
-
@
|
79
|
+
@cop_matchers.any? do |matcher|
|
80
|
+
matcher.match?(cop.cop_name)
|
81
|
+
end
|
60
82
|
end
|
61
83
|
end
|
62
84
|
|
@@ -97,7 +97,13 @@ module RuboCop
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def loaded_extensions
|
100
|
-
@config_store.for_pwd
|
100
|
+
rubocop_config = @config_store.for_pwd
|
101
|
+
|
102
|
+
plugin_names = rubocop_config.loaded_plugins.map do |plugin|
|
103
|
+
plugin.about.name
|
104
|
+
end
|
105
|
+
|
106
|
+
plugin_names + rubocop_config.loaded_features.to_a
|
101
107
|
end
|
102
108
|
|
103
109
|
def installed_and_not_loaded_extensions
|
data/lib/rubocop/cli.rb
CHANGED
@@ -87,7 +87,7 @@ module RuboCop
|
|
87
87
|
next unless directive.enabled?
|
88
88
|
next if directive.all_cops?
|
89
89
|
|
90
|
-
cops.merge(directive.
|
90
|
+
cops.merge(directive.raw_cop_names)
|
91
91
|
end
|
92
92
|
cops
|
93
93
|
end
|
@@ -205,7 +205,7 @@ module RuboCop
|
|
205
205
|
directive.cop_names.each do |name|
|
206
206
|
if directive.disabled?
|
207
207
|
names[name] += 1
|
208
|
-
elsif
|
208
|
+
elsif names[name].positive?
|
209
209
|
names[name] -= 1
|
210
210
|
else
|
211
211
|
extras[directive.comment] << name
|
data/lib/rubocop/config.rb
CHANGED
@@ -16,6 +16,7 @@ module RuboCop
|
|
16
16
|
|
17
17
|
CopConfig = Struct.new(:name, :metadata)
|
18
18
|
|
19
|
+
EMPTY_CONFIG = {}.freeze
|
19
20
|
DEFAULT_RAILS_VERSION = 5.0
|
20
21
|
attr_reader :loaded_path
|
21
22
|
|
@@ -26,14 +27,43 @@ module RuboCop
|
|
26
27
|
config
|
27
28
|
end
|
28
29
|
|
29
|
-
# rubocop:disable Metrics/AbcSize
|
30
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
30
31
|
def initialize(hash = RuboCop::ConfigLoader.default_configuration, loaded_path = nil)
|
31
32
|
@loaded_path = loaded_path
|
32
33
|
@for_cop = Hash.new do |h, cop|
|
33
34
|
cop_name = cop.respond_to?(:cop_name) ? cop.cop_name : cop
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
|
36
|
+
if ConfigObsoletion.deprecated_cop_name?(cop)
|
37
|
+
# Since a deprecated cop will no longer have a qualified name (as the badge is no
|
38
|
+
# longer valid), and since we do not want to automatically enable the cop, we just
|
39
|
+
# set the configuration to an empty hash if it is unset.
|
40
|
+
# This is necessary to allow a renamed cop have its old configuration merged in
|
41
|
+
# before being used (which is necessary to allow it to be disabled via config).
|
42
|
+
cop_options = self[cop_name].dup || {}
|
43
|
+
else
|
44
|
+
qualified_cop_name = Cop::Registry.qualified_cop_name(cop_name, loaded_path, warn: false)
|
45
|
+
cop_options = self[qualified_cop_name].dup || {}
|
46
|
+
cop_options['Enabled'] = enable_cop?(qualified_cop_name, cop_options)
|
47
|
+
|
48
|
+
# If the cop has deprecated names (ie. it has been renamed), it is possible that
|
49
|
+
# users will still have old configuration for the cop's old name. In this case,
|
50
|
+
# if `ConfigObsoletion` is configured to warn rather than error (and therefore
|
51
|
+
# RuboCop runs), we want to respect the old configuration, so merge it in.
|
52
|
+
#
|
53
|
+
# NOTE: If there is configuration for both the cop and a deprecated names, the old
|
54
|
+
# configuration will be merged on top of the new configuration!
|
55
|
+
ConfigObsoletion.deprecated_names_for(cop).each do |deprecated_cop_name|
|
56
|
+
deprecated_config = @for_cop[deprecated_cop_name]
|
57
|
+
next if deprecated_config.empty?
|
58
|
+
|
59
|
+
warn Rainbow(<<~WARNING).yellow
|
60
|
+
Warning: Using `#{deprecated_cop_name}` configuration in #{loaded_path} for `#{cop}`.
|
61
|
+
WARNING
|
62
|
+
|
63
|
+
cop_options.merge!(@for_cop[deprecated_cop_name])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
37
67
|
h[cop] = h[cop_name] = cop_options
|
38
68
|
end
|
39
69
|
@hash = hash
|
@@ -42,7 +72,11 @@ module RuboCop
|
|
42
72
|
@badge_config_cache = {}.compare_by_identity
|
43
73
|
@clusivity_config_exists_cache = {}
|
44
74
|
end
|
45
|
-
# rubocop:enable Metrics/AbcSize
|
75
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
76
|
+
|
77
|
+
def loaded_plugins
|
78
|
+
@loaded_plugins ||= ConfigLoader.loaded_plugins
|
79
|
+
end
|
46
80
|
|
47
81
|
def loaded_features
|
48
82
|
@loaded_features ||= ConfigLoader.loaded_features
|
@@ -80,10 +114,7 @@ module RuboCop
|
|
80
114
|
|
81
115
|
def make_excludes_absolute
|
82
116
|
each_key do |key|
|
83
|
-
|
84
|
-
next unless self[key]['Exclude']
|
85
|
-
|
86
|
-
self[key]['Exclude'].map! do |exclude_elem|
|
117
|
+
dig(key, 'Exclude')&.map! do |exclude_elem|
|
87
118
|
if exclude_elem.is_a?(String) && !absolute?(exclude_elem)
|
88
119
|
File.expand_path(File.join(base_dir_for_path_parameters, exclude_elem))
|
89
120
|
else
|
@@ -123,6 +154,13 @@ module RuboCop
|
|
123
154
|
@for_cop[cop]
|
124
155
|
end
|
125
156
|
|
157
|
+
# @return [Config, Hash] for the given cop / cop name.
|
158
|
+
# If the given cop is enabled, returns its configuration hash.
|
159
|
+
# Otherwise, returns an empty hash.
|
160
|
+
def for_enabled_cop(cop)
|
161
|
+
cop_enabled?(cop) ? for_cop(cop) : EMPTY_CONFIG
|
162
|
+
end
|
163
|
+
|
126
164
|
# @return [Config] for the given cop merged with that of its department (if any)
|
127
165
|
# Note: the 'Enabled' attribute is same as that returned by `for_cop`
|
128
166
|
def for_badge(badge)
|
@@ -159,6 +197,10 @@ module RuboCop
|
|
159
197
|
@for_all_cops ||= self['AllCops'] || {}
|
160
198
|
end
|
161
199
|
|
200
|
+
def cop_enabled?(name)
|
201
|
+
!!for_cop(name)['Enabled']
|
202
|
+
end
|
203
|
+
|
162
204
|
def disabled_new_cops?
|
163
205
|
for_all_cops['NewCops'] == 'disable'
|
164
206
|
end
|
@@ -249,7 +291,7 @@ module RuboCop
|
|
249
291
|
end
|
250
292
|
|
251
293
|
def parser_engine
|
252
|
-
@parser_engine ||= for_all_cops.fetch('ParserEngine', :
|
294
|
+
@parser_engine ||= for_all_cops.fetch('ParserEngine', :default).to_sym
|
253
295
|
end
|
254
296
|
|
255
297
|
def target_rails_version
|
@@ -33,26 +33,36 @@ module RuboCop
|
|
33
33
|
attr_accessor :debug, :ignore_parent_exclusion, :disable_pending_cops, :enable_pending_cops,
|
34
34
|
:ignore_unrecognized_cops
|
35
35
|
attr_writer :default_configuration
|
36
|
-
attr_reader :loaded_features
|
36
|
+
attr_reader :loaded_plugins, :loaded_features
|
37
37
|
|
38
38
|
alias debug? debug
|
39
39
|
alias ignore_parent_exclusion? ignore_parent_exclusion
|
40
40
|
|
41
41
|
def clear_options
|
42
42
|
@debug = nil
|
43
|
+
@loaded_plugins = Set.new
|
43
44
|
@loaded_features = Set.new
|
45
|
+
@disable_pending_cops = nil
|
46
|
+
@enable_pending_cops = nil
|
47
|
+
@ignore_parent_exclusion = nil
|
48
|
+
@ignore_unrecognized_cops = nil
|
44
49
|
FileFinder.root_level = nil
|
45
50
|
end
|
46
51
|
|
52
|
+
# rubocop:disable Metrics/AbcSize
|
47
53
|
def load_file(file, check: true)
|
48
54
|
path = file_path(file)
|
49
55
|
|
50
56
|
hash = load_yaml_configuration(path)
|
51
57
|
|
58
|
+
rubocop_config = Config.create(hash, path, check: false)
|
59
|
+
plugins = hash.delete('plugins')
|
60
|
+
loaded_plugins = resolver.resolve_plugins(rubocop_config, plugins)
|
61
|
+
add_loaded_plugins(loaded_plugins)
|
62
|
+
|
52
63
|
loaded_features = resolver.resolve_requires(path, hash)
|
53
64
|
add_loaded_features(loaded_features)
|
54
65
|
|
55
|
-
resolver.override_department_setting_for_cops({}, hash)
|
56
66
|
resolver.resolve_inheritance_from_gems(hash)
|
57
67
|
resolver.resolve_inheritance(path, hash, file, debug?)
|
58
68
|
hash.delete('inherit_from')
|
@@ -63,6 +73,7 @@ module RuboCop
|
|
63
73
|
|
64
74
|
Config.create(hash, path, check: check)
|
65
75
|
end
|
76
|
+
# rubocop:enable Metrics/AbcSize
|
66
77
|
|
67
78
|
def load_yaml_configuration(absolute_path)
|
68
79
|
file_contents = read_file(absolute_path)
|
@@ -80,8 +91,12 @@ module RuboCop
|
|
80
91
|
def add_missing_namespaces(path, hash)
|
81
92
|
# Using `hash.each_key` will cause the
|
82
93
|
# `can't add a new key into hash during iteration` error
|
94
|
+
obsoletion = ConfigObsoletion.new(hash)
|
95
|
+
|
83
96
|
hash_keys = hash.keys
|
84
97
|
hash_keys.each do |key|
|
98
|
+
next if obsoletion.deprecated_cop_name?(key)
|
99
|
+
|
85
100
|
q = Cop::Registry.qualified_cop_name(key, path)
|
86
101
|
next if q == key
|
87
102
|
|
@@ -151,14 +166,35 @@ module RuboCop
|
|
151
166
|
end
|
152
167
|
end
|
153
168
|
|
154
|
-
#
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
169
|
+
# This API is primarily intended for testing and documenting plugins.
|
170
|
+
# When testing a plugin using `rubocop/rspec/support`, the plugin is loaded automatically,
|
171
|
+
# so this API is usually not needed. It is intended to be used only when implementing tests
|
172
|
+
# that do not use `rubocop/rspec/support`.
|
173
|
+
# rubocop:disable Metrics/MethodLength
|
174
|
+
def inject_defaults!(config_yml_path)
|
175
|
+
if Pathname(config_yml_path).directory?
|
176
|
+
# TODO: Since the warning noise is expected to be high until some time after the release,
|
177
|
+
# warnings will only be issued when `RUBYOPT=-w` is specified.
|
178
|
+
# To proceed step by step, the next step is to remove `$VERBOSE` and always issue warning.
|
179
|
+
# Eventually, `project_root` will no longer be accepted.
|
180
|
+
if $VERBOSE
|
181
|
+
warn Rainbow(<<~MESSAGE).yellow, uplevel: 1
|
182
|
+
Use config YAML file path instead of project root directory.
|
183
|
+
e.g., `path/to/config/default.yml`
|
184
|
+
MESSAGE
|
185
|
+
end
|
186
|
+
# NOTE: For compatibility.
|
187
|
+
project_root = config_yml_path
|
188
|
+
path = File.join(project_root, 'config', 'default.yml')
|
189
|
+
config = load_file(path)
|
190
|
+
else
|
191
|
+
hash = ConfigLoader.load_yaml_configuration(config_yml_path.to_s)
|
192
|
+
config = Config.new(hash, config_yml_path).tap(&:make_excludes_absolute)
|
193
|
+
end
|
194
|
+
|
195
|
+
@default_configuration = ConfigLoader.merge_with_default(config, path)
|
161
196
|
end
|
197
|
+
# rubocop:enable Metrics/MethodLength
|
162
198
|
|
163
199
|
# Returns the path RuboCop inferred as the root of the project. No file
|
164
200
|
# searches will go past this directory.
|
@@ -192,6 +228,13 @@ module RuboCop
|
|
192
228
|
resolver.merge_with_default(config, config_file, unset_nil: unset_nil)
|
193
229
|
end
|
194
230
|
|
231
|
+
# @api private
|
232
|
+
# Used to add plugins that were required inside a config or from
|
233
|
+
# the CLI using `--plugin`.
|
234
|
+
def add_loaded_plugins(loaded_plugins)
|
235
|
+
@loaded_plugins.merge(Array(loaded_plugins))
|
236
|
+
end
|
237
|
+
|
195
238
|
# @api private
|
196
239
|
# Used to add features that were required inside a config or from
|
197
240
|
# the CLI using `--require`.
|
@@ -2,16 +2,35 @@
|
|
2
2
|
|
3
3
|
require 'pathname'
|
4
4
|
require 'yaml'
|
5
|
+
require_relative 'plugin'
|
5
6
|
|
6
7
|
module RuboCop
|
7
8
|
# A help class for ConfigLoader that handles configuration resolution.
|
8
9
|
# @api private
|
9
10
|
class ConfigLoaderResolver # rubocop:disable Metrics/ClassLength
|
11
|
+
def resolve_plugins(rubocop_config, plugins)
|
12
|
+
plugins = Array(plugins) - ConfigLoader.loaded_plugins.map { |plugin| plugin.about.name }
|
13
|
+
return if plugins.empty?
|
14
|
+
|
15
|
+
Plugin.integrate_plugins(rubocop_config, plugins)
|
16
|
+
end
|
17
|
+
|
10
18
|
def resolve_requires(path, hash)
|
11
19
|
config_dir = File.dirname(path)
|
12
20
|
hash.delete('require').tap do |loaded_features|
|
13
21
|
Array(loaded_features).each do |feature|
|
14
|
-
|
22
|
+
if Plugin.plugin_capable?(feature)
|
23
|
+
# NOTE: Compatibility for before plugins style.
|
24
|
+
warn Rainbow(<<~MESSAGE).yellow
|
25
|
+
#{feature} extension supports plugin, specify `plugins: #{feature}` instead of `require: #{feature}` in #{path}.
|
26
|
+
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
|
27
|
+
MESSAGE
|
28
|
+
rubocop_config = Config.create(hash, path, check: false)
|
29
|
+
|
30
|
+
resolve_plugins(rubocop_config, feature)
|
31
|
+
else
|
32
|
+
FeatureLoader.load(config_directory_path: config_dir, feature: feature)
|
33
|
+
end
|
15
34
|
end
|
16
35
|
end
|
17
36
|
end
|
@@ -105,7 +124,7 @@ module RuboCop
|
|
105
124
|
elsif merge_hashes?(base_hash, derived_hash, key)
|
106
125
|
result[key] = merge(base_hash[key], derived_hash[key], **opts)
|
107
126
|
elsif should_union?(derived_hash, base_hash, opts[:inherit_mode], key)
|
108
|
-
result[key] = base_hash[key] | derived_hash[key]
|
127
|
+
result[key] = Array(base_hash[key]) | Array(derived_hash[key])
|
109
128
|
elsif opts[:debug]
|
110
129
|
warn_on_duplicate_setting(base_hash, derived_hash, key, **opts)
|
111
130
|
end
|
@@ -157,20 +176,27 @@ module RuboCop
|
|
157
176
|
return false if inherited_file.nil? # Not inheritance resolving merge
|
158
177
|
return false if inherited_file.start_with?('..') # Legitimate override
|
159
178
|
return false if base_hash[key] == derived_hash[key] # Same value
|
160
|
-
return false if remote_file?(inherited_file) # Can't change
|
179
|
+
return false if PathUtil.remote_file?(inherited_file) # Can't change
|
161
180
|
|
162
181
|
Gem.path.none? { |dir| inherited_file.start_with?(dir) } # Can change?
|
163
182
|
end
|
164
183
|
|
165
184
|
def warn_on_duplicate_setting(base_hash, derived_hash, key, **opts)
|
185
|
+
# If the file being considered is remote, don't bother checking for duplicates
|
186
|
+
return if remote_config?(opts[:file])
|
187
|
+
|
166
188
|
return unless duplicate_setting?(base_hash, derived_hash, key, opts[:inherited_file])
|
167
189
|
|
168
190
|
inherit_mode = opts[:inherit_mode]['merge'] || opts[:inherit_mode]['override']
|
169
191
|
return if base_hash[key].is_a?(Array) && inherit_mode&.include?(key)
|
170
192
|
|
171
|
-
puts
|
172
|
-
|
173
|
-
|
193
|
+
puts duplicate_setting_warning(opts, key)
|
194
|
+
end
|
195
|
+
|
196
|
+
def duplicate_setting_warning(opts, key)
|
197
|
+
"#{PathUtil.smart_path(opts[:file])}: " \
|
198
|
+
"#{opts[:cop_name]}:#{key} overrides " \
|
199
|
+
"the same parameter in #{opts[:inherited_file]}"
|
174
200
|
end
|
175
201
|
|
176
202
|
def determine_inherit_mode(hash, key)
|
@@ -180,7 +206,7 @@ module RuboCop
|
|
180
206
|
end
|
181
207
|
|
182
208
|
def should_union?(derived_hash, base_hash, root_mode, key)
|
183
|
-
return false unless base_hash[key].is_a?(Array)
|
209
|
+
return false unless base_hash[key].is_a?(Array) || derived_hash[key].is_a?(Array)
|
184
210
|
|
185
211
|
derived_mode = derived_hash['inherit_mode']
|
186
212
|
return false if should_override?(derived_mode, key)
|
@@ -218,7 +244,7 @@ module RuboCop
|
|
218
244
|
end
|
219
245
|
|
220
246
|
def inherited_file(path, inherit_from, file)
|
221
|
-
if remote_file?(inherit_from)
|
247
|
+
if PathUtil.remote_file?(inherit_from)
|
222
248
|
# A remote configuration, e.g. `inherit_from: http://example.com/rubocop.yml`.
|
223
249
|
RemoteConfig.new(inherit_from, File.dirname(path))
|
224
250
|
elsif Pathname.new(inherit_from).absolute?
|
@@ -238,8 +264,8 @@ module RuboCop
|
|
238
264
|
end
|
239
265
|
end
|
240
266
|
|
241
|
-
def
|
242
|
-
|
267
|
+
def remote_config?(file)
|
268
|
+
file.is_a?(RemoteConfig)
|
243
269
|
end
|
244
270
|
|
245
271
|
def handle_disabled_by_default(config, new_default_configuration)
|
@@ -15,7 +15,7 @@ module RuboCop
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def violated?
|
18
|
-
return false if
|
18
|
+
return false if plugin_loaded?
|
19
19
|
|
20
20
|
affected_cops.any?
|
21
21
|
end
|
@@ -38,8 +38,9 @@ module RuboCop
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
42
|
-
|
41
|
+
def plugin_loaded?
|
42
|
+
# Plugins loaded via `require` are included in `loaded_features`.
|
43
|
+
config.loaded_plugins.include?(gem) || config.loaded_features.include?(gem)
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
@@ -6,17 +6,28 @@ module RuboCop
|
|
6
6
|
# a cop or moving it to a new department.
|
7
7
|
# @api private
|
8
8
|
class RenamedCop < CopRule
|
9
|
-
attr_reader :new_name
|
9
|
+
attr_reader :new_name, :metadata
|
10
10
|
|
11
|
-
def initialize(config, old_name,
|
11
|
+
def initialize(config, old_name, name_or_hash)
|
12
12
|
super(config, old_name)
|
13
|
-
|
13
|
+
|
14
|
+
if name_or_hash.is_a?(Hash)
|
15
|
+
@metadata = name_or_hash
|
16
|
+
@new_name = name_or_hash['new_name']
|
17
|
+
else
|
18
|
+
@metadata = {}
|
19
|
+
@new_name = name_or_hash
|
20
|
+
end
|
14
21
|
end
|
15
22
|
|
16
23
|
def rule_message
|
17
24
|
"The `#{old_name}` cop has been #{verb} to `#{new_name}`."
|
18
25
|
end
|
19
26
|
|
27
|
+
def warning?
|
28
|
+
severity == 'warning'
|
29
|
+
end
|
30
|
+
|
20
31
|
private
|
21
32
|
|
22
33
|
def moved?
|
@@ -29,6 +40,10 @@ module RuboCop
|
|
29
40
|
def verb
|
30
41
|
moved? ? 'moved' : 'renamed'
|
31
42
|
end
|
43
|
+
|
44
|
+
def severity
|
45
|
+
metadata['severity']
|
46
|
+
end
|
32
47
|
end
|
33
48
|
end
|
34
49
|
end
|
@@ -23,9 +23,40 @@ module RuboCop
|
|
23
23
|
class << self
|
24
24
|
attr_accessor :files
|
25
25
|
|
26
|
+
def global
|
27
|
+
@global ||= new(Config.new)
|
28
|
+
end
|
29
|
+
|
30
|
+
def reset!
|
31
|
+
@global = nil
|
32
|
+
@deprecated_names = {}
|
33
|
+
LOAD_RULES_CACHE[rules_cache_key] = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def rules_cache_key
|
37
|
+
files.hash
|
38
|
+
end
|
39
|
+
|
26
40
|
def legacy_cop_names
|
27
41
|
# Used by DepartmentName#qualified_legacy_cop_name
|
28
|
-
|
42
|
+
global.legacy_cop_names
|
43
|
+
end
|
44
|
+
|
45
|
+
def deprecated_cop_name?(name)
|
46
|
+
global.deprecated_cop_name?(name)
|
47
|
+
end
|
48
|
+
|
49
|
+
def deprecated_names_for(cop)
|
50
|
+
@deprecated_names ||= {}
|
51
|
+
return @deprecated_names[cop] if @deprecated_names.key?(cop)
|
52
|
+
|
53
|
+
@deprecated_names[cop] = global.rules.filter_map do |rule|
|
54
|
+
next unless rule.cop_rule?
|
55
|
+
next unless rule.respond_to?(:new_name)
|
56
|
+
next unless rule.new_name == cop
|
57
|
+
|
58
|
+
rule.old_name
|
59
|
+
end
|
29
60
|
end
|
30
61
|
end
|
31
62
|
|
@@ -45,12 +76,21 @@ module RuboCop
|
|
45
76
|
raise ValidationError, messages.join("\n")
|
46
77
|
end
|
47
78
|
|
79
|
+
def legacy_cop_names
|
80
|
+
# Used by DepartmentName#qualified_legacy_cop_name
|
81
|
+
cop_rules.map(&:old_name)
|
82
|
+
end
|
83
|
+
|
84
|
+
def deprecated_cop_name?(name)
|
85
|
+
legacy_cop_names.include?(name)
|
86
|
+
end
|
87
|
+
|
48
88
|
private
|
49
89
|
|
50
90
|
# Default rules for obsoletions are in config/obsoletion.yml
|
51
91
|
# Additional rules files can be added with `RuboCop::ConfigObsoletion.files << filename`
|
52
92
|
def load_rules # rubocop:disable Metrics/AbcSize
|
53
|
-
rules = LOAD_RULES_CACHE[self.class.
|
93
|
+
rules = LOAD_RULES_CACHE[self.class.rules_cache_key] ||=
|
54
94
|
self.class.files.each_with_object({}) do |filename, hash|
|
55
95
|
hash.merge!(YAML.safe_load(File.read(filename)) || {}) do |_key, first, second|
|
56
96
|
case first
|
@@ -107,5 +147,9 @@ module RuboCop
|
|
107
147
|
rule.message
|
108
148
|
end
|
109
149
|
end
|
150
|
+
|
151
|
+
def cop_rules
|
152
|
+
rules.select(&:cop_rule?)
|
153
|
+
end
|
110
154
|
end
|
111
155
|
end
|