rubocop 1.50.2 → 1.62.1
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 +7 -5
- data/assets/output.css.erb +159 -0
- data/assets/output.html.erb +1 -160
- data/config/default.yml +196 -28
- data/config/obsoletion.yml +5 -0
- data/lib/rubocop/cli/command/auto_generate_config.rb +22 -8
- data/lib/rubocop/cli/command/lsp.rb +19 -0
- data/lib/rubocop/cli.rb +10 -2
- data/lib/rubocop/config.rb +8 -2
- data/lib/rubocop/config_finder.rb +14 -4
- data/lib/rubocop/config_loader.rb +0 -1
- data/lib/rubocop/config_loader_resolver.rb +4 -3
- data/lib/rubocop/config_obsoletion/parameter_rule.rb +9 -1
- data/lib/rubocop/config_obsoletion.rb +13 -10
- data/lib/rubocop/config_validator.rb +14 -7
- data/lib/rubocop/cop/autocorrect_logic.rb +9 -2
- data/lib/rubocop/cop/base.rb +23 -4
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -0
- data/lib/rubocop/cop/bundler/duplicated_group.rb +127 -0
- data/lib/rubocop/cop/bundler/gem_comment.rb +3 -3
- data/lib/rubocop/cop/bundler/gem_version.rb +2 -2
- data/lib/rubocop/cop/bundler/ordered_gems.rb +9 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +1 -1
- 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/lambda_literal_to_method_corrector.rb +7 -4
- data/lib/rubocop/cop/exclude_limit.rb +1 -1
- data/lib/rubocop/cop/gemspec/dependency_version.rb +2 -2
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/development_dependencies.rb +1 -1
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +9 -1
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +5 -1
- data/lib/rubocop/cop/generator/require_file_injector.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +32 -8
- data/lib/rubocop/cop/internal_affairs/example_description.rb +45 -24
- data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +3 -1
- data/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +8 -6
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +19 -20
- data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +53 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +127 -33
- data/lib/rubocop/cop/internal_affairs/redundant_expect_offense_arguments.rb +34 -0
- data/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb +11 -2
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -0
- data/lib/rubocop/cop/internal_affairs.rb +2 -0
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +7 -0
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +1 -2
- data/lib/rubocop/cop/layout/dot_position.rb +1 -5
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +42 -9
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +14 -7
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +27 -4
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +2 -0
- data/lib/rubocop/cop/layout/end_alignment.rb +15 -3
- data/lib/rubocop/cop/layout/extra_spacing.rb +4 -10
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +22 -7
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +4 -4
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +4 -1
- data/lib/rubocop/cop/layout/indentation_style.rb +1 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +3 -3
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +17 -9
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +2 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +18 -3
- data/lib/rubocop/cop/layout/redundant_line_break.rb +30 -7
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +4 -4
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +5 -0
- data/lib/rubocop/cop/layout/space_after_comma.rb +9 -1
- data/lib/rubocop/cop/layout/space_after_not.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_operators.rb +53 -21
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +19 -10
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -0
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_parens.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_range_literal.rb +1 -1
- data/lib/rubocop/cop/layout/trailing_empty_lines.rb +5 -0
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +13 -1
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +4 -4
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +2 -2
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +19 -5
- data/lib/rubocop/cop/lint/duplicate_hash_key.rb +2 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +46 -19
- data/lib/rubocop/cop/lint/empty_block.rb +1 -1
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +6 -7
- data/lib/rubocop/cop/lint/float_comparison.rb +10 -0
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +2 -1
- data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +1 -1
- data/lib/rubocop/cop/lint/identity_comparison.rb +0 -1
- data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +5 -3
- data/lib/rubocop/cop/lint/inherit_exception.rb +9 -0
- data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +56 -0
- data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +1 -1
- data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +85 -0
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/missing_super.rb +34 -5
- data/lib/rubocop/cop/lint/mixed_case_range.rb +111 -0
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +6 -21
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +10 -7
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +3 -5
- data/lib/rubocop/cop/lint/number_conversion.rb +14 -4
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +2 -2
- data/lib/rubocop/cop/lint/ordered_magic_comments.rb +0 -1
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +130 -0
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +12 -3
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +72 -8
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_with_index.rb +3 -2
- data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
- data/lib/rubocop/cop/lint/rescue_type.rb +1 -3
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +14 -8
- data/lib/rubocop/cop/lint/script_permission.rb +3 -3
- data/lib/rubocop/cop/lint/self_assignment.rb +38 -0
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -2
- data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowed_exception.rb +5 -11
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +7 -1
- data/lib/rubocop/cop/lint/struct_new_override.rb +12 -12
- data/lib/rubocop/cop/lint/suppressed_exception.rb +2 -2
- data/lib/rubocop/cop/lint/symbol_conversion.rb +8 -3
- data/lib/rubocop/cop/lint/syntax.rb +6 -3
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +12 -5
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +23 -9
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -1
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +2 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -2
- data/lib/rubocop/cop/lint/useless_assignment.rb +94 -10
- data/lib/rubocop/cop/lint/useless_times.rb +2 -2
- data/lib/rubocop/cop/lint/void.rb +97 -11
- data/lib/rubocop/cop/metrics/abc_size.rb +3 -3
- data/lib/rubocop/cop/metrics/block_length.rb +1 -1
- data/lib/rubocop/cop/metrics/class_length.rb +8 -3
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -2
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +32 -4
- data/lib/rubocop/cop/migration/department_name.rb +2 -2
- data/lib/rubocop/cop/mixin/allowed_receivers.rb +34 -0
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +19 -11
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -0
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +14 -11
- data/lib/rubocop/cop/mixin/heredoc.rb +6 -2
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +4 -3
- data/lib/rubocop/cop/mixin/percent_literal.rb +1 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +6 -8
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/string_help.rb +4 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +13 -5
- data/lib/rubocop/cop/naming/constant_name.rb +2 -3
- data/lib/rubocop/cop/naming/file_name.rb +1 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +3 -1
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +26 -11
- data/lib/rubocop/cop/naming/predicate_name.rb +2 -2
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +11 -3
- data/lib/rubocop/cop/naming/variable_name.rb +6 -1
- data/lib/rubocop/cop/registry.rb +1 -1
- data/lib/rubocop/cop/security/open.rb +2 -2
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +2 -2
- data/lib/rubocop/cop/style/accessor_grouping.rb +6 -2
- data/lib/rubocop/cop/style/alias.rb +9 -8
- data/lib/rubocop/cop/style/arguments_forwarding.rb +411 -63
- data/lib/rubocop/cop/style/array_first_last.rb +64 -0
- data/lib/rubocop/cop/style/array_intersect.rb +13 -5
- data/lib/rubocop/cop/style/attr.rb +11 -1
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +21 -14
- data/lib/rubocop/cop/style/begin_block.rb +1 -2
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +2 -2
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +5 -4
- data/lib/rubocop/cop/style/case_like_if.rb +5 -5
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/class_check.rb +1 -0
- data/lib/rubocop/cop/style/class_equality_comparison.rb +24 -39
- data/lib/rubocop/cop/style/class_vars.rb +3 -3
- data/lib/rubocop/cop/style/collection_compact.rb +32 -12
- data/lib/rubocop/cop/style/collection_methods.rb +2 -0
- data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
- data/lib/rubocop/cop/style/combinable_loops.rb +36 -8
- data/lib/rubocop/cop/style/commented_keyword.rb +5 -2
- data/lib/rubocop/cop/style/concat_array_literals.rb +2 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +11 -10
- data/lib/rubocop/cop/style/copyright.rb +5 -2
- data/lib/rubocop/cop/style/date_time.rb +5 -4
- data/lib/rubocop/cop/style/dir.rb +1 -1
- data/lib/rubocop/cop/style/dir_empty.rb +8 -14
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +7 -7
- data/lib/rubocop/cop/style/each_with_object.rb +2 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +6 -1
- data/lib/rubocop/cop/style/empty_literal.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +8 -19
- data/lib/rubocop/cop/style/exact_regexp_match.rb +69 -0
- data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -2
- data/lib/rubocop/cop/style/file_read.rb +2 -2
- data/lib/rubocop/cop/style/for.rb +3 -1
- data/lib/rubocop/cop/style/format_string.rb +24 -3
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -1
- data/lib/rubocop/cop/style/guard_clause.rb +28 -0
- data/lib/rubocop/cop/style/hash_conversion.rb +10 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +106 -33
- data/lib/rubocop/cop/style/hash_except.rb +21 -9
- data/lib/rubocop/cop/style/hash_syntax.rb +6 -2
- 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 +34 -5
- data/lib/rubocop/cop/style/if_inside_else.rb +6 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +3 -0
- data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -2
- data/lib/rubocop/cop/style/inverse_methods.rb +14 -13
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +54 -8
- data/lib/rubocop/cop/style/lambda.rb +3 -3
- data/lib/rubocop/cop/style/lambda_call.rb +5 -0
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +8 -10
- data/lib/rubocop/cop/style/map_to_hash.rb +17 -7
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +24 -9
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +20 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/missing_respond_to_missing.rb +2 -2
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
- data/lib/rubocop/cop/style/multiline_method_signature.rb +10 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +6 -4
- data/lib/rubocop/cop/style/multiple_comparison.rb +14 -0
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +3 -11
- data/lib/rubocop/cop/style/next.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_literals.rb +1 -1
- data/lib/rubocop/cop/style/object_then.rb +5 -3
- data/lib/rubocop/cop/style/open_struct_use.rb +1 -1
- data/lib/rubocop/cop/style/operator_method_call.rb +8 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +3 -5
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -0
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/preferred_hash_methods.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +4 -1
- data/lib/rubocop/cop/style/redundant_argument.rb +10 -4
- data/lib/rubocop/cop/style/redundant_array_constructor.rb +77 -0
- data/lib/rubocop/cop/style/redundant_assignment.rb +10 -2
- data/lib/rubocop/cop/style/redundant_begin.rb +10 -2
- data/lib/rubocop/cop/style/redundant_conditional.rb +2 -10
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +39 -0
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +93 -5
- data/lib/rubocop/cop/style/redundant_each.rb +7 -4
- data/lib/rubocop/cop/style/redundant_exception.rb +32 -12
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +3 -3
- data/lib/rubocop/cop/style/redundant_filter_chain.rb +118 -0
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +32 -8
- data/lib/rubocop/cop/style/redundant_parentheses.rb +72 -23
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +100 -0
- data/lib/rubocop/cop/style/redundant_regexp_constructor.rb +46 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +2 -1
- data/lib/rubocop/cop/style/redundant_return.rb +14 -3
- data/lib/rubocop/cop/style/redundant_self.rb +17 -2
- data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +8 -1
- data/lib/rubocop/cop/style/redundant_sort.rb +10 -9
- data/lib/rubocop/cop/style/redundant_sort_by.rb +2 -2
- data/lib/rubocop/cop/style/redundant_string_escape.rb +3 -1
- data/lib/rubocop/cop/style/regexp_literal.rb +11 -2
- data/lib/rubocop/cop/style/require_order.rb +11 -5
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -3
- data/lib/rubocop/cop/style/return_nil.rb +6 -2
- data/lib/rubocop/cop/style/return_nil_in_predicate_method_definition.rb +95 -0
- data/lib/rubocop/cop/style/sample.rb +3 -4
- data/lib/rubocop/cop/style/select_by_regexp.rb +22 -11
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +20 -4
- data/lib/rubocop/cop/style/signal_exception.rb +1 -1
- data/lib/rubocop/cop/style/single_argument_dig.rb +7 -3
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +67 -0
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +76 -10
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +6 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -4
- data/lib/rubocop/cop/style/string_chars.rb +1 -0
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +30 -5
- data/lib/rubocop/cop/style/strip.rb +7 -4
- data/lib/rubocop/cop/style/super_with_args_parentheses.rb +35 -0
- data/lib/rubocop/cop/style/symbol_array.rb +35 -15
- data/lib/rubocop/cop/style/symbol_proc.rb +36 -0
- data/lib/rubocop/cop/style/unpack_first.rb +11 -14
- data/lib/rubocop/cop/style/yaml_file_read.rb +66 -0
- data/lib/rubocop/cop/style/yoda_condition.rb +4 -2
- data/lib/rubocop/cop/style/yoda_expression.rb +8 -7
- data/lib/rubocop/cop/team.rb +1 -1
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/utils/regexp_ranges.rb +113 -0
- data/lib/rubocop/cop/variable_force/assignment.rb +45 -4
- data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
- data/lib/rubocop/cop/variable_force.rb +1 -0
- data/lib/rubocop/cops_documentation_generator.rb +16 -4
- data/lib/rubocop/directive_comment.rb +10 -8
- data/lib/rubocop/ext/regexp_node.rb +9 -4
- data/lib/rubocop/ext/regexp_parser.rb +4 -1
- data/lib/rubocop/file_finder.rb +4 -7
- data/lib/rubocop/formatter/disabled_config_formatter.rb +17 -6
- data/lib/rubocop/formatter/html_formatter.rb +35 -14
- data/lib/rubocop/formatter/json_formatter.rb +0 -1
- data/lib/rubocop/formatter/junit_formatter.rb +1 -1
- data/lib/rubocop/formatter/offense_count_formatter.rb +12 -2
- data/lib/rubocop/formatter.rb +1 -1
- data/lib/rubocop/lsp/logger.rb +22 -0
- data/lib/rubocop/lsp/routes.rb +246 -0
- data/lib/rubocop/lsp/runtime.rb +99 -0
- data/lib/rubocop/lsp/server.rb +71 -0
- data/lib/rubocop/lsp/severity.rb +27 -0
- data/lib/rubocop/lsp.rb +29 -0
- data/lib/rubocop/magic_comment.rb +13 -11
- data/lib/rubocop/options.rb +22 -9
- data/lib/rubocop/path_util.rb +6 -2
- data/lib/rubocop/result_cache.rb +5 -2
- data/lib/rubocop/rspec/cop_helper.rb +8 -2
- data/lib/rubocop/rspec/expect_offense.rb +8 -8
- data/lib/rubocop/rspec/shared_contexts.rb +42 -18
- data/lib/rubocop/rspec/support.rb +2 -0
- data/lib/rubocop/runner.rb +15 -6
- data/lib/rubocop/server/cache.rb +1 -1
- data/lib/rubocop/server/client_command/exec.rb +3 -3
- data/lib/rubocop/server/server_command/exec.rb +0 -1
- data/lib/rubocop/string_interpreter.rb +3 -3
- data/lib/rubocop/target_finder.rb +91 -81
- data/lib/rubocop/target_ruby.rb +85 -78
- data/lib/rubocop/version.rb +27 -8
- data/lib/rubocop.rb +19 -0
- metadata +56 -14
- /data/lib/rubocop/formatter/{git_hub_actions_formatter.rb → github_actions_formatter.rb} +0 -0
@@ -44,9 +44,9 @@ module RuboCop
|
|
44
44
|
|
45
45
|
# @!method map_and_compact?(node)
|
46
46
|
def_node_matcher :map_and_compact?, <<~RUBY
|
47
|
-
(
|
47
|
+
(call
|
48
48
|
(block
|
49
|
-
(
|
49
|
+
(call _ :map)
|
50
50
|
(args
|
51
51
|
$(arg _))
|
52
52
|
{
|
@@ -85,6 +85,7 @@ module RuboCop
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
88
|
+
alias on_csend on_send
|
88
89
|
|
89
90
|
private
|
90
91
|
|
@@ -115,20 +116,17 @@ module RuboCop
|
|
115
116
|
def truthy_branch_for_guard?(node)
|
116
117
|
if_node = node.left_sibling
|
117
118
|
|
118
|
-
if if_node.if?
|
119
|
-
if_node.
|
120
|
-
|
121
|
-
if_node.if_branch.
|
119
|
+
if if_node.if?
|
120
|
+
if_node.if_branch.arguments.any?
|
121
|
+
else
|
122
|
+
if_node.if_branch.arguments.none?
|
122
123
|
end
|
123
124
|
end
|
124
125
|
|
125
126
|
def range(node)
|
126
|
-
buffer = node.source_range.source_buffer
|
127
127
|
map_node = node.receiver.send_node
|
128
|
-
begin_pos = map_node.loc.selector.begin_pos
|
129
|
-
end_pos = node.source_range.end_pos
|
130
128
|
|
131
|
-
|
129
|
+
map_node.loc.selector.join(node.source_range.end)
|
132
130
|
end
|
133
131
|
end
|
134
132
|
end
|
@@ -34,21 +34,25 @@ module RuboCop
|
|
34
34
|
|
35
35
|
minimum_target_ruby_version 2.6
|
36
36
|
|
37
|
-
MSG = 'Pass a block to `to_h` instead of calling `%<method>s
|
37
|
+
MSG = 'Pass a block to `to_h` instead of calling `%<method>s%<dot>sto_h`.'
|
38
38
|
RESTRICT_ON_SEND = %i[to_h].freeze
|
39
39
|
|
40
|
-
# @!method map_to_h
|
41
|
-
def_node_matcher :map_to_h
|
40
|
+
# @!method map_to_h(node)
|
41
|
+
def_node_matcher :map_to_h, <<~PATTERN
|
42
42
|
{
|
43
|
-
$(
|
44
|
-
$(
|
43
|
+
$(call ({block numblock} $(call _ {:map :collect}) ...) :to_h)
|
44
|
+
$(call $(call _ {:map :collect} (block_pass sym)) :to_h)
|
45
45
|
}
|
46
46
|
PATTERN
|
47
47
|
|
48
|
+
def self.autocorrect_incompatible_with
|
49
|
+
[Layout::SingleLineBlockChain]
|
50
|
+
end
|
51
|
+
|
48
52
|
def on_send(node)
|
49
|
-
return unless (to_h_node, map_node = map_to_h
|
53
|
+
return unless (to_h_node, map_node = map_to_h(node))
|
50
54
|
|
51
|
-
message = format(MSG, method: map_node.loc.selector.source)
|
55
|
+
message = format(MSG, method: map_node.loc.selector.source, dot: to_h_node.loc.dot.source)
|
52
56
|
add_offense(map_node.loc.selector, message: message) do |corrector|
|
53
57
|
# If the `to_h` call already has a block, do not autocorrect.
|
54
58
|
next if to_h_node.block_node
|
@@ -56,15 +60,21 @@ module RuboCop
|
|
56
60
|
autocorrect(corrector, to_h_node, map_node)
|
57
61
|
end
|
58
62
|
end
|
63
|
+
alias on_csend on_send
|
59
64
|
|
60
65
|
private
|
61
66
|
|
67
|
+
# rubocop:disable Metrics/AbcSize
|
62
68
|
def autocorrect(corrector, to_h, map)
|
63
69
|
removal_range = range_between(to_h.loc.dot.begin_pos, to_h.loc.selector.end_pos)
|
64
70
|
|
65
71
|
corrector.remove(range_with_surrounding_space(removal_range, side: :left))
|
72
|
+
if (map_dot = map.loc.dot)
|
73
|
+
corrector.replace(map_dot, to_h.loc.dot.source)
|
74
|
+
end
|
66
75
|
corrector.replace(map.loc.selector, 'to_h')
|
67
76
|
end
|
77
|
+
# rubocop:enable Metrics/AbcSize
|
68
78
|
end
|
69
79
|
end
|
70
80
|
end
|
@@ -86,6 +86,7 @@ module RuboCop
|
|
86
86
|
|
87
87
|
def legitimate_call_with_parentheses?(node) # rubocop:disable Metrics/PerceivedComplexity
|
88
88
|
call_in_literals?(node) ||
|
89
|
+
node.parent&.when_type? ||
|
89
90
|
call_with_ambiguous_arguments?(node) ||
|
90
91
|
call_in_logical_operators?(node) ||
|
91
92
|
call_in_optional_arguments?(node) ||
|
@@ -98,7 +99,7 @@ module RuboCop
|
|
98
99
|
|
99
100
|
def call_in_literals?(node)
|
100
101
|
parent = node.parent&.block_type? ? node.parent.parent : node.parent
|
101
|
-
return unless parent
|
102
|
+
return false unless parent
|
102
103
|
|
103
104
|
parent.pair_type? ||
|
104
105
|
parent.array_type? ||
|
@@ -109,7 +110,7 @@ module RuboCop
|
|
109
110
|
|
110
111
|
def call_in_logical_operators?(node)
|
111
112
|
parent = node.parent&.block_type? ? node.parent.parent : node.parent
|
112
|
-
return unless parent
|
113
|
+
return false unless parent
|
113
114
|
|
114
115
|
logical_operator?(parent) ||
|
115
116
|
(parent.send_type? &&
|
@@ -124,25 +125,39 @@ module RuboCop
|
|
124
125
|
node.parent&.class_type? && node.parent&.single_line?
|
125
126
|
end
|
126
127
|
|
127
|
-
def call_with_ambiguous_arguments?(node)
|
128
|
+
def call_with_ambiguous_arguments?(node) # rubocop:disable Metrics/PerceivedComplexity
|
128
129
|
call_with_braced_block?(node) ||
|
130
|
+
call_in_argument_with_block?(node) ||
|
129
131
|
call_as_argument_or_chain?(node) ||
|
132
|
+
call_in_match_pattern?(node) ||
|
130
133
|
hash_literal_in_arguments?(node) ||
|
131
134
|
node.descendants.any? do |n|
|
132
|
-
n.forwarded_args_type? ||
|
133
|
-
|
135
|
+
n.forwarded_args_type? || n.block_type? || n.numblock_type? ||
|
136
|
+
ambiguous_literal?(n) || logical_operator?(n)
|
134
137
|
end
|
135
138
|
end
|
136
139
|
|
137
140
|
def call_with_braced_block?(node)
|
138
|
-
(node.
|
139
|
-
|
141
|
+
(node.call_type? || node.super_type?) && node.block_node&.braces?
|
142
|
+
end
|
143
|
+
|
144
|
+
def call_in_argument_with_block?(node)
|
145
|
+
parent = node.parent&.block_type? && node.parent&.parent
|
146
|
+
return false unless parent
|
147
|
+
|
148
|
+
parent.call_type? || parent.super_type? || parent.yield_type?
|
140
149
|
end
|
141
150
|
|
142
151
|
def call_as_argument_or_chain?(node)
|
143
152
|
node.parent &&
|
144
|
-
(
|
145
|
-
|
153
|
+
(node.parent.call_type? || node.parent.super_type? || node.parent.yield_type?) &&
|
154
|
+
!assigned_before?(node.parent, node)
|
155
|
+
end
|
156
|
+
|
157
|
+
def call_in_match_pattern?(node)
|
158
|
+
return false unless (parent = node.parent)
|
159
|
+
|
160
|
+
parent.match_pattern_type? || parent.match_pattern_p_type?
|
146
161
|
end
|
147
162
|
|
148
163
|
def hash_literal_in_arguments?(node)
|
@@ -218,15 +218,13 @@ module RuboCop
|
|
218
218
|
send(style, node) # call require_parentheses or omit_parentheses
|
219
219
|
end
|
220
220
|
alias on_csend on_send
|
221
|
-
alias on_super on_send
|
222
221
|
alias on_yield on_send
|
223
222
|
|
224
223
|
private
|
225
224
|
|
226
225
|
def args_begin(node)
|
227
226
|
loc = node.loc
|
228
|
-
selector =
|
229
|
-
node.super_type? || node.yield_type? ? loc.keyword : loc.selector
|
227
|
+
selector = node.yield_type? ? loc.keyword : loc.selector
|
230
228
|
|
231
229
|
resize_by = args_parenthesized?(node) ? 2 : 1
|
232
230
|
selector.end.resize(resize_by)
|
@@ -239,7 +237,7 @@ module RuboCop
|
|
239
237
|
def args_parenthesized?(node)
|
240
238
|
return false unless node.arguments.one?
|
241
239
|
|
242
|
-
first_node = node.
|
240
|
+
first_node = node.first_argument
|
243
241
|
first_node.begin_type? && first_node.parenthesized_call?
|
244
242
|
end
|
245
243
|
end
|
@@ -8,6 +8,9 @@ module RuboCop
|
|
8
8
|
# This cop can be customized allowed methods with `AllowedMethods`.
|
9
9
|
# By default, there are no methods to allowed.
|
10
10
|
#
|
11
|
+
# NOTE: This cop allows the use of `it()` without arguments in blocks,
|
12
|
+
# as in `0.times { it() }`, following `Lint/ItWithoutArgumentsInBlock` cop.
|
13
|
+
#
|
11
14
|
# @example
|
12
15
|
# # bad
|
13
16
|
# object.some_method()
|
@@ -30,15 +33,18 @@ module RuboCop
|
|
30
33
|
|
31
34
|
MSG = 'Do not use parentheses for method calls with no arguments.'
|
32
35
|
|
36
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
33
37
|
def on_send(node)
|
34
38
|
return unless !node.arguments? && node.parenthesized?
|
35
39
|
return if ineligible_node?(node)
|
36
40
|
return if default_argument?(node)
|
37
41
|
return if allowed_method_name?(node.method_name)
|
38
42
|
return if same_name_assignment?(node)
|
43
|
+
return if parenthesized_it_method_in_block?(node)
|
39
44
|
|
40
45
|
register_offense(node)
|
41
46
|
end
|
47
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
42
48
|
|
43
49
|
private
|
44
50
|
|
@@ -71,6 +77,20 @@ module RuboCop
|
|
71
77
|
end
|
72
78
|
end
|
73
79
|
|
80
|
+
# Respects `Lint/ItWithoutArgumentsInBlock` cop and the following Ruby 3.3's warning:
|
81
|
+
#
|
82
|
+
# $ ruby -e '0.times { begin; it; end }'
|
83
|
+
# -e:1: warning: `it` calls without arguments will refer to the first block param in
|
84
|
+
# Ruby 3.4; use it() or self.it
|
85
|
+
#
|
86
|
+
def parenthesized_it_method_in_block?(node)
|
87
|
+
return false unless node.method?(:it)
|
88
|
+
return false unless (block_node = node.each_ancestor(:block).first)
|
89
|
+
return false unless block_node.arguments.empty_and_without_delimiters?
|
90
|
+
|
91
|
+
!node.receiver && node.arguments.empty? && !node.block_literal?
|
92
|
+
end
|
93
|
+
|
74
94
|
def any_assignment?(node)
|
75
95
|
node.each_ancestor(*AST::Node::ASSIGNMENTS).any? do |asgn_node|
|
76
96
|
# `obj.method = value` parses as (send ... :method= ...), and will
|
@@ -170,7 +170,7 @@ module RuboCop
|
|
170
170
|
return true if node.arguments.any? do |arg|
|
171
171
|
arg.forward_arg_type? || arg.restarg_type? || arg.kwrestarg_type?
|
172
172
|
end
|
173
|
-
return false unless (last_argument = node.
|
173
|
+
return false unless (last_argument = node.last_argument)
|
174
174
|
|
175
175
|
last_argument.blockarg_type? && last_argument.name.nil?
|
176
176
|
end
|
@@ -40,7 +40,7 @@ module RuboCop
|
|
40
40
|
def on_class(node)
|
41
41
|
begin_node = node.child_nodes.find(&:begin_type?) || node
|
42
42
|
begin_node.each_child_node(:send).select(&:macro?).each do |macro|
|
43
|
-
next
|
43
|
+
next if !MIXIN_METHODS.include?(macro.method_name) || macro.arguments.empty?
|
44
44
|
|
45
45
|
check(macro)
|
46
46
|
end
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
MSG = 'Avoid multi-line chains of blocks.'
|
29
29
|
|
30
30
|
def on_block(node)
|
31
|
-
node.send_node.each_node(:send) do |send_node|
|
31
|
+
node.send_node.each_node(:send, :csend) do |send_node|
|
32
32
|
receiver = send_node.receiver
|
33
33
|
|
34
34
|
next unless (receiver&.block_type? || receiver&.numblock_type?) && receiver&.multiline?
|
@@ -38,6 +38,7 @@ module RuboCop
|
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
|
+
# rubocop:disable Metrics/AbcSize
|
41
42
|
def autocorrect(corrector, node, begin_of_arguments)
|
42
43
|
arguments = node.arguments
|
43
44
|
joined_arguments = arguments.map(&:source).join(', ')
|
@@ -49,9 +50,17 @@ module RuboCop
|
|
49
50
|
corrector.remove(range_by_whole_lines(arguments.loc.end, include_final_newline: true))
|
50
51
|
end
|
51
52
|
|
52
|
-
|
53
|
+
arguments_range = arguments_range(node)
|
54
|
+
# If the method name isn't on the same line as def, move it directly after def
|
55
|
+
if arguments_range.first_line != opening_line(node)
|
56
|
+
corrector.remove(node.loc.name)
|
57
|
+
corrector.insert_after(node.loc.keyword, " #{node.loc.name.source}")
|
58
|
+
end
|
59
|
+
|
60
|
+
corrector.remove(arguments_range)
|
53
61
|
corrector.insert_after(begin_of_arguments, joined_arguments)
|
54
62
|
end
|
63
|
+
# rubocop:enable Metrics/AbcSize
|
55
64
|
|
56
65
|
def last_line_source_of_arguments(arguments)
|
57
66
|
processed_source[arguments.last_line - 1].strip
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
|
40
40
|
MSG_IF = 'Avoid multi-line ternary operators, use `if` or `unless` instead.'
|
41
41
|
MSG_SINGLE_LINE = 'Avoid multi-line ternary operators, use single-line instead.'
|
42
|
-
SINGLE_LINE_TYPES = %i[return break next send].freeze
|
42
|
+
SINGLE_LINE_TYPES = %i[return break next send csend].freeze
|
43
43
|
|
44
44
|
def on_if(node)
|
45
45
|
return unless offense?(node)
|
@@ -47,19 +47,21 @@ module RuboCop
|
|
47
47
|
message = enforce_single_line_ternary_operator?(node) ? MSG_SINGLE_LINE : MSG_IF
|
48
48
|
|
49
49
|
add_offense(node, message: message) do |corrector|
|
50
|
+
next if part_of_ignored_node?(node)
|
51
|
+
|
50
52
|
autocorrect(corrector, node)
|
53
|
+
|
54
|
+
ignore_node(node)
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
54
58
|
private
|
55
59
|
|
56
60
|
def offense?(node)
|
57
|
-
node.ternary? && node.multiline?
|
61
|
+
node.ternary? && node.multiline? && node.source != replacement(node)
|
58
62
|
end
|
59
63
|
|
60
64
|
def autocorrect(corrector, node)
|
61
|
-
return unless offense?(node)
|
62
|
-
|
63
65
|
corrector.replace(node, replacement(node))
|
64
66
|
return unless (parent = node.parent)
|
65
67
|
return unless (comments_in_condition = comments_in_condition(node))
|
@@ -40,6 +40,15 @@ module RuboCop
|
|
40
40
|
#
|
41
41
|
# # good
|
42
42
|
# foo if [b.lightweight, b.heavyweight].include?(a)
|
43
|
+
#
|
44
|
+
# @example ComparisonsThreshold: 2 (default)
|
45
|
+
# # bad
|
46
|
+
# foo if a == 'a' || a == 'b'
|
47
|
+
#
|
48
|
+
# @example ComparisonsThreshold: 3
|
49
|
+
# # good
|
50
|
+
# foo if a == 'a' || a == 'b'
|
51
|
+
#
|
43
52
|
class MultipleComparison < Base
|
44
53
|
extend AutoCorrector
|
45
54
|
|
@@ -58,6 +67,7 @@ module RuboCop
|
|
58
67
|
return unless node == root_of_or_node
|
59
68
|
return unless nested_variable_comparison?(root_of_or_node)
|
60
69
|
return if @allowed_method_comparison
|
70
|
+
return if @compared_elements.size < comparisons_threshold
|
61
71
|
|
62
72
|
add_offense(node) do |corrector|
|
63
73
|
elements = @compared_elements.join(', ')
|
@@ -151,6 +161,10 @@ module RuboCop
|
|
151
161
|
def allow_method_comparison?
|
152
162
|
cop_config.fetch('AllowMethodComparison', true)
|
153
163
|
end
|
164
|
+
|
165
|
+
def comparisons_threshold
|
166
|
+
cop_config.fetch('ComparisonsThreshold', 2)
|
167
|
+
end
|
154
168
|
end
|
155
169
|
end
|
156
170
|
end
|
@@ -27,24 +27,16 @@ module RuboCop
|
|
27
27
|
|
28
28
|
node.each_descendant(:if).select(&:ternary?).each do |nested_ternary|
|
29
29
|
add_offense(nested_ternary) do |corrector|
|
30
|
-
|
31
|
-
next if part_of_ignored_node?(if_node)
|
30
|
+
next if part_of_ignored_node?(node)
|
32
31
|
|
33
|
-
autocorrect(corrector,
|
34
|
-
ignore_node(
|
32
|
+
autocorrect(corrector, node)
|
33
|
+
ignore_node(node)
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
38
|
private
|
40
39
|
|
41
|
-
def if_node(node)
|
42
|
-
node = node.parent
|
43
|
-
return node if node.if_type?
|
44
|
-
|
45
|
-
if_node(node)
|
46
|
-
end
|
47
|
-
|
48
40
|
def autocorrect(corrector, if_node)
|
49
41
|
replace_loc_and_whitespace(corrector, if_node.loc.question, "\n")
|
50
42
|
replace_loc_and_whitespace(corrector, if_node.loc.colon, "\nelse\n")
|
@@ -46,15 +46,17 @@ module RuboCop
|
|
46
46
|
private
|
47
47
|
|
48
48
|
def check_method_node(node)
|
49
|
-
return unless preferred_method(node)
|
49
|
+
return unless preferred_method?(node)
|
50
50
|
|
51
51
|
message = message(node)
|
52
52
|
add_offense(node.loc.selector, message: message) do |corrector|
|
53
|
-
|
53
|
+
prefer = style == :then && node.receiver.nil? ? 'self.then' : style
|
54
|
+
|
55
|
+
corrector.replace(node.loc.selector, prefer)
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
|
-
def preferred_method(node)
|
59
|
+
def preferred_method?(node)
|
58
60
|
case style
|
59
61
|
when :then
|
60
62
|
node.method?(:yield_self)
|
@@ -45,7 +45,7 @@ module RuboCop
|
|
45
45
|
MSG = 'Avoid using `OpenStruct`; use `Struct`, `Hash`, a class or test doubles instead.'
|
46
46
|
|
47
47
|
# @!method uses_open_struct?(node)
|
48
|
-
def_node_matcher :uses_open_struct?,
|
48
|
+
def_node_matcher :uses_open_struct?, <<~PATTERN
|
49
49
|
(const {nil? (cbase)} :OpenStruct)
|
50
50
|
PATTERN
|
51
51
|
|
@@ -4,8 +4,8 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
6
|
# Checks for redundant dot before operator method call.
|
7
|
-
# The target operator methods are `|`, `^`, `&`,
|
8
|
-
#
|
7
|
+
# The target operator methods are `|`, `^`, `&`, ``<=>``, `==`, `===`, `=~`, `>`, `>=`, `<`,
|
8
|
+
# ``<=``, `<<`, `>>`, `+`, `-`, `*`, `/`, `%`, `**`, `~`, `!`, `!=`, and `!~`.
|
9
9
|
#
|
10
10
|
# @example
|
11
11
|
#
|
@@ -23,6 +23,7 @@ module RuboCop
|
|
23
23
|
MSG = 'Redundant dot detected.'
|
24
24
|
RESTRICT_ON_SEND = %i[| ^ & <=> == === =~ > >= < <= << >> + - * / % ** ~ ! != !~].freeze
|
25
25
|
|
26
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
26
27
|
def on_send(node)
|
27
28
|
return unless (dot = node.loc.dot)
|
28
29
|
return if node.receiver.const_type? || !node.arguments.one?
|
@@ -33,8 +34,12 @@ module RuboCop
|
|
33
34
|
add_offense(dot) do |corrector|
|
34
35
|
wrap_in_parentheses_if_chained(corrector, node)
|
35
36
|
corrector.replace(dot, ' ')
|
37
|
+
|
38
|
+
selector = node.loc.selector
|
39
|
+
corrector.insert_after(selector, ' ') if selector.end_pos == rhs.source_range.begin_pos
|
36
40
|
end
|
37
41
|
end
|
42
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
38
43
|
|
39
44
|
private
|
40
45
|
|
@@ -54,6 +59,7 @@ module RuboCop
|
|
54
59
|
|
55
60
|
def wrap_in_parentheses_if_chained(corrector, node)
|
56
61
|
return unless node.parent&.call_type?
|
62
|
+
return if node.parent.first_argument == node
|
57
63
|
|
58
64
|
operator = node.loc.selector
|
59
65
|
|
@@ -142,8 +142,8 @@ module RuboCop
|
|
142
142
|
@assignments = assignments
|
143
143
|
end
|
144
144
|
|
145
|
-
def tsort_each_node(
|
146
|
-
@assignments.each(
|
145
|
+
def tsort_each_node(...)
|
146
|
+
@assignments.each(...)
|
147
147
|
end
|
148
148
|
|
149
149
|
def tsort_each_child(assignment)
|
@@ -289,9 +289,7 @@ module RuboCop
|
|
289
289
|
private
|
290
290
|
|
291
291
|
def modifier_range(node)
|
292
|
-
|
293
|
-
node.loc.keyword.begin_pos,
|
294
|
-
node.source_range.end_pos)
|
292
|
+
node.loc.keyword.join(node.source_range.end)
|
295
293
|
end
|
296
294
|
end
|
297
295
|
end
|
@@ -81,6 +81,7 @@ module RuboCop
|
|
81
81
|
cond = node.condition
|
82
82
|
|
83
83
|
control_op_condition(cond) do |first_child, rest_children|
|
84
|
+
return if require_parentheses?(node, first_child)
|
84
85
|
return if semicolon_separated_expressions?(first_child, rest_children)
|
85
86
|
return if modifier_op?(first_child)
|
86
87
|
return if parens_allowed?(cond)
|
@@ -92,6 +93,13 @@ module RuboCop
|
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
96
|
+
def require_parentheses?(node, condition_body)
|
97
|
+
return false if !node.while_type? && !node.until_type?
|
98
|
+
return false if !condition_body.block_type? && !condition_body.numblock_type?
|
99
|
+
|
100
|
+
condition_body.send_node.block_literal? && condition_body.keywords?
|
101
|
+
end
|
102
|
+
|
95
103
|
def semicolon_separated_expressions?(first_exp, rest_exps)
|
96
104
|
return false unless (second_exp = rest_exps.first)
|
97
105
|
|
@@ -93,7 +93,7 @@ module RuboCop
|
|
93
93
|
def contains_delimiter?(node, delimiters)
|
94
94
|
delimiters_regexp = Regexp.union(delimiters)
|
95
95
|
|
96
|
-
node.children.
|
96
|
+
node.children.filter_map { |n| string_source(n) }.any?(delimiters_regexp)
|
97
97
|
end
|
98
98
|
|
99
99
|
def string_source(node)
|
@@ -16,6 +16,9 @@ module RuboCop
|
|
16
16
|
# The exploded style has an `AllowedCompactTypes` configuration
|
17
17
|
# option that takes an Array of exception name Strings.
|
18
18
|
#
|
19
|
+
# @safety
|
20
|
+
# This cop is unsafe because `raise Foo` calls `Foo.exception`, not `Foo.new`.
|
21
|
+
#
|
19
22
|
# @example EnforcedStyle: exploded (default)
|
20
23
|
# # bad
|
21
24
|
# raise StandardError.new('message')
|
@@ -77,7 +80,7 @@ module RuboCop
|
|
77
80
|
|
78
81
|
def correction_exploded_to_compact(node)
|
79
82
|
exception_node, *message_nodes = *node.arguments
|
80
|
-
return
|
83
|
+
return if message_nodes.size > 1
|
81
84
|
|
82
85
|
argument = message_nodes.first.source
|
83
86
|
exception_class = exception_node.receiver&.source || exception_node.source
|