rubocop 1.42.0 → 1.64.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 -6
- data/assets/output.css.erb +159 -0
- data/assets/output.html.erb +1 -160
- data/config/default.yml +342 -64
- data/config/obsoletion.yml +5 -0
- data/lib/rubocop/cached_data.rb +11 -3
- data/lib/rubocop/cli/command/auto_generate_config.rb +27 -6
- data/lib/rubocop/cli/command/execute_runner.rb +7 -2
- data/lib/rubocop/cli/command/lsp.rb +19 -0
- data/lib/rubocop/cli/command/show_docs_url.rb +2 -2
- data/lib/rubocop/cli.rb +68 -10
- data/lib/rubocop/comment_config.rb +19 -0
- data/lib/rubocop/config.rb +43 -15
- data/lib/rubocop/config_finder.rb +14 -4
- data/lib/rubocop/config_loader.rb +20 -24
- 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 +37 -14
- data/lib/rubocop/cop/base.rb +97 -28
- 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 +4 -4
- data/lib/rubocop/cop/bundler/gem_version.rb +5 -7
- data/lib/rubocop/cop/bundler/ordered_gems.rb +9 -1
- data/lib/rubocop/cop/commissioner.rb +8 -2
- data/lib/rubocop/cop/cop.rb +25 -5
- data/lib/rubocop/cop/corrector.rb +11 -3
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +4 -8
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +6 -14
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +7 -4
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +2 -7
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/documentation.rb +16 -6
- data/lib/rubocop/cop/exclude_limit.rb +1 -1
- data/lib/rubocop/cop/force.rb +12 -0
- data/lib/rubocop/cop/gemspec/dependency_version.rb +6 -8
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +3 -3
- data/lib/rubocop/cop/gemspec/development_dependencies.rb +107 -0
- 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 +37 -13
- data/lib/rubocop/cop/internal_affairs/example_description.rb +46 -24
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +3 -3
- data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/location_expression.rb +37 -0
- 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 +128 -34
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb +42 -0
- data/lib/rubocop/cop/internal_affairs/redundant_expect_offense_arguments.rb +34 -0
- data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +11 -3
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb +11 -2
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +66 -0
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -0
- data/lib/rubocop/cop/internal_affairs.rb +5 -0
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/block_end_newline.rb +7 -15
- data/lib/rubocop/cop/layout/class_structure.rb +15 -19
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +2 -3
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +2 -6
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +1 -5
- data/lib/rubocop/cop/layout/empty_comment.rb +6 -4
- 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 +28 -5
- data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -0
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +2 -0
- data/lib/rubocop/cop/layout/end_alignment.rb +23 -3
- data/lib/rubocop/cop/layout/extra_spacing.rb +3 -4
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +8 -3
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +24 -7
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +25 -34
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +7 -19
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +42 -52
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +38 -55
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +12 -6
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +12 -12
- 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/initial_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +2 -2
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +18 -12
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +12 -8
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +2 -0
- data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +8 -27
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +7 -26
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +4 -21
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +18 -3
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +6 -30
- data/lib/rubocop/cop/layout/redundant_line_break.rb +33 -11
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +6 -6
- 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_keyword.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_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +11 -13
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +3 -1
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_parens.rb +3 -3
- data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_range_literal.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +4 -4
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +6 -6
- data/lib/rubocop/cop/layout/trailing_empty_lines.rb +5 -0
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +13 -1
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +4 -0
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +6 -6
- 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/constant_resolution.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +49 -26
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +62 -112
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_hash_key.rb +2 -1
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +122 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -3
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +47 -22
- data/lib/rubocop/cop/lint/else_layout.rb +3 -7
- data/lib/rubocop/cop/lint/empty_block.rb +2 -2
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +6 -4
- data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +27 -21
- data/lib/rubocop/cop/lint/float_comparison.rb +10 -0
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +14 -7
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +2 -1
- data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +16 -18
- data/lib/rubocop/cop/lint/identity_comparison.rb +0 -1
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +5 -3
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
- 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 +47 -5
- data/lib/rubocop/cop/lint/missing_super.rb +63 -5
- data/lib/rubocop/cop/lint/mixed_case_range.rb +116 -0
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +4 -9
- 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/or_assignment_to_constant.rb +2 -0
- data/lib/rubocop/cop/lint/ordered_magic_comments.rb +0 -1
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +8 -12
- data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +11 -5
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +5 -5
- data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +130 -0
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +21 -2
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +72 -8
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +35 -15
- data/lib/rubocop/cop/lint/redundant_with_index.rb +7 -3
- data/lib/rubocop/cop/lint/redundant_with_object.rb +3 -3
- data/lib/rubocop/cop/lint/refinement_import_methods.rb +2 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +2 -4
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +14 -8
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +1 -1
- 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 +6 -12
- 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 +10 -3
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +23 -6
- 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/unreachable_code.rb +4 -2
- data/lib/rubocop/cop/lint/unreachable_loop.rb +11 -5
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +12 -9
- data/lib/rubocop/cop/lint/useless_assignment.rb +94 -10
- data/lib/rubocop/cop/lint/useless_method_definition.rb +12 -4
- data/lib/rubocop/cop/lint/useless_rescue.rb +89 -0
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +9 -1
- data/lib/rubocop/cop/lint/useless_times.rb +3 -3
- data/lib/rubocop/cop/lint/void.rb +119 -20
- data/lib/rubocop/cop/metrics/abc_size.rb +3 -3
- data/lib/rubocop/cop/metrics/block_length.rb +2 -2
- data/lib/rubocop/cop/metrics/block_nesting.rb +2 -2
- data/lib/rubocop/cop/metrics/class_length.rb +8 -2
- data/lib/rubocop/cop/metrics/collection_literal_length.rb +76 -0
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/metrics/parameter_lists.rb +27 -0
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +3 -7
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +38 -10
- data/lib/rubocop/cop/migration/department_name.rb +3 -3
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/allowed_methods.rb +3 -1
- data/lib/rubocop/cop/mixin/allowed_receivers.rb +34 -0
- data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -1
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/code_length.rb +12 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +21 -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/documentation_comment.rb +1 -1
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +78 -29
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +3 -3
- data/lib/rubocop/cop/mixin/heredoc.rb +6 -2
- data/lib/rubocop/cop/mixin/line_length_help.rb +3 -1
- data/lib/rubocop/cop/mixin/method_complexity.rb +15 -6
- data/lib/rubocop/cop/mixin/min_branches_count.rb +40 -0
- data/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb +0 -3
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +4 -3
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
- 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/range_help.rb +1 -6
- data/lib/rubocop/cop/mixin/safe_assignment.rb +1 -1
- 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/statement_modifier.rb +4 -3
- data/lib/rubocop/cop/mixin/string_help.rb +4 -2
- data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -3
- data/lib/rubocop/cop/mixin/trailing_comma.rb +3 -3
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +38 -7
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +2 -3
- data/lib/rubocop/cop/naming/file_name.rb +3 -3
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +1 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +3 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +24 -6
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +26 -11
- data/lib/rubocop/cop/naming/method_name.rb +3 -3
- data/lib/rubocop/cop/naming/predicate_name.rb +3 -3
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +12 -4
- data/lib/rubocop/cop/naming/variable_name.rb +6 -1
- data/lib/rubocop/cop/registry.rb +16 -9
- data/lib/rubocop/cop/security/compound_hash.rb +2 -2
- data/lib/rubocop/cop/security/open.rb +2 -2
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +78 -13
- data/lib/rubocop/cop/style/accessor_grouping.rb +44 -18
- data/lib/rubocop/cop/style/alias.rb +10 -8
- data/lib/rubocop/cop/style/arguments_forwarding.rb +414 -62
- data/lib/rubocop/cop/style/array_first_last.rb +64 -0
- data/lib/rubocop/cop/style/array_intersect.rb +14 -6
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
- 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 +3 -3
- data/lib/rubocop/cop/style/block_comments.rb +2 -2
- data/lib/rubocop/cop/style/block_delimiters.rb +22 -6
- data/lib/rubocop/cop/style/case_like_if.rb +25 -8
- data/lib/rubocop/cop/style/class_and_module_children.rb +5 -12
- data/lib/rubocop/cop/style/class_check.rb +1 -0
- data/lib/rubocop/cop/style/class_equality_comparison.rb +58 -40
- data/lib/rubocop/cop/style/class_vars.rb +3 -3
- data/lib/rubocop/cop/style/collection_compact.rb +37 -14
- 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/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +7 -4
- data/lib/rubocop/cop/style/comparable_clamp.rb +125 -0
- data/lib/rubocop/cop/style/concat_array_literals.rb +12 -3
- data/lib/rubocop/cop/style/conditional_assignment.rb +15 -20
- data/lib/rubocop/cop/style/copyright.rb +37 -24
- data/lib/rubocop/cop/style/data_inheritance.rb +75 -0
- 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 +54 -0
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +3 -3
- data/lib/rubocop/cop/style/documentation.rb +36 -30
- data/lib/rubocop/cop/style/documentation_method.rb +30 -4
- data/lib/rubocop/cop/style/double_negation.rb +2 -2
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +7 -7
- data/lib/rubocop/cop/style/each_with_object.rb +3 -3
- data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
- data/lib/rubocop/cop/style/empty_case_condition.rb +6 -1
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
- data/lib/rubocop/cop/style/empty_literal.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +14 -23
- data/lib/rubocop/cop/style/exact_regexp_match.rb +70 -0
- data/lib/rubocop/cop/style/explicit_block_argument.rb +3 -3
- data/lib/rubocop/cop/style/file_empty.rb +71 -0
- data/lib/rubocop/cop/style/file_read.rb +3 -3
- data/lib/rubocop/cop/style/file_write.rb +1 -1
- data/lib/rubocop/cop/style/for.rb +3 -1
- data/lib/rubocop/cop/style/format_string.rb +33 -12
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +4 -2
- data/lib/rubocop/cop/style/guard_clause.rb +29 -1
- data/lib/rubocop/cop/style/hash_conversion.rb +10 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +106 -21
- data/lib/rubocop/cop/style/hash_except.rb +25 -13
- data/lib/rubocop/cop/style/hash_like_case.rb +3 -9
- data/lib/rubocop/cop/style/hash_syntax.rb +29 -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 +34 -5
- data/lib/rubocop/cop/style/if_inside_else.rb +6 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +111 -15
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +7 -3
- data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -2
- data/lib/rubocop/cop/style/infinite_loop.rb +2 -5
- data/lib/rubocop/cop/style/inverse_methods.rb +14 -13
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +160 -0
- 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_into_array.rb +175 -0
- data/lib/rubocop/cop/style/map_to_hash.rb +20 -7
- data/lib/rubocop/cop/style/map_to_set.rb +5 -2
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +48 -28
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +46 -41
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +22 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/min_max.rb +3 -3
- data/lib/rubocop/cop/style/min_max_comparison.rb +11 -1
- data/lib/rubocop/cop/style/missing_else.rb +13 -1
- data/lib/rubocop/cop/style/missing_respond_to_missing.rb +2 -2
- data/lib/rubocop/cop/style/mixin_grouping.rb +5 -5
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +0 -4
- data/lib/rubocop/cop/style/multiline_memoization.rb +2 -2
- data/lib/rubocop/cop/style/multiline_method_signature.rb +17 -5
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +21 -4
- data/lib/rubocop/cop/style/multiple_comparison.rb +14 -0
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +13 -12
- 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/nil_lambda.rb +2 -2
- data/lib/rubocop/cop/style/numbered_parameters_limit.rb +11 -3
- 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/numeric_predicate.rb +10 -2
- data/lib/rubocop/cop/style/object_then.rb +5 -3
- data/lib/rubocop/cop/style/one_line_conditional.rb +4 -7
- data/lib/rubocop/cop/style/open_struct_use.rb +1 -1
- data/lib/rubocop/cop/style/operator_method_call.rb +24 -4
- data/lib/rubocop/cop/style/parallel_assignment.rb +32 -24
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -0
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -3
- data/lib/rubocop/cop/style/percent_q_literals.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 +33 -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_condition.rb +18 -3
- data/lib/rubocop/cop/style/redundant_conditional.rb +2 -14
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +39 -0
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +103 -9
- 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 +9 -7
- data/lib/rubocop/cop/style/redundant_filter_chain.rb +118 -0
- data/lib/rubocop/cop/style/redundant_heredoc_delimiter_quotes.rb +58 -0
- data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +200 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +73 -24
- data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +100 -0
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +7 -8
- data/lib/rubocop/cop/style/redundant_regexp_constructor.rb +46 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +13 -4
- 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 +13 -12
- data/lib/rubocop/cop/style/redundant_sort_by.rb +2 -2
- data/lib/rubocop/cop/style/redundant_string_escape.rb +6 -5
- data/lib/rubocop/cop/style/regexp_literal.rb +11 -2
- data/lib/rubocop/cop/style/require_order.rb +12 -15
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -3
- data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -2
- 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/safe_navigation.rb +2 -2
- 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 +3 -3
- data/lib/rubocop/cop/style/semicolon.rb +43 -5
- data/lib/rubocop/cop/style/send.rb +4 -4
- data/lib/rubocop/cop/style/send_with_literal_method_name.rb +90 -0
- 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 +77 -11
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +9 -5
- data/lib/rubocop/cop/style/special_global_vars.rb +4 -6
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/string_chars.rb +1 -0
- data/lib/rubocop/cop/style/string_hash_keys.rb +4 -1
- 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/struct_inheritance.rb +1 -1
- data/lib/rubocop/cop/style/super_arguments.rb +156 -0
- 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 +68 -5
- data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -1
- data/lib/rubocop/cop/style/trailing_body_on_class.rb +1 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_logical_operators.rb +1 -0
- data/lib/rubocop/cop/style/unpack_first.rb +11 -14
- data/lib/rubocop/cop/style/word_array.rb +18 -6
- data/lib/rubocop/cop/style/yaml_file_read.rb +66 -0
- data/lib/rubocop/cop/style/yoda_condition.rb +17 -8
- data/lib/rubocop/cop/style/yoda_expression.rb +26 -9
- data/lib/rubocop/cop/style/zero_length_predicate.rb +9 -5
- data/lib/rubocop/cop/team.rb +36 -23
- data/lib/rubocop/cop/util.rb +14 -5
- 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/scope.rb +3 -3
- data/lib/rubocop/cop/variable_force/variable.rb +5 -3
- data/lib/rubocop/cop/variable_force/variable_table.rb +5 -3
- data/lib/rubocop/cop/variable_force.rb +2 -1
- data/lib/rubocop/cops_documentation_generator.rb +26 -7
- data/lib/rubocop/directive_comment.rb +13 -11
- data/lib/rubocop/ext/comment.rb +18 -0
- data/lib/rubocop/ext/regexp_node.rb +10 -5
- data/lib/rubocop/ext/regexp_parser.rb +5 -2
- data/lib/rubocop/file_finder.rb +4 -7
- data/lib/rubocop/formatter/clang_style_formatter.rb +3 -7
- data/lib/rubocop/formatter/disabled_config_formatter.rb +23 -8
- data/lib/rubocop/formatter/formatter_set.rb +7 -1
- 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 +4 -1
- data/lib/rubocop/formatter/offense_count_formatter.rb +12 -2
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
- data/lib/rubocop/formatter/tap_formatter.rb +3 -7
- data/lib/rubocop/formatter.rb +1 -2
- data/lib/rubocop/lockfile.rb +56 -7
- data/lib/rubocop/lsp/logger.rb +22 -0
- data/lib/rubocop/lsp/routes.rb +243 -0
- data/lib/rubocop/lsp/runtime.rb +99 -0
- data/lib/rubocop/lsp/server.rb +73 -0
- data/lib/rubocop/lsp/severity.rb +27 -0
- data/lib/rubocop/lsp.rb +36 -0
- data/lib/rubocop/magic_comment.rb +13 -11
- data/lib/rubocop/options.rb +49 -12
- data/lib/rubocop/path_util.rb +17 -8
- data/lib/rubocop/rake_task.rb +1 -1
- data/lib/rubocop/result_cache.rb +6 -3
- data/lib/rubocop/rspec/cop_helper.rb +9 -3
- data/lib/rubocop/rspec/expect_offense.rb +18 -8
- data/lib/rubocop/rspec/shared_contexts.rb +59 -19
- data/lib/rubocop/rspec/support.rb +3 -0
- data/lib/rubocop/runner.rb +59 -10
- data/lib/rubocop/server/cache.rb +11 -4
- data/lib/rubocop/server/cli.rb +37 -18
- data/lib/rubocop/server/client_command/exec.rb +4 -4
- data/lib/rubocop/server/client_command/start.rb +6 -1
- data/lib/rubocop/server/core.rb +24 -9
- data/lib/rubocop/server/helper.rb +1 -1
- data/lib/rubocop/server/server_command/exec.rb +1 -2
- 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 +35 -0
- metadata +76 -35
- /data/lib/rubocop/formatter/{git_hub_actions_formatter.rb → github_actions_formatter.rb} +0 -0
@@ -31,9 +31,17 @@ module RuboCop
|
|
31
31
|
(send nil? :let
|
32
32
|
(sym :config))
|
33
33
|
(args)
|
34
|
-
|
35
|
-
(
|
36
|
-
(const
|
34
|
+
{
|
35
|
+
(send
|
36
|
+
(const
|
37
|
+
(const nil? :RuboCop) :Config) :new)
|
38
|
+
(send
|
39
|
+
(const
|
40
|
+
(const nil? :RuboCop) :Config) :new
|
41
|
+
(hash (pair (send (send (send nil? :described_class) :badge) :to_s)
|
42
|
+
(send nil? :cop_config))))
|
43
|
+
}
|
44
|
+
)
|
37
45
|
PATTERN
|
38
46
|
|
39
47
|
def on_block(node)
|
@@ -14,6 +14,12 @@ module RuboCop
|
|
14
14
|
# node.method_name
|
15
15
|
#
|
16
16
|
# # bad
|
17
|
+
# node.send_node.method?(:method_name)
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
# node.method?(:method_name)
|
21
|
+
#
|
22
|
+
# # bad
|
17
23
|
# node.send_node.receiver
|
18
24
|
#
|
19
25
|
# # good
|
@@ -24,11 +30,14 @@ module RuboCop
|
|
24
30
|
extend AutoCorrector
|
25
31
|
|
26
32
|
MSG = 'Remove the redundant `send_node`.'
|
27
|
-
RESTRICT_ON_SEND = %i[method_name receiver].freeze
|
33
|
+
RESTRICT_ON_SEND = %i[method_name method? receiver].freeze
|
28
34
|
|
29
35
|
# @!method dispatch_method(node)
|
30
36
|
def_node_matcher :dispatch_method, <<~PATTERN
|
31
|
-
|
37
|
+
{
|
38
|
+
(send $(send _ :send_node) {:method_name :receiver})
|
39
|
+
(send $(send _ :send_node) :method? _)
|
40
|
+
}
|
32
41
|
PATTERN
|
33
42
|
|
34
43
|
def on_send(node)
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Checks for redundant `source_range`.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# node.source_range.source
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# node.source
|
15
|
+
#
|
16
|
+
# # bad
|
17
|
+
# add_offense(node) { |corrector| corrector.replace(node.source_range, prefer) }
|
18
|
+
# add_offense(node) { |corrector| corrector.insert_before(node.source_range, prefer) }
|
19
|
+
# add_offense(node) { |corrector| corrector.insert_before_multi(node.source_range, prefer) }
|
20
|
+
# add_offense(node) { |corrector| corrector.insert_after(node.source_range, prefer) }
|
21
|
+
# add_offense(node) { |corrector| corrector.insert_after_multi(node.source_range, prefer) }
|
22
|
+
# add_offense(node) { |corrector| corrector.swap(node.source_range, before, after) }
|
23
|
+
#
|
24
|
+
# # good
|
25
|
+
# add_offense(node) { |corrector| corrector.replace(node, prefer) }
|
26
|
+
# add_offense(node) { |corrector| corrector.insert_before(node, prefer) }
|
27
|
+
# add_offense(node) { |corrector| corrector.insert_before_multi(node, prefer) }
|
28
|
+
# add_offense(node) { |corrector| corrector.insert_after(node, prefer) }
|
29
|
+
# add_offense(node) { |corrector| corrector.insert_after_multi(node, prefer) }
|
30
|
+
# add_offense(node) { |corrector| corrector.swap(node, before, after) }
|
31
|
+
#
|
32
|
+
class RedundantSourceRange < Base
|
33
|
+
extend AutoCorrector
|
34
|
+
|
35
|
+
MSG = 'Remove the redundant `source_range`.'
|
36
|
+
RESTRICT_ON_SEND = %i[
|
37
|
+
source
|
38
|
+
replace remove insert_before insert_before_multi insert_after insert_after_multi swap
|
39
|
+
].freeze
|
40
|
+
|
41
|
+
# @!method redundant_source_range(node)
|
42
|
+
def_node_matcher :redundant_source_range, <<~PATTERN
|
43
|
+
{
|
44
|
+
(send $(send _ :source_range) :source)
|
45
|
+
(send _ {
|
46
|
+
:replace :insert_before :insert_before_multi :insert_after :insert_after_multi
|
47
|
+
} $(send _ :source_range) _)
|
48
|
+
(send _ :remove $(send _ :source_range))
|
49
|
+
(send _ :swap $(send _ :source_range) _ _)
|
50
|
+
}
|
51
|
+
PATTERN
|
52
|
+
|
53
|
+
def on_send(node)
|
54
|
+
return unless (source_range = redundant_source_range(node))
|
55
|
+
return if source_range.receiver.send_type? && source_range.receiver.method?(:buffer)
|
56
|
+
|
57
|
+
selector = source_range.loc.selector
|
58
|
+
|
59
|
+
add_offense(selector) do |corrector|
|
60
|
+
corrector.remove(source_range.loc.dot.join(selector))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -7,20 +7,25 @@ require_relative 'internal_affairs/example_description'
|
|
7
7
|
require_relative 'internal_affairs/example_heredoc_delimiter'
|
8
8
|
require_relative 'internal_affairs/inherit_deprecated_cop_class'
|
9
9
|
require_relative 'internal_affairs/lambda_or_proc'
|
10
|
+
require_relative 'internal_affairs/location_expression'
|
10
11
|
require_relative 'internal_affairs/location_line_equality_comparison'
|
11
12
|
require_relative 'internal_affairs/method_name_end_with'
|
12
13
|
require_relative 'internal_affairs/method_name_equal'
|
13
14
|
require_relative 'internal_affairs/node_destructuring'
|
15
|
+
require_relative 'internal_affairs/node_first_or_last_argument'
|
14
16
|
require_relative 'internal_affairs/node_matcher_directive'
|
15
17
|
require_relative 'internal_affairs/node_type_predicate'
|
16
18
|
require_relative 'internal_affairs/numblock_handler'
|
17
19
|
require_relative 'internal_affairs/offense_location_keyword'
|
20
|
+
require_relative 'internal_affairs/processed_source_buffer_name'
|
18
21
|
require_relative 'internal_affairs/redundant_context_config_parameter'
|
19
22
|
require_relative 'internal_affairs/redundant_described_class_as_subject'
|
23
|
+
require_relative 'internal_affairs/redundant_expect_offense_arguments'
|
20
24
|
require_relative 'internal_affairs/redundant_let_rubocop_config_new'
|
21
25
|
require_relative 'internal_affairs/redundant_location_argument'
|
22
26
|
require_relative 'internal_affairs/redundant_message_argument'
|
23
27
|
require_relative 'internal_affairs/redundant_method_dispatch_node'
|
28
|
+
require_relative 'internal_affairs/redundant_source_range'
|
24
29
|
require_relative 'internal_affairs/single_line_comparison'
|
25
30
|
require_relative 'internal_affairs/style_detected_api_use'
|
26
31
|
require_relative 'internal_affairs/undefined_config'
|
@@ -36,17 +36,19 @@ module RuboCop
|
|
36
36
|
# If the end is on its own line, there is no offense
|
37
37
|
return if begins_its_line?(node.loc.end)
|
38
38
|
|
39
|
-
|
39
|
+
offense_range = offense_range(node)
|
40
|
+
return if offense_range.source.lstrip.start_with?(';')
|
41
|
+
|
42
|
+
register_offense(node, offense_range)
|
40
43
|
end
|
41
44
|
|
42
45
|
alias on_numblock on_block
|
43
46
|
|
44
47
|
private
|
45
48
|
|
46
|
-
def register_offense(node)
|
49
|
+
def register_offense(node, offense_range)
|
47
50
|
add_offense(node.loc.end, message: message(node)) do |corrector|
|
48
|
-
|
49
|
-
replacement = "\n#{offense_range.source.strip}"
|
51
|
+
replacement = "\n#{offense_range.source.lstrip}"
|
50
52
|
|
51
53
|
if (heredoc = last_heredoc_argument(node.body))
|
52
54
|
corrector.remove(offense_range)
|
@@ -72,17 +74,7 @@ module RuboCop
|
|
72
74
|
end
|
73
75
|
|
74
76
|
def offense_range(node)
|
75
|
-
|
76
|
-
node.loc.expression.source_buffer,
|
77
|
-
node.children.compact.last.loc.expression.end_pos,
|
78
|
-
end_of_method_chain(node).loc.expression.end_pos
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
|
-
def end_of_method_chain(node)
|
83
|
-
return node unless node.parent&.call_type?
|
84
|
-
|
85
|
-
end_of_method_chain(node.parent)
|
77
|
+
node.children.compact.last.source_range.end.join(node.loc.end)
|
86
78
|
end
|
87
79
|
end
|
88
80
|
end
|
@@ -68,6 +68,13 @@ module RuboCop
|
|
68
68
|
# - extend
|
69
69
|
# ----
|
70
70
|
#
|
71
|
+
# @safety
|
72
|
+
# Autocorrection is unsafe because class methods and module inclusion
|
73
|
+
# can behave differently, based on which methods or constants have
|
74
|
+
# already been defined.
|
75
|
+
#
|
76
|
+
# Constants will only be moved when they are assigned with literals.
|
77
|
+
#
|
71
78
|
# @example
|
72
79
|
# # bad
|
73
80
|
# # Expect extend be before constant
|
@@ -134,6 +141,7 @@ module RuboCop
|
|
134
141
|
#
|
135
142
|
class ClassStructure < Base
|
136
143
|
include VisibilityHelp
|
144
|
+
include CommentsHelp
|
137
145
|
extend AutoCorrector
|
138
146
|
|
139
147
|
HUMANIZED_NODE_TYPE = {
|
@@ -158,12 +166,13 @@ module RuboCop
|
|
158
166
|
previous = index
|
159
167
|
end
|
160
168
|
end
|
169
|
+
alias on_sclass on_class
|
161
170
|
|
162
171
|
private
|
163
172
|
|
164
173
|
# Autocorrect by swapping between two nodes autocorrecting them
|
165
174
|
def autocorrect(corrector, node)
|
166
|
-
previous = node.left_siblings.find do |sibling|
|
175
|
+
previous = node.left_siblings.reverse.find do |sibling|
|
167
176
|
!ignore_for_autocorrect?(node, sibling)
|
168
177
|
end
|
169
178
|
return unless previous
|
@@ -283,26 +292,13 @@ module RuboCop
|
|
283
292
|
node.arguments.any? { |arg| (arg.sym_type? || arg.str_type?) && arg.value == name }
|
284
293
|
end
|
285
294
|
|
286
|
-
def source_range_with_comment(node)
|
287
|
-
begin_pos, end_pos =
|
288
|
-
if (node.def_type? && !node.method?(:initialize)) ||
|
289
|
-
(node.send_type? && node.def_modifier?)
|
290
|
-
start_node = find_visibility_start(node) || node
|
291
|
-
end_node = find_visibility_end(node) || node
|
292
|
-
[begin_pos_with_comment(start_node),
|
293
|
-
end_position_for(end_node) + 1]
|
294
|
-
else
|
295
|
-
[begin_pos_with_comment(node), end_position_for(node)]
|
296
|
-
end
|
297
|
-
|
298
|
-
Parser::Source::Range.new(buffer, begin_pos, end_pos)
|
299
|
-
end
|
300
|
-
|
301
295
|
def end_position_for(node)
|
302
|
-
|
303
|
-
|
296
|
+
if node.casgn_type?
|
297
|
+
heredoc = find_heredoc(node)
|
298
|
+
return heredoc.location.heredoc_end.end_pos + 1 if heredoc
|
299
|
+
end
|
304
300
|
|
305
|
-
end_line = buffer.line_for_position(node.
|
301
|
+
end_line = buffer.line_for_position(node.source_range.end_pos)
|
306
302
|
buffer.line_range(end_line).end_pos
|
307
303
|
end
|
308
304
|
|
@@ -3,7 +3,6 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Layout
|
6
|
-
#
|
7
6
|
# Checks the indentation of here document closings.
|
8
7
|
#
|
9
8
|
# @example
|
@@ -73,7 +72,7 @@ module RuboCop
|
|
73
72
|
end
|
74
73
|
|
75
74
|
def argument_indentation_correct?(node)
|
76
|
-
return unless node.argument? || node.chained?
|
75
|
+
return false unless node.argument? || node.chained?
|
77
76
|
|
78
77
|
opening_indentation(
|
79
78
|
find_node_used_heredoc_argument(node.parent)
|
@@ -85,7 +84,7 @@ module RuboCop
|
|
85
84
|
end
|
86
85
|
|
87
86
|
def heredoc_opening(node)
|
88
|
-
node.
|
87
|
+
node.source_range.source_line
|
89
88
|
end
|
90
89
|
|
91
90
|
def heredoc_closing(node)
|
@@ -144,7 +144,7 @@ module RuboCop
|
|
144
144
|
def expected_column(left_paren, elements)
|
145
145
|
if line_break_after_left_paren?(left_paren, elements)
|
146
146
|
source_indent = processed_source.line_indentation(first_argument_line(elements))
|
147
|
-
new_indent = source_indent -
|
147
|
+
new_indent = source_indent - configured_indentation_width
|
148
148
|
|
149
149
|
new_indent.negative? ? 0 : new_indent
|
150
150
|
elsif all_elements_aligned?(elements)
|
@@ -157,7 +157,7 @@ module RuboCop
|
|
157
157
|
def all_elements_aligned?(elements)
|
158
158
|
elements.flat_map do |e|
|
159
159
|
if e.hash_type?
|
160
|
-
e.
|
160
|
+
e.each_child_node.map { |child| child.loc.column }
|
161
161
|
else
|
162
162
|
e.loc.column
|
163
163
|
end
|
@@ -184,10 +184,6 @@ module RuboCop
|
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
|
-
def indentation_width
|
188
|
-
@config.for_cop('Layout/IndentationWidth')['Width'] || 2
|
189
|
-
end
|
190
|
-
|
191
187
|
def line_break_after_left_paren?(left_paren, elements)
|
192
188
|
elements.first && elements.first.loc.line > left_paren.line
|
193
189
|
end
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def on_send(node)
|
35
|
-
return unless node.dot? ||
|
35
|
+
return unless node.dot? || node.safe_navigation?
|
36
36
|
|
37
37
|
return correct_style_detected if proper_dot_position?(node)
|
38
38
|
|
@@ -133,10 +133,6 @@ module RuboCop
|
|
133
133
|
# l.(1) has no selector, so we use the opening parenthesis instead
|
134
134
|
node.loc.selector || node.loc.begin
|
135
135
|
end
|
136
|
-
|
137
|
-
def ampersand_dot?(node)
|
138
|
-
node.loc.respond_to?(:dot) && node.loc.dot && node.loc.dot.is?('&.')
|
139
|
-
end
|
140
136
|
end
|
141
137
|
end
|
142
138
|
end
|
@@ -97,16 +97,18 @@ module RuboCop
|
|
97
97
|
def autocorrect(corrector, node)
|
98
98
|
previous_token = previous_token(node)
|
99
99
|
range = if previous_token && same_line?(node, previous_token)
|
100
|
-
range_with_surrounding_space(node.
|
100
|
+
range_with_surrounding_space(node.source_range, newlines: false)
|
101
101
|
else
|
102
|
-
range_by_whole_lines(node.
|
102
|
+
range_by_whole_lines(node.source_range, include_final_newline: true)
|
103
103
|
end
|
104
104
|
|
105
105
|
corrector.remove(range)
|
106
106
|
end
|
107
107
|
|
108
108
|
def concat_consecutive_comments(comments)
|
109
|
-
consecutive_comments = comments.chunk_while
|
109
|
+
consecutive_comments = comments.chunk_while do |i, j|
|
110
|
+
i.loc.line.succ == j.loc.line && i.loc.column == j.loc.column
|
111
|
+
end
|
110
112
|
|
111
113
|
consecutive_comments.map do |chunk|
|
112
114
|
joined_text = chunk.map { |c| comment_text(c) }.join
|
@@ -137,7 +139,7 @@ module RuboCop
|
|
137
139
|
end
|
138
140
|
|
139
141
|
def current_token(comment)
|
140
|
-
processed_source.
|
142
|
+
processed_source.tokens.find { |token| token.pos == comment.source_range }
|
141
143
|
end
|
142
144
|
|
143
145
|
def previous_token(node)
|
@@ -3,7 +3,23 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Layout
|
6
|
-
# Enforces empty line after guard clause
|
6
|
+
# Enforces empty line after guard clause.
|
7
|
+
#
|
8
|
+
# This cop allows `# :nocov:` directive after guard clause because
|
9
|
+
# SimpleCov excludes code from the coverage report by wrapping it in `# :nocov:`:
|
10
|
+
#
|
11
|
+
# [source,ruby]
|
12
|
+
# ----
|
13
|
+
# def foo
|
14
|
+
# # :nocov:
|
15
|
+
# return if condition
|
16
|
+
# # :nocov:
|
17
|
+
# bar
|
18
|
+
# end
|
19
|
+
# ----
|
20
|
+
#
|
21
|
+
# Refer to SimpleCov's documentation for more details:
|
22
|
+
# https://github.com/simplecov-ruby/simplecov#ignoringskipping-code
|
7
23
|
#
|
8
24
|
# @example
|
9
25
|
#
|
@@ -42,19 +58,22 @@ module RuboCop
|
|
42
58
|
|
43
59
|
MSG = 'Add empty line after guard clause.'
|
44
60
|
END_OF_HEREDOC_LINE = 1
|
61
|
+
SIMPLE_DIRECTIVE_COMMENT_PATTERN = /\A# *:nocov:\z/.freeze
|
45
62
|
|
46
63
|
def on_if(node)
|
47
64
|
return if correct_style?(node)
|
48
65
|
return if multiple_statements_on_line?(node)
|
49
66
|
|
50
67
|
if node.modifier_form? && (heredoc_node = last_heredoc_argument(node))
|
51
|
-
|
68
|
+
if next_line_empty_or_allowed_directive_comment?(heredoc_line(node, heredoc_node))
|
69
|
+
return
|
70
|
+
end
|
52
71
|
|
53
72
|
add_offense(heredoc_node.loc.heredoc_end) do |corrector|
|
54
73
|
autocorrect(corrector, heredoc_node)
|
55
74
|
end
|
56
75
|
else
|
57
|
-
return if
|
76
|
+
return if next_line_empty_or_allowed_directive_comment?(node.last_line)
|
58
77
|
|
59
78
|
add_offense(offense_location(node)) { |corrector| autocorrect(corrector, node) }
|
60
79
|
end
|
@@ -70,7 +89,7 @@ module RuboCop
|
|
70
89
|
end
|
71
90
|
|
72
91
|
next_line = node_range.last_line + 1
|
73
|
-
if
|
92
|
+
if next_line_allowed_directive_comment?(next_line)
|
74
93
|
node_range = processed_source.comment_at_line(next_line)
|
75
94
|
end
|
76
95
|
|
@@ -88,21 +107,21 @@ module RuboCop
|
|
88
107
|
node.if_branch&.guard_clause?
|
89
108
|
end
|
90
109
|
|
91
|
-
def
|
110
|
+
def next_line_empty_or_allowed_directive_comment?(line)
|
92
111
|
return true if next_line_empty?(line)
|
93
112
|
|
94
113
|
next_line = line + 1
|
95
|
-
|
114
|
+
next_line_allowed_directive_comment?(next_line) && next_line_empty?(next_line)
|
96
115
|
end
|
97
116
|
|
98
117
|
def next_line_empty?(line)
|
99
118
|
processed_source[line].blank?
|
100
119
|
end
|
101
120
|
|
102
|
-
def
|
121
|
+
def next_line_allowed_directive_comment?(line)
|
103
122
|
return false unless (comment = processed_source.comment_at_line(line))
|
104
123
|
|
105
|
-
DirectiveComment.new(comment).enabled?
|
124
|
+
DirectiveComment.new(comment).enabled? || simplecov_directive_comment?(comment)
|
106
125
|
end
|
107
126
|
|
108
127
|
def next_line_rescue_or_ensure?(node)
|
@@ -137,7 +156,7 @@ module RuboCop
|
|
137
156
|
return node if node
|
138
157
|
end
|
139
158
|
|
140
|
-
|
159
|
+
last_heredoc_argument(n.receiver) if n.respond_to?(:receiver)
|
141
160
|
end
|
142
161
|
|
143
162
|
def last_heredoc_argument_node(node)
|
@@ -145,6 +164,8 @@ module RuboCop
|
|
145
164
|
|
146
165
|
if node.if_branch.and_type?
|
147
166
|
node.if_branch.children.first
|
167
|
+
elsif use_heredoc_in_condition?(node.condition)
|
168
|
+
node.condition
|
148
169
|
else
|
149
170
|
node.if_branch.children.last
|
150
171
|
end
|
@@ -161,6 +182,12 @@ module RuboCop
|
|
161
182
|
node.respond_to?(:heredoc?) && node.heredoc?
|
162
183
|
end
|
163
184
|
|
185
|
+
def use_heredoc_in_condition?(condition)
|
186
|
+
condition.descendants.any? do |descendant|
|
187
|
+
descendant.respond_to?(:heredoc?) && descendant.heredoc?
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
164
191
|
def offense_location(node)
|
165
192
|
if node.loc.respond_to?(:end) && node.loc.end
|
166
193
|
node.loc.end
|
@@ -175,6 +202,12 @@ module RuboCop
|
|
175
202
|
|
176
203
|
parent.begin_type? && parent.single_line?
|
177
204
|
end
|
205
|
+
|
206
|
+
# SimpleCov excludes code from the coverage report by wrapping it in `# :nocov:`:
|
207
|
+
# https://github.com/simplecov-ruby/simplecov#ignoringskipping-code
|
208
|
+
def simplecov_directive_comment?(comment)
|
209
|
+
SIMPLE_DIRECTIVE_COMMENT_PATTERN.match?(comment.text)
|
210
|
+
end
|
178
211
|
end
|
179
212
|
end
|
180
213
|
end
|
@@ -27,9 +27,9 @@ module RuboCop
|
|
27
27
|
MSG = 'Add an empty line after magic comments.'
|
28
28
|
|
29
29
|
def on_new_investigation
|
30
|
-
return unless processed_source
|
31
|
-
|
32
|
-
return if
|
30
|
+
return unless (last_magic_comment = last_magic_comment(processed_source))
|
31
|
+
return unless (next_line = processed_source[last_magic_comment.loc.line])
|
32
|
+
return if next_line.strip.empty?
|
33
33
|
|
34
34
|
offending_range = offending_range(last_magic_comment)
|
35
35
|
|
@@ -46,18 +46,25 @@ module RuboCop
|
|
46
46
|
|
47
47
|
# Find the last magic comment in the source file.
|
48
48
|
#
|
49
|
-
# Take all comments that precede the first line of code
|
49
|
+
# Take all comments that precede the first line of code (or just take
|
50
|
+
# them all in the case when there is no code), select the
|
50
51
|
# magic comments, and return the last magic comment in the file.
|
51
52
|
#
|
52
53
|
# @return [Parser::Source::Comment] if magic comments exist before code
|
53
54
|
# @return [nil] otherwise
|
54
55
|
def last_magic_comment(source)
|
55
|
-
source
|
56
|
-
.comments
|
57
|
-
.take_while { |comment| comment.loc.line < source.ast.loc.line }
|
56
|
+
comments_before_code(source)
|
58
57
|
.reverse
|
59
58
|
.find { |comment| MagicComment.parse(comment.text).any? }
|
60
59
|
end
|
60
|
+
|
61
|
+
def comments_before_code(source)
|
62
|
+
if source.ast
|
63
|
+
source.comments.take_while { |comment| comment.loc.line < source.ast.loc.line }
|
64
|
+
else
|
65
|
+
source.comments
|
66
|
+
end
|
67
|
+
end
|
61
68
|
end
|
62
69
|
end
|
63
70
|
end
|
@@ -135,7 +135,8 @@ module RuboCop
|
|
135
135
|
return if nodes.all?(&:single_line?) && cop_config['AllowAdjacentOneLineDefs']
|
136
136
|
|
137
137
|
correction_node = nodes.last
|
138
|
-
|
138
|
+
|
139
|
+
location = def_location(correction_node)
|
139
140
|
add_offense(location, message: message(correction_node, count: count)) do |corrector|
|
140
141
|
autocorrect(corrector, *nodes, count)
|
141
142
|
end
|
@@ -159,10 +160,28 @@ module RuboCop
|
|
159
160
|
|
160
161
|
private
|
161
162
|
|
163
|
+
def def_location(correction_node)
|
164
|
+
if correction_node.block_type?
|
165
|
+
correction_node.source_range.join(correction_node.children.first.source_range)
|
166
|
+
else
|
167
|
+
correction_node.loc.keyword.join(correction_node.loc.name)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
162
171
|
def candidate?(node)
|
163
|
-
return unless node
|
172
|
+
return false unless node
|
164
173
|
|
165
|
-
method_candidate?(node) || class_candidate?(node) || module_candidate?(node)
|
174
|
+
method_candidate?(node) || class_candidate?(node) || module_candidate?(node) ||
|
175
|
+
macro_candidate?(node)
|
176
|
+
end
|
177
|
+
|
178
|
+
def empty_line_between_macros
|
179
|
+
cop_config.fetch('DefLikeMacros', []).map(&:to_sym)
|
180
|
+
end
|
181
|
+
|
182
|
+
def macro_candidate?(node)
|
183
|
+
node.block_type? && node.children.first.macro? &&
|
184
|
+
empty_line_between_macros.include?(node.children.first.method_name)
|
166
185
|
end
|
167
186
|
|
168
187
|
def method_candidate?(node)
|
@@ -226,7 +245,11 @@ module RuboCop
|
|
226
245
|
end
|
227
246
|
|
228
247
|
def def_start(node)
|
229
|
-
node.
|
248
|
+
if node.block_type? && node.children.first.send_type?
|
249
|
+
node.source_range.line
|
250
|
+
else
|
251
|
+
node.loc.keyword.line
|
252
|
+
end
|
230
253
|
end
|
231
254
|
|
232
255
|
def def_end(node)
|
@@ -235,7 +258,7 @@ module RuboCop
|
|
235
258
|
|
236
259
|
def end_loc(node)
|
237
260
|
if (node.def_type? || node.defs_type?) && node.endless?
|
238
|
-
node.
|
261
|
+
node.source_range.end
|
239
262
|
else
|
240
263
|
node.loc.end
|
241
264
|
end
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
return unless processed_source.raw_source.include?("\n\n\n")
|
32
32
|
|
33
33
|
lines = Set.new
|
34
|
-
processed_source.
|
34
|
+
processed_source.tokens.each { |token| lines << token.line }
|
35
35
|
|
36
36
|
each_extra_empty_line(lines.sort) do |range|
|
37
37
|
add_offense(range) do |corrector|
|