rubocop 1.72.1 → 1.81.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +22 -18
- data/config/default.yml +240 -65
- data/config/internal_affairs.yml +20 -0
- data/config/obsoletion.yml +8 -3
- data/exe/rubocop +1 -8
- data/lib/rubocop/cli/command/auto_generate_config.rb +2 -2
- data/lib/rubocop/cli.rb +19 -4
- data/lib/rubocop/config.rb +35 -6
- data/lib/rubocop/config_loader.rb +8 -40
- data/lib/rubocop/config_loader_resolver.rb +9 -7
- data/lib/rubocop/config_obsoletion/extracted_cop.rb +4 -3
- data/lib/rubocop/config_obsoletion/renamed_cop.rb +18 -3
- data/lib/rubocop/config_obsoletion.rb +46 -2
- data/lib/rubocop/config_store.rb +5 -0
- data/lib/rubocop/config_validator.rb +7 -6
- data/lib/rubocop/cop/autocorrect_logic.rb +22 -14
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +7 -4
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -2
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +5 -2
- data/lib/rubocop/cop/gemspec/attribute_assignment.rb +91 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +37 -15
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/gemspec/require_mfa.rb +15 -1
- data/lib/rubocop/cop/internal_affairs/example_description.rb +9 -5
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +4 -4
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +6 -2
- data/lib/rubocop/cop/internal_affairs/node_type_group.rb +92 -0
- data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +6 -5
- data/lib/rubocop/cop/internal_affairs/undefined_config.rb +6 -1
- data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +1 -1
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/block_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/block_end_newline.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +36 -1
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -5
- data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +32 -14
- data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +101 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +34 -4
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +8 -29
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +1 -0
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/hash_alignment.rb +4 -7
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -0
- data/lib/rubocop/cop/layout/leading_comment_space.rb +13 -1
- data/lib/rubocop/cop/layout/line_length.rb +43 -10
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +9 -5
- data/lib/rubocop/cop/layout/redundant_line_break.rb +9 -5
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +11 -5
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +10 -0
- data/lib/rubocop/cop/layout/space_around_keyword.rb +6 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +12 -1
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -0
- data/lib/rubocop/cop/layout/space_before_brackets.rb +5 -38
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +12 -3
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -0
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +3 -0
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_range.rb +5 -0
- data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +2 -3
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -5
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +3 -2
- data/lib/rubocop/cop/lint/cop_directive_syntax.rb +13 -7
- data/lib/rubocop/cop/lint/debugger.rb +2 -4
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +5 -2
- data/lib/rubocop/cop/lint/duplicate_methods.rb +111 -23
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +14 -64
- data/lib/rubocop/cop/lint/empty_interpolation.rb +14 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +0 -6
- data/lib/rubocop/cop/lint/float_comparison.rb +32 -10
- data/lib/rubocop/cop/lint/identity_comparison.rb +19 -15
- data/lib/rubocop/cop/lint/literal_as_condition.rb +124 -10
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +17 -8
- data/lib/rubocop/cop/lint/mixed_case_range.rb +2 -2
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -3
- data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +1 -0
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
- data/lib/rubocop/cop/lint/raise_exception.rb +29 -10
- data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +0 -21
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +101 -2
- data/lib/rubocop/cop/lint/redundant_type_conversion.rb +43 -13
- data/lib/rubocop/cop/lint/redundant_with_index.rb +3 -0
- data/lib/rubocop/cop/lint/redundant_with_object.rb +3 -0
- data/lib/rubocop/cop/lint/require_range_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -4
- data/lib/rubocop/cop/lint/rescue_type.rb +1 -1
- data/lib/rubocop/cop/lint/return_in_void_context.rb +9 -11
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +4 -4
- data/lib/rubocop/cop/lint/self_assignment.rb +31 -5
- data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +13 -1
- data/lib/rubocop/cop/lint/shared_mutable_default.rb +12 -1
- data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
- data/lib/rubocop/cop/lint/unexpected_block_arity.rb +2 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_loop.rb +5 -5
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +30 -4
- data/lib/rubocop/cop/lint/useless_assignment.rb +2 -0
- data/lib/rubocop/cop/lint/useless_constant_scoping.rb +9 -12
- data/lib/rubocop/cop/lint/useless_default_value_argument.rb +90 -0
- data/lib/rubocop/cop/lint/useless_numeric_operation.rb +1 -0
- data/lib/rubocop/cop/lint/useless_or.rb +98 -0
- data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +3 -3
- data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +121 -0
- data/lib/rubocop/cop/lint/void.rb +16 -2
- data/lib/rubocop/cop/message_annotator.rb +7 -3
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/block_length.rb +1 -0
- data/lib/rubocop/cop/metrics/method_length.rb +1 -0
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +4 -4
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -3
- data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +2 -2
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
- data/lib/rubocop/cop/mixin/forbidden_identifiers.rb +20 -0
- data/lib/rubocop/cop/mixin/forbidden_pattern.rb +16 -0
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -2
- data/lib/rubocop/cop/mixin/gemspec_help.rb +22 -0
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +15 -14
- data/lib/rubocop/cop/mixin/hash_subset.rb +19 -4
- data/lib/rubocop/cop/mixin/line_length_help.rb +24 -8
- data/lib/rubocop/cop/mixin/method_complexity.rb +1 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +12 -0
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +1 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +18 -2
- data/lib/rubocop/cop/naming/block_forwarding.rb +3 -3
- data/lib/rubocop/cop/naming/file_name.rb +2 -2
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +187 -15
- data/lib/rubocop/cop/naming/predicate_method.rb +319 -0
- data/lib/rubocop/cop/naming/{predicate_name.rb → predicate_prefix.rb} +4 -4
- data/lib/rubocop/cop/naming/variable_name.rb +51 -6
- data/lib/rubocop/cop/registry.rb +9 -6
- data/lib/rubocop/cop/security/eval.rb +2 -1
- data/lib/rubocop/cop/security/json_load.rb +33 -11
- data/lib/rubocop/cop/security/open.rb +1 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +32 -10
- data/lib/rubocop/cop/style/accessor_grouping.rb +32 -6
- data/lib/rubocop/cop/style/arguments_forwarding.rb +21 -24
- data/lib/rubocop/cop/style/array_intersect.rb +113 -38
- data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -0
- data/lib/rubocop/cop/style/bitwise_predicate.rb +8 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +3 -2
- data/lib/rubocop/cop/style/case_like_if.rb +1 -1
- data/lib/rubocop/cop/style/class_and_module_children.rb +48 -10
- data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -1
- data/lib/rubocop/cop/style/collection_methods.rb +1 -0
- data/lib/rubocop/cop/style/collection_querying.rb +167 -0
- data/lib/rubocop/cop/style/combinable_loops.rb +1 -0
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +12 -5
- data/lib/rubocop/cop/style/comparable_between.rb +78 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +26 -8
- data/lib/rubocop/cop/style/constant_visibility.rb +14 -9
- data/lib/rubocop/cop/style/data_inheritance.rb +7 -0
- data/lib/rubocop/cop/style/def_with_parentheses.rb +18 -5
- data/lib/rubocop/cop/style/dig_chain.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +3 -3
- data/lib/rubocop/cop/style/empty_literal.rb +4 -0
- data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +100 -0
- data/lib/rubocop/cop/style/endless_method.rb +176 -18
- data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -7
- data/lib/rubocop/cop/style/explicit_block_argument.rb +3 -3
- data/lib/rubocop/cop/style/exponential_notation.rb +5 -4
- data/lib/rubocop/cop/style/fetch_env_var.rb +32 -6
- data/lib/rubocop/cop/style/float_division.rb +15 -1
- data/lib/rubocop/cop/style/for.rb +1 -0
- data/lib/rubocop/cop/style/format_string_token.rb +38 -11
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -2
- data/lib/rubocop/cop/style/global_std_stream.rb +3 -0
- data/lib/rubocop/cop/style/guard_clause.rb +2 -1
- data/lib/rubocop/cop/style/hash_conversion.rb +16 -8
- data/lib/rubocop/cop/style/hash_each_methods.rb +3 -2
- data/lib/rubocop/cop/style/hash_fetch_chain.rb +104 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -1
- data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +3 -3
- data/lib/rubocop/cop/style/if_inside_else.rb +10 -13
- data/lib/rubocop/cop/style/if_unless_modifier.rb +35 -8
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +4 -7
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +10 -6
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +2 -2
- data/lib/rubocop/cop/style/ip_addresses.rb +2 -2
- data/lib/rubocop/cop/style/it_assignment.rb +69 -12
- data/lib/rubocop/cop/style/it_block_parameter.rb +121 -0
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +13 -7
- data/lib/rubocop/cop/style/lambda.rb +1 -0
- data/lib/rubocop/cop/style/lambda_call.rb +7 -2
- data/lib/rubocop/cop/style/line_end_concatenation.rb +10 -4
- data/lib/rubocop/cop/style/map_into_array.rb +4 -1
- data/lib/rubocop/cop/style/map_to_hash.rb +12 -3
- data/lib/rubocop/cop/style/map_to_set.rb +1 -3
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +9 -8
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +16 -0
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -1
- data/lib/rubocop/cop/style/min_max_comparison.rb +13 -5
- data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -1
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -0
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -9
- data/lib/rubocop/cop/style/next.rb +44 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +9 -7
- data/lib/rubocop/cop/style/object_then.rb +1 -0
- data/lib/rubocop/cop/style/one_line_conditional.rb +17 -9
- data/lib/rubocop/cop/style/parallel_assignment.rb +32 -20
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -0
- data/lib/rubocop/cop/style/raise_args.rb +8 -8
- data/lib/rubocop/cop/style/redundant_array_flatten.rb +50 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +35 -0
- data/lib/rubocop/cop/style/redundant_condition.rb +57 -0
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +14 -4
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -9
- data/lib/rubocop/cop/style/redundant_format.rb +79 -18
- data/lib/rubocop/cop/style/redundant_freeze.rb +2 -2
- data/lib/rubocop/cop/style/redundant_interpolation.rb +12 -3
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +1 -4
- data/lib/rubocop/cop/style/redundant_parentheses.rb +73 -18
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +4 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -0
- data/lib/rubocop/cop/style/redundant_self.rb +9 -5
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/redundant_sort_by.rb +17 -1
- data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
- data/lib/rubocop/cop/style/rescue_modifier.rb +3 -0
- data/lib/rubocop/cop/style/return_nil.rb +2 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +61 -14
- data/lib/rubocop/cop/style/select_by_regexp.rb +4 -1
- data/lib/rubocop/cop/style/semicolon.rb +23 -7
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +3 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +10 -7
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +75 -101
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/string_concatenation.rb +18 -15
- data/lib/rubocop/cop/style/struct_inheritance.rb +8 -1
- data/lib/rubocop/cop/style/super_arguments.rb +1 -2
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +3 -1
- data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -0
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +52 -1
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +47 -6
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +48 -6
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_else.rb +10 -9
- data/lib/rubocop/cop/team.rb +1 -1
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/utils/format_string.rb +15 -2
- data/lib/rubocop/cop/variable_force/assignment.rb +7 -3
- data/lib/rubocop/cop/variable_force/scope.rb +1 -1
- data/lib/rubocop/cop/variable_force/variable.rb +3 -8
- data/lib/rubocop/cop/variable_force.rb +26 -9
- data/lib/rubocop/cops_documentation_generator.rb +23 -7
- data/lib/rubocop/directive_comment.rb +1 -1
- data/lib/rubocop/ext/regexp_node.rb +0 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +19 -5
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/html_formatter.rb +1 -1
- data/lib/rubocop/formatter/markdown_formatter.rb +1 -0
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
- data/lib/rubocop/formatter/pacman_formatter.rb +2 -1
- data/lib/rubocop/lsp/diagnostic.rb +25 -24
- data/lib/rubocop/lsp/routes.rb +65 -9
- data/lib/rubocop/lsp/runtime.rb +5 -5
- data/lib/rubocop/lsp/server.rb +2 -2
- data/lib/rubocop/lsp/stdin_runner.rb +3 -17
- data/lib/rubocop/magic_comment.rb +8 -0
- data/lib/rubocop/pending_cops_reporter.rb +56 -0
- data/lib/rubocop/plugin/configuration_integrator.rb +2 -0
- data/lib/rubocop/plugin/load_error.rb +1 -1
- data/lib/rubocop/plugin.rb +9 -2
- data/lib/rubocop/result_cache.rb +14 -12
- data/lib/rubocop/rspec/cop_helper.rb +6 -1
- data/lib/rubocop/rspec/expect_offense.rb +9 -3
- data/lib/rubocop/rspec/shared_contexts.rb +34 -0
- data/lib/rubocop/rspec/support.rb +3 -0
- data/lib/rubocop/runner.rb +10 -4
- data/lib/rubocop/server/cache.rb +17 -12
- data/lib/rubocop/server/client_command/base.rb +10 -0
- data/lib/rubocop/server/client_command/exec.rb +2 -1
- data/lib/rubocop/server/client_command/start.rb +11 -1
- data/lib/rubocop/target_finder.rb +13 -9
- data/lib/rubocop/target_ruby.rb +11 -2
- data/lib/rubocop/version.rb +14 -7
- data/lib/rubocop.rb +17 -2
- data/lib/ruby_lsp/rubocop/addon.rb +25 -10
- data/lib/ruby_lsp/rubocop/runtime_adapter.rb +57 -5
- metadata +24 -8
- data/lib/rubocop/cop/utils/regexp_ranges.rb +0 -113
|
@@ -4,8 +4,8 @@ module RuboCop
|
|
|
4
4
|
module Cop
|
|
5
5
|
module Lint
|
|
6
6
|
# Checks for useless constant scoping. Private constants must be defined using
|
|
7
|
-
# `private_constant
|
|
8
|
-
#
|
|
7
|
+
# `private_constant`. Even if `private` access modifier is used, it is public scope despite
|
|
8
|
+
# its appearance.
|
|
9
9
|
#
|
|
10
10
|
# It does not support autocorrection due to behavior change and multiple ways to fix it.
|
|
11
11
|
# Or a public constant may be intended.
|
|
@@ -26,14 +26,6 @@ module RuboCop
|
|
|
26
26
|
#
|
|
27
27
|
# # good
|
|
28
28
|
# class Foo
|
|
29
|
-
# class << self
|
|
30
|
-
# private
|
|
31
|
-
# PRIVATE_CONST = 42
|
|
32
|
-
# end
|
|
33
|
-
# end
|
|
34
|
-
#
|
|
35
|
-
# # good
|
|
36
|
-
# class Foo
|
|
37
29
|
# PUBLIC_CONST = 42 # If private scope is not intended.
|
|
38
30
|
# end
|
|
39
31
|
#
|
|
@@ -46,7 +38,6 @@ module RuboCop
|
|
|
46
38
|
PATTERN
|
|
47
39
|
|
|
48
40
|
def on_casgn(node)
|
|
49
|
-
return if node.each_ancestor(:sclass).any?
|
|
50
41
|
return unless after_private_modifier?(node.left_siblings)
|
|
51
42
|
return if private_constantize?(node.right_siblings, node.name)
|
|
52
43
|
|
|
@@ -56,7 +47,13 @@ module RuboCop
|
|
|
56
47
|
private
|
|
57
48
|
|
|
58
49
|
def after_private_modifier?(left_siblings)
|
|
59
|
-
left_siblings.compact.select
|
|
50
|
+
access_modifier_candidates = left_siblings.compact.select do |left_sibling|
|
|
51
|
+
left_sibling.respond_to?(:send_type?) && left_sibling.send_type?
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
access_modifier_candidates.any? do |candidate|
|
|
55
|
+
candidate.command?(:private) && candidate.arguments.none?
|
|
56
|
+
end
|
|
60
57
|
end
|
|
61
58
|
|
|
62
59
|
def private_constantize?(right_siblings, const_value)
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Lint
|
|
6
|
+
# Checks for usage of method `fetch` or `Array.new` with default value argument
|
|
7
|
+
# and block. In such cases, block will always be used as default value.
|
|
8
|
+
#
|
|
9
|
+
# This cop emulates Ruby warning "block supersedes default value argument" which
|
|
10
|
+
# applies to `Array.new`, `Array#fetch`, `Hash#fetch`, `ENV.fetch` and
|
|
11
|
+
# `Thread#fetch`.
|
|
12
|
+
#
|
|
13
|
+
# A `fetch` call without a receiver is considered a custom method and does not register
|
|
14
|
+
# an offense.
|
|
15
|
+
#
|
|
16
|
+
# @safety
|
|
17
|
+
# This cop is unsafe because the receiver could have nonstandard implementation
|
|
18
|
+
# of `fetch`, or be a class other than the one listed above.
|
|
19
|
+
#
|
|
20
|
+
# It is also unsafe because default value argument could have side effects:
|
|
21
|
+
#
|
|
22
|
+
# [source,ruby]
|
|
23
|
+
# ----
|
|
24
|
+
# def x(a) = puts "side effect"
|
|
25
|
+
# Array.new(5, x(1)) { 2 }
|
|
26
|
+
# ----
|
|
27
|
+
#
|
|
28
|
+
# so removing it would change behavior.
|
|
29
|
+
#
|
|
30
|
+
# @example
|
|
31
|
+
# # bad
|
|
32
|
+
# x.fetch(key, default_value) { block_value }
|
|
33
|
+
# Array.new(size, default_value) { block_value }
|
|
34
|
+
#
|
|
35
|
+
# # good
|
|
36
|
+
# x.fetch(key) { block_value }
|
|
37
|
+
# Array.new(size) { block_value }
|
|
38
|
+
#
|
|
39
|
+
# # also good - in case default value argument is desired instead
|
|
40
|
+
# x.fetch(key, default_value)
|
|
41
|
+
# Array.new(size, default_value)
|
|
42
|
+
#
|
|
43
|
+
# # good - keyword arguments aren't registered as offenses
|
|
44
|
+
# x.fetch(key, keyword: :arg) { block_value }
|
|
45
|
+
#
|
|
46
|
+
# @example AllowedReceivers: ['Rails.cache']
|
|
47
|
+
# # good
|
|
48
|
+
# Rails.cache.fetch(name, options) { block }
|
|
49
|
+
#
|
|
50
|
+
class UselessDefaultValueArgument < Base
|
|
51
|
+
include AllowedReceivers
|
|
52
|
+
extend AutoCorrector
|
|
53
|
+
|
|
54
|
+
MSG = 'Block supersedes default value argument.'
|
|
55
|
+
|
|
56
|
+
RESTRICT_ON_SEND = %i[fetch new].freeze
|
|
57
|
+
|
|
58
|
+
# @!method default_value_argument_and_block(node)
|
|
59
|
+
def_node_matcher :default_value_argument_and_block, <<~PATTERN
|
|
60
|
+
(any_block
|
|
61
|
+
{
|
|
62
|
+
(call !nil? :fetch $_key $_default_value)
|
|
63
|
+
(send (const _ :Array) :new $_size $_default_value)
|
|
64
|
+
}
|
|
65
|
+
_args
|
|
66
|
+
_block_body)
|
|
67
|
+
PATTERN
|
|
68
|
+
|
|
69
|
+
def on_send(node)
|
|
70
|
+
unless (prev_arg_node, default_value_node = default_value_argument_and_block(node.parent))
|
|
71
|
+
return
|
|
72
|
+
end
|
|
73
|
+
return if allowed_receiver?(node.receiver)
|
|
74
|
+
return if hash_without_braces?(default_value_node)
|
|
75
|
+
|
|
76
|
+
add_offense(default_value_node) do |corrector|
|
|
77
|
+
corrector.remove(prev_arg_node.source_range.end.join(default_value_node.source_range))
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
alias on_csend on_send
|
|
81
|
+
|
|
82
|
+
private
|
|
83
|
+
|
|
84
|
+
def hash_without_braces?(node)
|
|
85
|
+
node.hash_type? && !node.braces?
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Lint
|
|
6
|
+
# Checks for useless OR (`||` and `or`) expressions.
|
|
7
|
+
#
|
|
8
|
+
# Some methods always return a truthy value, even when called
|
|
9
|
+
# on `nil` (e.g. `nil.to_i` evaluates to `0`). Therefore, OR expressions
|
|
10
|
+
# appended after these methods will never evaluate.
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
#
|
|
14
|
+
# # bad
|
|
15
|
+
# x.to_a || fallback
|
|
16
|
+
# x.to_c || fallback
|
|
17
|
+
# x.to_d || fallback
|
|
18
|
+
# x.to_i || fallback
|
|
19
|
+
# x.to_f || fallback
|
|
20
|
+
# x.to_h || fallback
|
|
21
|
+
# x.to_r || fallback
|
|
22
|
+
# x.to_s || fallback
|
|
23
|
+
# x.to_sym || fallback
|
|
24
|
+
# x.intern || fallback
|
|
25
|
+
# x.inspect || fallback
|
|
26
|
+
# x.hash || fallback
|
|
27
|
+
# x.object_id || fallback
|
|
28
|
+
# x.__id__ || fallback
|
|
29
|
+
#
|
|
30
|
+
# x.to_s or fallback
|
|
31
|
+
#
|
|
32
|
+
# # good - if fallback is same as return value of method called on nil
|
|
33
|
+
# x.to_a # nil.to_a returns []
|
|
34
|
+
# x.to_c # nil.to_c returns (0+0i)
|
|
35
|
+
# x.to_d # nil.to_d returns 0.0
|
|
36
|
+
# x.to_i # nil.to_i returns 0
|
|
37
|
+
# x.to_f # nil.to_f returns 0.0
|
|
38
|
+
# x.to_h # nil.to_h returns {}
|
|
39
|
+
# x.to_r # nil.to_r returns (0/1)
|
|
40
|
+
# x.to_s # nil.to_s returns ''
|
|
41
|
+
# x.to_sym # nil.to_sym raises an error
|
|
42
|
+
# x.intern # nil.intern raises an error
|
|
43
|
+
# x.inspect # nil.inspect returns "nil"
|
|
44
|
+
# x.hash # nil.hash returns an Integer
|
|
45
|
+
# x.object_id # nil.object_id returns an Integer
|
|
46
|
+
# x.__id__ # nil.object_id returns an Integer
|
|
47
|
+
#
|
|
48
|
+
# # good - if the intention is not to call the method on nil
|
|
49
|
+
# x&.to_a || fallback
|
|
50
|
+
# x&.to_c || fallback
|
|
51
|
+
# x&.to_d || fallback
|
|
52
|
+
# x&.to_i || fallback
|
|
53
|
+
# x&.to_f || fallback
|
|
54
|
+
# x&.to_h || fallback
|
|
55
|
+
# x&.to_r || fallback
|
|
56
|
+
# x&.to_s || fallback
|
|
57
|
+
# x&.to_sym || fallback
|
|
58
|
+
# x&.intern || fallback
|
|
59
|
+
# x&.inspect || fallback
|
|
60
|
+
# x&.hash || fallback
|
|
61
|
+
# x&.object_id || fallback
|
|
62
|
+
# x&.__id__ || fallback
|
|
63
|
+
#
|
|
64
|
+
# x&.to_s or fallback
|
|
65
|
+
#
|
|
66
|
+
class UselessOr < Base
|
|
67
|
+
MSG = '`%<rhs>s` will never evaluate because `%<lhs>s` always returns a truthy value.'
|
|
68
|
+
|
|
69
|
+
TRUTHY_RETURN_VALUE_METHODS = Set[:to_a, :to_c, :to_d, :to_i, :to_f, :to_h, :to_r,
|
|
70
|
+
:to_s, :to_sym, :intern, :inspect, :hash, :object_id,
|
|
71
|
+
:__id__].freeze
|
|
72
|
+
|
|
73
|
+
# @!method truthy_return_value_method?(node)
|
|
74
|
+
def_node_matcher :truthy_return_value_method?, <<~PATTERN
|
|
75
|
+
(send _ %TRUTHY_RETURN_VALUE_METHODS)
|
|
76
|
+
PATTERN
|
|
77
|
+
|
|
78
|
+
def on_or(node)
|
|
79
|
+
if truthy_return_value_method?(node.lhs)
|
|
80
|
+
report_offense(node, node.lhs)
|
|
81
|
+
elsif truthy_return_value_method?(node.rhs)
|
|
82
|
+
parent = node.parent
|
|
83
|
+
parent = parent.parent if parent&.begin_type?
|
|
84
|
+
|
|
85
|
+
report_offense(parent, node.rhs) if parent&.or_type?
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private
|
|
90
|
+
|
|
91
|
+
def report_offense(or_node, truthy_node)
|
|
92
|
+
add_offense(or_node.loc.operator.join(or_node.rhs.source_range),
|
|
93
|
+
message: format(MSG, lhs: truthy_node.source, rhs: or_node.rhs.source))
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -89,7 +89,7 @@ module RuboCop
|
|
|
89
89
|
private
|
|
90
90
|
|
|
91
91
|
def inspect_def(node, def_node)
|
|
92
|
-
return if allowed_arguments(def_node.arguments)
|
|
92
|
+
return if allowed_arguments?(def_node.arguments)
|
|
93
93
|
|
|
94
94
|
add_offense(node.loc.selector, message: format(MSG, method_name: def_node.method_name))
|
|
95
95
|
end
|
|
@@ -101,7 +101,7 @@ module RuboCop
|
|
|
101
101
|
definition = find_method_definition(node, method_name)
|
|
102
102
|
|
|
103
103
|
return unless definition
|
|
104
|
-
return if allowed_arguments(definition.arguments)
|
|
104
|
+
return if allowed_arguments?(definition.arguments)
|
|
105
105
|
|
|
106
106
|
add_offense(node, message: format(MSG, method_name: method_name))
|
|
107
107
|
end
|
|
@@ -115,7 +115,7 @@ module RuboCop
|
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
# `ruby2_keywords` is only allowed if there's a `restarg` and no keyword arguments
|
|
118
|
-
def allowed_arguments(arguments)
|
|
118
|
+
def allowed_arguments?(arguments)
|
|
119
119
|
return false if arguments.empty?
|
|
120
120
|
|
|
121
121
|
arguments.each_child_node(:restarg).any? &&
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Lint
|
|
6
|
+
module Utils
|
|
7
|
+
# Utility class that checks if the receiver can't be nil.
|
|
8
|
+
class NilReceiverChecker
|
|
9
|
+
NIL_METHODS = (nil.methods + %i[!]).to_set.freeze
|
|
10
|
+
|
|
11
|
+
def initialize(receiver, additional_nil_methods)
|
|
12
|
+
@receiver = receiver
|
|
13
|
+
@additional_nil_methods = additional_nil_methods
|
|
14
|
+
@checked_nodes = {}.compare_by_identity
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def cant_be_nil?
|
|
18
|
+
sole_condition_of_parent_if?(@receiver) || _cant_be_nil?(@receiver.parent, @receiver)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
# rubocop:disable Metrics
|
|
24
|
+
def _cant_be_nil?(node, receiver)
|
|
25
|
+
return false unless node
|
|
26
|
+
|
|
27
|
+
# For some nodes, we check their parent and then some children for these parents.
|
|
28
|
+
# This is added to avoid infinite loops.
|
|
29
|
+
return false if @checked_nodes.key?(node)
|
|
30
|
+
|
|
31
|
+
@checked_nodes[node] = true
|
|
32
|
+
|
|
33
|
+
case node.type
|
|
34
|
+
when :def, :class, :module, :sclass
|
|
35
|
+
return false
|
|
36
|
+
when :send
|
|
37
|
+
return non_nil_method?(node.method_name) if node.receiver == receiver
|
|
38
|
+
|
|
39
|
+
node.arguments.each do |argument|
|
|
40
|
+
return true if _cant_be_nil?(argument, receiver)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
return true if _cant_be_nil?(node.receiver, receiver)
|
|
44
|
+
when :begin
|
|
45
|
+
return true if _cant_be_nil?(node.children.first, receiver)
|
|
46
|
+
when :if, :case
|
|
47
|
+
return true if _cant_be_nil?(node.condition, receiver)
|
|
48
|
+
when :and, :or
|
|
49
|
+
return true if _cant_be_nil?(node.lhs, receiver)
|
|
50
|
+
when :pair
|
|
51
|
+
if _cant_be_nil?(node.key, receiver) ||
|
|
52
|
+
_cant_be_nil?(node.value, receiver)
|
|
53
|
+
return true
|
|
54
|
+
end
|
|
55
|
+
when :when
|
|
56
|
+
node.each_condition do |condition|
|
|
57
|
+
return true if _cant_be_nil?(condition, receiver)
|
|
58
|
+
end
|
|
59
|
+
when :lvasgn, :ivasgn, :cvasgn, :gvasgn, :casgn
|
|
60
|
+
return true if _cant_be_nil?(node.expression, receiver)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Due to how `if/else` are implemented (`elsif` is a child of `if` or another `elsif`),
|
|
64
|
+
# using left_siblings will not work correctly for them.
|
|
65
|
+
if !else_branch?(node) || (node.if_type? && !node.elsif?)
|
|
66
|
+
node.left_siblings.reverse_each do |sibling|
|
|
67
|
+
next unless sibling.is_a?(AST::Node)
|
|
68
|
+
|
|
69
|
+
return true if _cant_be_nil?(sibling, receiver)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
if node.parent
|
|
74
|
+
_cant_be_nil?(node.parent, receiver)
|
|
75
|
+
else
|
|
76
|
+
false
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
# rubocop:enable Metrics
|
|
80
|
+
|
|
81
|
+
def non_nil_method?(method_name)
|
|
82
|
+
!NIL_METHODS.include?(method_name) && !@additional_nil_methods.include?(method_name)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
|
86
|
+
def sole_condition_of_parent_if?(node)
|
|
87
|
+
parent = node.parent
|
|
88
|
+
|
|
89
|
+
while parent
|
|
90
|
+
if parent.if_type?
|
|
91
|
+
if parent.condition == node
|
|
92
|
+
return true
|
|
93
|
+
elsif parent.elsif?
|
|
94
|
+
parent = find_top_if(parent)
|
|
95
|
+
end
|
|
96
|
+
elsif else_branch?(parent)
|
|
97
|
+
# Find the top `if` for `else`.
|
|
98
|
+
parent = parent.parent
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
parent = parent&.parent
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
false
|
|
105
|
+
end
|
|
106
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
|
107
|
+
|
|
108
|
+
def else_branch?(node)
|
|
109
|
+
node.parent&.if_type? && node.parent.else_branch == node
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def find_top_if(node)
|
|
113
|
+
node = node.parent while node.elsif?
|
|
114
|
+
|
|
115
|
+
node
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -16,6 +16,12 @@ module RuboCop
|
|
|
16
16
|
# enumerator.each { |item| item >= 2 } #=> [2, 3]
|
|
17
17
|
# ----
|
|
18
18
|
#
|
|
19
|
+
# NOTE: Return values in assignment method definitions such as `def foo=(arg)` are
|
|
20
|
+
# detected because they are in a void context. However, autocorrection does not remove
|
|
21
|
+
# the return value, as that would change behavior. In such cases, whether to remove
|
|
22
|
+
# the return value or rename the method to something more appropriate should be left to
|
|
23
|
+
# the user.
|
|
24
|
+
#
|
|
19
25
|
# @example CheckForMethodsWithNoSideEffects: false (default)
|
|
20
26
|
# # bad
|
|
21
27
|
# def some_method
|
|
@@ -86,6 +92,7 @@ module RuboCop
|
|
|
86
92
|
check_expression(node.body)
|
|
87
93
|
end
|
|
88
94
|
alias on_numblock on_block
|
|
95
|
+
alias on_itblock on_block
|
|
89
96
|
|
|
90
97
|
def on_begin(node)
|
|
91
98
|
check_begin(node)
|
|
@@ -125,9 +132,14 @@ module RuboCop
|
|
|
125
132
|
check_nonmutating(expr)
|
|
126
133
|
end
|
|
127
134
|
|
|
135
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
128
136
|
def check_void_op(node, &block)
|
|
129
|
-
node = node.children.first while node
|
|
130
|
-
return unless node
|
|
137
|
+
node = node.children.first while node&.begin_type?
|
|
138
|
+
return unless node&.call_type? && OPERATORS.include?(node.method_name)
|
|
139
|
+
if !UNARY_OPERATORS.include?(node.method_name) && node.loc.dot && node.arguments.none?
|
|
140
|
+
return
|
|
141
|
+
end
|
|
142
|
+
|
|
131
143
|
return if block && yield(node)
|
|
132
144
|
|
|
133
145
|
add_offense(node.loc.selector,
|
|
@@ -135,6 +147,7 @@ module RuboCop
|
|
|
135
147
|
autocorrect_void_op(corrector, node)
|
|
136
148
|
end
|
|
137
149
|
end
|
|
150
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
138
151
|
|
|
139
152
|
def check_var(node)
|
|
140
153
|
return unless node.variable? || node.const_type?
|
|
@@ -226,6 +239,7 @@ module RuboCop
|
|
|
226
239
|
|
|
227
240
|
def autocorrect_void_expression(corrector, node)
|
|
228
241
|
return if node.parent.if_type?
|
|
242
|
+
return if (def_node = node.each_ancestor(:any_def).first) && def_node.assignment_method?
|
|
229
243
|
|
|
230
244
|
corrector.remove(range_with_surrounding_space(range: node.source_range, side: :left))
|
|
231
245
|
end
|
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
|
32
32
|
# @param [String] cop_name for specific cop name
|
|
33
33
|
# @param [Hash] cop_config configs for specific cop, from config#for_cop
|
|
34
34
|
# @option cop_config [String] :StyleGuide Extension of base styleguide URL
|
|
35
|
-
# @option cop_config [String] :
|
|
35
|
+
# @option cop_config [String] :References Full reference URLs
|
|
36
36
|
# @option cop_config [String] :Details
|
|
37
37
|
#
|
|
38
38
|
# @param [Hash, nil] options optional
|
|
@@ -100,8 +100,12 @@ module RuboCop
|
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
def reference_urls
|
|
103
|
-
urls =
|
|
104
|
-
|
|
103
|
+
urls = cop_config
|
|
104
|
+
.values_at('References', 'Reference') # Support legacy Reference key
|
|
105
|
+
.flat_map { |url| Array(url) }
|
|
106
|
+
.reject(&:empty?)
|
|
107
|
+
|
|
108
|
+
urls unless urls.empty?
|
|
105
109
|
end
|
|
106
110
|
|
|
107
111
|
def extra_details?
|
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
|
39
39
|
class AbcSize < Base
|
|
40
40
|
include MethodComplexity
|
|
41
41
|
|
|
42
|
-
MSG = 'Assignment Branch Condition size for
|
|
42
|
+
MSG = 'Assignment Branch Condition size for `%<method>s` is too high. ' \
|
|
43
43
|
'[%<abc_vector>s %<complexity>.4g/%<max>.4g]'
|
|
44
44
|
|
|
45
45
|
private
|
|
@@ -145,7 +145,7 @@ module RuboCop
|
|
|
145
145
|
|
|
146
146
|
def extract_body(node)
|
|
147
147
|
case node.type
|
|
148
|
-
when :class, :module, :sclass, :block, :numblock, :def, :defs
|
|
148
|
+
when :class, :module, :sclass, :block, :numblock, :itblock, :def, :defs
|
|
149
149
|
node.body
|
|
150
150
|
when :casgn
|
|
151
151
|
extract_body(node.expression)
|
|
@@ -66,7 +66,7 @@ module RuboCop
|
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
# @deprecated Use processed_source.line_with_comment?(line)
|
|
69
|
-
def end_of_line_comment(line)
|
|
69
|
+
def end_of_line_comment(line) # rubocop:disable Naming/PredicateMethod
|
|
70
70
|
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
|
71
71
|
`end_of_line_comment` is deprecated. Use `processed_source.line_with_comment?` instead.
|
|
72
72
|
WARNING
|
|
@@ -18,12 +18,12 @@ module RuboCop
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
# @deprecated Use allowed_line? instead
|
|
21
|
-
def ignored_line?
|
|
21
|
+
def ignored_line?(line)
|
|
22
22
|
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
|
23
23
|
`ignored_line?` is deprecated. Use `allowed_line?` instead.
|
|
24
24
|
WARNING
|
|
25
25
|
|
|
26
|
-
allowed_line?
|
|
26
|
+
allowed_line?(line)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def matches_allowed_pattern?(line)
|
|
@@ -31,12 +31,12 @@ module RuboCop
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
# @deprecated Use matches_allowed_pattern? instead
|
|
34
|
-
def matches_ignored_pattern?
|
|
34
|
+
def matches_ignored_pattern?(line)
|
|
35
35
|
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
|
36
36
|
`matches_ignored_pattern?` is deprecated. Use `matches_allowed_pattern?` instead.
|
|
37
37
|
WARNING
|
|
38
38
|
|
|
39
|
-
matches_allowed_pattern?
|
|
39
|
+
matches_allowed_pattern?(line)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def allowed_patterns
|
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
|
48
48
|
|
|
49
49
|
args = process_args(node.arguments)
|
|
50
50
|
return extract_breakable_node_from_elements(node, args, max)
|
|
51
|
-
elsif node.
|
|
51
|
+
elsif node.any_def_type?
|
|
52
52
|
return extract_breakable_node_from_elements(node, node.arguments, max)
|
|
53
53
|
elsif node.type?(:array, :hash)
|
|
54
54
|
return extract_breakable_node_from_elements(node, node.children, max)
|
|
@@ -220,14 +220,14 @@ module RuboCop
|
|
|
220
220
|
|
|
221
221
|
# @api private
|
|
222
222
|
def already_on_multiple_lines?(node)
|
|
223
|
-
return node.first_line != node.last_argument.last_line if node.
|
|
223
|
+
return node.first_line != node.last_argument.last_line if node.any_def_type?
|
|
224
224
|
|
|
225
225
|
!node.single_line?
|
|
226
226
|
end
|
|
227
227
|
|
|
228
228
|
def chained_to_heredoc?(node)
|
|
229
229
|
while (node = node.receiver)
|
|
230
|
-
return true if node.
|
|
230
|
+
return true if node.any_str_type? && node.heredoc?
|
|
231
231
|
end
|
|
232
232
|
|
|
233
233
|
false
|
|
@@ -35,12 +35,12 @@ module RuboCop
|
|
|
35
35
|
comment_line_numbers = processed_source.comments.map { |comment| comment.loc.line }
|
|
36
36
|
|
|
37
37
|
comment_line_numbers.any? do |comment_line_number|
|
|
38
|
-
comment_line_number
|
|
38
|
+
comment_line_number.between?(node.first_line, node.last_line)
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def safe_to_split?(node)
|
|
43
|
-
node.each_descendant(:if, :case, :kwbegin, :
|
|
43
|
+
node.each_descendant(:if, :case, :kwbegin, :any_def).none? &&
|
|
44
44
|
node.each_descendant(:dstr, :str).none? { |n| n.heredoc? || n.value.include?("\n") } &&
|
|
45
45
|
node.each_descendant(:begin, :sym).none? { |b| !b.single_line? }
|
|
46
46
|
end
|
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
|
19
19
|
|
|
20
20
|
# @!method non_public_modifier?(node)
|
|
21
21
|
def_node_matcher :non_public_modifier?, <<~PATTERN
|
|
22
|
-
(send nil? {:private :protected :private_class_method} (
|
|
22
|
+
(send nil? {:private :protected :private_class_method} (any_def ...))
|
|
23
23
|
PATTERN
|
|
24
24
|
end
|
|
25
25
|
end
|
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
|
21
21
|
|
|
22
22
|
# @!method empty_line_required?(node)
|
|
23
23
|
def_node_matcher :empty_line_required?,
|
|
24
|
-
'{
|
|
24
|
+
'{any_def class module (send nil? {:private :protected :public})}'
|
|
25
25
|
|
|
26
26
|
def check(node, body, adjusted_first_line: nil)
|
|
27
27
|
return if valid_body_style?(body)
|
|
@@ -19,8 +19,7 @@ module RuboCop
|
|
|
19
19
|
def check_end_kw_alignment(node, align_ranges)
|
|
20
20
|
return if ignored_node?(node)
|
|
21
21
|
|
|
22
|
-
end_loc = node.loc.end
|
|
23
|
-
return if accept_end_kw_alignment?(end_loc)
|
|
22
|
+
return unless (end_loc = node.loc.end)
|
|
24
23
|
|
|
25
24
|
matching = matching_ranges(end_loc, align_ranges)
|
|
26
25
|
|
|
@@ -57,11 +56,6 @@ module RuboCop
|
|
|
57
56
|
add_offense(end_loc, message: msg) { |corrector| autocorrect(corrector, node) }
|
|
58
57
|
end
|
|
59
58
|
|
|
60
|
-
def accept_end_kw_alignment?(end_loc)
|
|
61
|
-
end_loc.nil? || # Discard modifier forms of if/while/until.
|
|
62
|
-
!/\A[ \t]*end/.match?(processed_source.lines[end_loc.line - 1])
|
|
63
|
-
end
|
|
64
|
-
|
|
65
59
|
def style_parameter_name
|
|
66
60
|
'EnforcedStyleAlignWith'
|
|
67
61
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
# This module encapsulates the ability to forbid certain identifiers in a cop.
|
|
6
|
+
module ForbiddenIdentifiers
|
|
7
|
+
SIGILS = '@$' # if a variable starts with a sigil it will be removed
|
|
8
|
+
|
|
9
|
+
def forbidden_identifier?(name)
|
|
10
|
+
name = name.to_s.delete(SIGILS)
|
|
11
|
+
|
|
12
|
+
forbidden_identifiers.any? && forbidden_identifiers.include?(name)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def forbidden_identifiers
|
|
16
|
+
cop_config.fetch('ForbiddenIdentifiers', [])
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|