rubocop 1.12.1 → 1.16.1
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 +5 -2
- data/config/default.yml +78 -8
- data/exe/rubocop +1 -3
- data/lib/rubocop.rb +10 -1
- data/lib/rubocop/cached_data.rb +1 -3
- data/lib/rubocop/cli.rb +4 -6
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +9 -19
- data/lib/rubocop/cli/command/init_dotfile.rb +1 -3
- data/lib/rubocop/cli/command/show_cops.rb +1 -4
- data/lib/rubocop/comment_config.rb +2 -7
- data/lib/rubocop/config.rb +11 -26
- data/lib/rubocop/config_loader.rb +5 -11
- data/lib/rubocop/config_loader_resolver.rb +22 -14
- data/lib/rubocop/config_obsoletion/cop_rule.rb +1 -2
- data/lib/rubocop/config_store.rb +1 -2
- data/lib/rubocop/config_validator.rb +5 -10
- data/lib/rubocop/cop/autocorrect_logic.rb +3 -8
- data/lib/rubocop/cop/badge.rb +1 -2
- data/lib/rubocop/cop/base.rb +8 -6
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -2
- data/lib/rubocop/cop/bundler/gem_comment.rb +43 -11
- data/lib/rubocop/cop/bundler/gem_version.rb +99 -0
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -4
- data/lib/rubocop/cop/commissioner.rb +2 -8
- data/lib/rubocop/cop/cop.rb +4 -18
- data/lib/rubocop/cop/corrector.rb +1 -4
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +3 -6
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +2 -4
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +1 -2
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +3 -6
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +1 -3
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +1 -3
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -8
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +1 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -4
- data/lib/rubocop/cop/generator.rb +1 -4
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -2
- data/lib/rubocop/cop/generator/require_file_injector.rb +2 -5
- data/lib/rubocop/cop/internal_affairs/example_description.rb +7 -5
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +2 -5
- data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +1 -3
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -3
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -2
- data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +1 -2
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +1 -3
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -2
- data/lib/rubocop/cop/layout/argument_alignment.rb +30 -14
- data/lib/rubocop/cop/layout/assignment_indentation.rb +2 -4
- data/lib/rubocop/cop/layout/begin_end_alignment.rb +1 -4
- data/lib/rubocop/cop/layout/block_alignment.rb +7 -19
- data/lib/rubocop/cop/layout/case_indentation.rb +57 -11
- data/lib/rubocop/cop/layout/class_structure.rb +4 -10
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +4 -15
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -5
- data/lib/rubocop/cop/layout/def_end_alignment.rb +2 -6
- data/lib/rubocop/cop/layout/dot_position.rb +1 -3
- data/lib/rubocop/cop/layout/else_alignment.rb +1 -3
- data/lib/rubocop/cop/layout/empty_comment.rb +5 -12
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +2 -5
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -6
- data/lib/rubocop/cop/layout/empty_lines.rb +1 -3
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +8 -18
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +2 -8
- data/lib/rubocop/cop/layout/end_alignment.rb +1 -2
- data/lib/rubocop/cop/layout/end_of_line.rb +1 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +3 -7
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +1 -2
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -2
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +14 -5
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +1 -2
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -2
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +1 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +36 -15
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -9
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -6
- data/lib/rubocop/cop/layout/indentation_style.rb +1 -3
- data/lib/rubocop/cop/layout/indentation_width.rb +6 -4
- data/lib/rubocop/cop/layout/initial_indentation.rb +1 -4
- data/lib/rubocop/cop/layout/line_length.rb +4 -15
- data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +1 -2
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +7 -15
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +1 -2
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -2
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +4 -10
- data/lib/rubocop/cop/layout/redundant_line_break.rb +137 -0
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -6
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +53 -0
- data/lib/rubocop/cop/layout/space_after_colon.rb +1 -3
- data/lib/rubocop/cop/layout/space_after_method_name.rb +2 -4
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +6 -14
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +1 -2
- data/lib/rubocop/cop/layout/space_around_keyword.rb +19 -6
- data/lib/rubocop/cop/layout/space_around_operators.rb +4 -9
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -2
- data/lib/rubocop/cop/layout/space_before_brackets.rb +1 -3
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +5 -11
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +2 -4
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +5 -10
- data/lib/rubocop/cop/layout/space_inside_array_percent_literal.rb +2 -7
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +5 -10
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +1 -2
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -2
- data/lib/rubocop/cop/legacy/corrections_proxy.rb +2 -8
- data/lib/rubocop/cop/legacy/corrector.rb +1 -3
- data/lib/rubocop/cop/lint/ambiguous_assignment.rb +1 -6
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +14 -7
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -2
- data/lib/rubocop/cop/lint/constant_resolution.rb +1 -2
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +83 -41
- data/lib/rubocop/cop/lint/deprecated_constants.rb +3 -3
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +2 -5
- data/lib/rubocop/cop/lint/duplicate_branch.rb +1 -2
- data/lib/rubocop/cop/lint/duplicate_hash_key.rb +1 -3
- data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -7
- data/lib/rubocop/cop/lint/else_layout.rb +1 -3
- data/lib/rubocop/cop/lint/empty_block.rb +18 -2
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -3
- data/lib/rubocop/cop/lint/empty_file.rb +1 -3
- data/lib/rubocop/cop/lint/empty_in_pattern.rb +62 -0
- data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -3
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -3
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +3 -7
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -2
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +3 -6
- data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +1 -2
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -2
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +3 -7
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -2
- data/lib/rubocop/cop/lint/interpolation_check.rb +3 -11
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +3 -6
- data/lib/rubocop/cop/lint/loop.rb +1 -2
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +3 -7
- data/lib/rubocop/cop/lint/missing_super.rb +1 -2
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -2
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -2
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -3
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +1 -3
- data/lib/rubocop/cop/lint/number_conversion.rb +2 -3
- data/lib/rubocop/cop/lint/ordered_magic_comments.rb +1 -2
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +1 -3
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -3
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -3
- data/lib/rubocop/cop/lint/raise_exception.rb +1 -2
- data/lib/rubocop/cop/lint/rand_one.rb +1 -2
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +18 -27
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -3
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +3 -7
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -2
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -4
- data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -4
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +1 -3
- data/lib/rubocop/cop/lint/require_parentheses.rb +2 -4
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -2
- data/lib/rubocop/cop/lint/rescue_type.rb +2 -7
- data/lib/rubocop/cop/lint/return_in_void_context.rb +1 -2
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -2
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +4 -10
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -2
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +2 -7
- data/lib/rubocop/cop/lint/shadowed_argument.rb +4 -11
- data/lib/rubocop/cop/lint/shadowed_exception.rb +7 -8
- data/lib/rubocop/cop/lint/struct_new_override.rb +1 -2
- data/lib/rubocop/cop/lint/symbol_conversion.rb +4 -16
- data/lib/rubocop/cop/lint/syntax.rb +1 -3
- data/lib/rubocop/cop/lint/to_json.rb +1 -2
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -3
- data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +1 -3
- data/lib/rubocop/cop/lint/unreachable_code.rb +2 -5
- data/lib/rubocop/cop/lint/unreachable_loop.rb +14 -7
- data/lib/rubocop/cop/lint/unused_block_argument.rb +9 -7
- data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -4
- data/lib/rubocop/cop/lint/useless_assignment.rb +4 -9
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -3
- data/lib/rubocop/cop/lint/void.rb +5 -12
- data/lib/rubocop/cop/message_annotator.rb +1 -3
- data/lib/rubocop/cop/metrics/block_nesting.rb +2 -7
- data/lib/rubocop/cop/metrics/class_length.rb +1 -3
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -2
- data/lib/rubocop/cop/metrics/module_length.rb +2 -6
- data/lib/rubocop/cop/metrics/parameter_lists.rb +2 -5
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -2
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +4 -7
- data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +2 -7
- data/lib/rubocop/cop/migration/department_name.rb +3 -7
- data/lib/rubocop/cop/mixin/alignment.rb +2 -4
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +19 -3
- data/lib/rubocop/cop/mixin/code_length.rb +1 -3
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +2 -2
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +3 -8
- data/lib/rubocop/cop/mixin/def_node.rb +2 -5
- data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -5
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -7
- data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -3
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -3
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -6
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -3
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +7 -7
- data/lib/rubocop/cop/mixin/gem_declaration.rb +13 -0
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +17 -9
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +7 -22
- data/lib/rubocop/cop/mixin/interpolation.rb +1 -3
- data/lib/rubocop/cop/mixin/line_length_help.rb +2 -4
- data/lib/rubocop/cop/mixin/match_range.rb +2 -5
- data/lib/rubocop/cop/mixin/method_complexity.rb +1 -3
- data/lib/rubocop/cop/mixin/method_preference.rb +1 -2
- data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +1 -2
- data/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb +1 -3
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +7 -17
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -2
- data/lib/rubocop/cop/mixin/negative_conditional.rb +1 -2
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -4
- data/lib/rubocop/cop/mixin/percent_array.rb +1 -3
- data/lib/rubocop/cop/mixin/percent_literal.rb +0 -6
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +5 -11
- data/lib/rubocop/cop/mixin/preferred_delimiters.rb +3 -6
- data/lib/rubocop/cop/mixin/range_help.rb +10 -13
- data/lib/rubocop/cop/mixin/rescue_node.rb +2 -6
- data/lib/rubocop/cop/mixin/safe_assignment.rb +1 -2
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -4
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -2
- data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -3
- data/lib/rubocop/cop/mixin/string_literals_help.rb +3 -5
- data/lib/rubocop/cop/mixin/symbol_help.rb +13 -0
- data/lib/rubocop/cop/mixin/trailing_body.rb +1 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -2
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +3 -7
- data/lib/rubocop/cop/mixin/unused_argument.rb +1 -3
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +2 -4
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -2
- data/lib/rubocop/cop/naming/file_name.rb +7 -16
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -3
- data/lib/rubocop/cop/naming/method_name.rb +1 -2
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -2
- data/lib/rubocop/cop/offense.rb +3 -8
- data/lib/rubocop/cop/registry.rb +3 -11
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -3
- data/lib/rubocop/cop/style/accessor_grouping.rb +1 -3
- data/lib/rubocop/cop/style/alias.rb +5 -12
- data/lib/rubocop/cop/style/arguments_forwarding.rb +1 -3
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -2
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +2 -5
- data/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb +1 -3
- data/lib/rubocop/cop/style/case_like_if.rb +1 -2
- data/lib/rubocop/cop/style/character_literal.rb +2 -4
- data/lib/rubocop/cop/style/class_and_module_children.rb +19 -10
- data/lib/rubocop/cop/style/class_methods.rb +1 -3
- data/lib/rubocop/cop/style/collection_compact.rb +1 -3
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -3
- data/lib/rubocop/cop/style/combinable_loops.rb +3 -2
- data/lib/rubocop/cop/style/command_literal.rb +3 -8
- data/lib/rubocop/cop/style/comment_annotation.rb +3 -6
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -8
- data/lib/rubocop/cop/style/conditional_assignment.rb +10 -24
- data/lib/rubocop/cop/style/copyright.rb +3 -6
- data/lib/rubocop/cop/style/date_time.rb +2 -5
- data/lib/rubocop/cop/style/def_with_parentheses.rb +1 -2
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +2 -7
- data/lib/rubocop/cop/style/empty_else.rb +3 -9
- data/lib/rubocop/cop/style/empty_literal.rb +12 -9
- data/lib/rubocop/cop/style/empty_method.rb +3 -7
- data/lib/rubocop/cop/style/end_block.rb +1 -2
- data/lib/rubocop/cop/style/endless_method.rb +1 -3
- data/lib/rubocop/cop/style/eval_with_location.rb +2 -4
- data/lib/rubocop/cop/style/expand_path_arguments.rb +1 -3
- data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -4
- data/lib/rubocop/cop/style/format_string_token.rb +1 -4
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -8
- data/lib/rubocop/cop/style/guard_clause.rb +3 -7
- data/lib/rubocop/cop/style/hash_conversion.rb +28 -3
- data/lib/rubocop/cop/style/hash_each_methods.rb +19 -3
- data/lib/rubocop/cop/style/hash_like_case.rb +1 -2
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -9
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +27 -8
- data/lib/rubocop/cop/style/if_unless_modifier.rb +40 -13
- data/lib/rubocop/cop/style/in_pattern_then.rb +56 -0
- data/lib/rubocop/cop/style/infinite_loop.rb +2 -5
- data/lib/rubocop/cop/style/inverse_methods.rb +3 -7
- data/lib/rubocop/cop/style/ip_addresses.rb +1 -2
- data/lib/rubocop/cop/style/lambda.rb +2 -4
- data/lib/rubocop/cop/style/lambda_call.rb +1 -2
- data/lib/rubocop/cop/style/line_end_concatenation.rb +5 -12
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +7 -12
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -2
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -4
- data/lib/rubocop/cop/style/method_def_parentheses.rb +4 -8
- data/lib/rubocop/cop/style/min_max.rb +1 -2
- data/lib/rubocop/cop/style/missing_else.rb +2 -4
- data/lib/rubocop/cop/style/missing_respond_to_missing.rb +1 -2
- data/lib/rubocop/cop/style/mixin_grouping.rb +4 -10
- data/lib/rubocop/cop/style/mixin_usage.rb +1 -2
- data/lib/rubocop/cop/style/module_function.rb +3 -6
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -2
- data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +62 -0
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -3
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -2
- data/lib/rubocop/cop/style/multiline_when_then.rb +2 -11
- data/lib/rubocop/cop/style/multiple_comparison.rb +2 -4
- data/lib/rubocop/cop/style/mutable_constant.rb +4 -10
- data/lib/rubocop/cop/style/negated_if.rb +1 -2
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +17 -9
- data/lib/rubocop/cop/style/negated_unless.rb +1 -2
- data/lib/rubocop/cop/style/nested_modifier.rb +3 -7
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +2 -3
- data/lib/rubocop/cop/style/next.rb +4 -9
- data/lib/rubocop/cop/style/nil_lambda.rb +29 -12
- data/lib/rubocop/cop/style/non_nil_check.rb +2 -5
- data/lib/rubocop/cop/style/numeric_literals.rb +3 -11
- data/lib/rubocop/cop/style/numeric_predicate.rb +2 -7
- data/lib/rubocop/cop/style/one_line_conditional.rb +1 -2
- data/lib/rubocop/cop/style/option_hash.rb +1 -3
- data/lib/rubocop/cop/style/optional_arguments.rb +2 -5
- data/lib/rubocop/cop/style/or_assignment.rb +2 -6
- data/lib/rubocop/cop/style/parallel_assignment.rb +6 -9
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -3
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -2
- data/lib/rubocop/cop/style/perl_backrefs.rb +2 -9
- data/lib/rubocop/cop/style/preferred_hash_methods.rb +1 -4
- data/lib/rubocop/cop/style/proc.rb +1 -2
- data/lib/rubocop/cop/style/quoted_symbols.rb +110 -0
- data/lib/rubocop/cop/style/raise_args.rb +4 -8
- data/lib/rubocop/cop/style/random_with_offset.rb +3 -8
- data/lib/rubocop/cop/style/redundant_argument.rb +2 -11
- data/lib/rubocop/cop/style/redundant_assignment.rb +1 -3
- data/lib/rubocop/cop/style/redundant_begin.rb +4 -4
- data/lib/rubocop/cop/style/redundant_capital_w.rb +1 -2
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -5
- data/lib/rubocop/cop/style/redundant_conditional.rb +3 -6
- data/lib/rubocop/cop/style/redundant_exception.rb +3 -6
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -1
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -2
- data/lib/rubocop/cop/style/redundant_interpolation.rb +1 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +8 -20
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -2
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -4
- data/lib/rubocop/cop/style/redundant_return.rb +3 -5
- data/lib/rubocop/cop/style/redundant_self.rb +25 -7
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +2 -2
- data/lib/rubocop/cop/style/redundant_sort.rb +2 -5
- data/lib/rubocop/cop/style/regexp_literal.rb +4 -8
- data/lib/rubocop/cop/style/rescue_modifier.rb +4 -0
- data/lib/rubocop/cop/style/rescue_standard_error.rb +3 -7
- data/lib/rubocop/cop/style/return_nil.rb +1 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +10 -21
- data/lib/rubocop/cop/style/send.rb +1 -2
- data/lib/rubocop/cop/style/signal_exception.rb +3 -7
- data/lib/rubocop/cop/style/single_argument_dig.rb +1 -2
- data/lib/rubocop/cop/style/single_line_block_params.rb +2 -5
- data/lib/rubocop/cop/style/single_line_methods.rb +20 -4
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +15 -7
- data/lib/rubocop/cop/style/special_global_vars.rb +6 -18
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -2
- data/lib/rubocop/cop/style/stderr_puts.rb +2 -6
- data/lib/rubocop/cop/style/string_chars.rb +2 -1
- data/lib/rubocop/cop/style/string_concatenation.rb +8 -10
- data/lib/rubocop/cop/style/string_literals.rb +3 -5
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +1 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +9 -1
- data/lib/rubocop/cop/style/symbol_literal.rb +1 -3
- data/lib/rubocop/cop/style/symbol_proc.rb +4 -9
- data/lib/rubocop/cop/style/ternary_parentheses.rb +3 -6
- data/lib/rubocop/cop/style/top_level_method_definition.rb +83 -0
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +1 -2
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +2 -6
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +2 -5
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +4 -10
- data/lib/rubocop/cop/style/trivial_accessors.rb +67 -4
- data/lib/rubocop/cop/style/unless_else.rb +1 -2
- data/lib/rubocop/cop/style/unless_logical_operators.rb +2 -2
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +4 -2
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -2
- data/lib/rubocop/cop/style/word_array.rb +1 -2
- data/lib/rubocop/cop/style/yoda_condition.rb +3 -11
- data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -2
- data/lib/rubocop/cop/team.rb +2 -5
- data/lib/rubocop/cop/util.rb +4 -10
- data/lib/rubocop/cop/utils/format_string.rb +1 -3
- data/lib/rubocop/cop/variable_force.rb +6 -15
- data/lib/rubocop/cop/variable_force/assignment.rb +1 -2
- data/lib/rubocop/cop/variable_force/branch.rb +16 -2
- data/lib/rubocop/cop/variable_force/reference.rb +1 -3
- data/lib/rubocop/cop/variable_force/scope.rb +4 -8
- data/lib/rubocop/cop/variable_force/variable.rb +2 -4
- data/lib/rubocop/cops_documentation_generator.rb +7 -21
- data/lib/rubocop/directive_comment.rb +5 -1
- data/lib/rubocop/file_finder.rb +1 -3
- data/lib/rubocop/formatter/disabled_config_formatter.rb +3 -8
- data/lib/rubocop/formatter/git_hub_actions_formatter.rb +1 -5
- data/lib/rubocop/formatter/html_formatter.rb +4 -10
- data/lib/rubocop/formatter/json_formatter.rb +1 -5
- data/lib/rubocop/formatter/junit_formatter.rb +23 -14
- data/lib/rubocop/formatter/progress_formatter.rb +1 -3
- data/lib/rubocop/options.rb +30 -50
- data/lib/rubocop/path_util.rb +1 -3
- data/lib/rubocop/rake_task.rb +3 -0
- data/lib/rubocop/remote_config.rb +4 -7
- data/lib/rubocop/result_cache.rb +5 -12
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +4 -9
- data/lib/rubocop/rspec/shared_contexts.rb +8 -15
- data/lib/rubocop/runner.rb +7 -14
- data/lib/rubocop/target_finder.rb +18 -16
- data/lib/rubocop/target_ruby.rb +4 -8
- data/lib/rubocop/version.rb +1 -1
- metadata +16 -7
- data/lib/rubocop/core_ext/hash.rb +0 -20
@@ -25,12 +25,7 @@ module RuboCop
|
|
25
25
|
|
26
26
|
SIMPLE_ASSIGNMENT_TYPES = %i[lvasgn ivasgn cvasgn gvasgn casgn].freeze
|
27
27
|
|
28
|
-
MISTAKES = {
|
29
|
-
'=-' => '-=',
|
30
|
-
'=+' => '+=',
|
31
|
-
'=*' => '*=',
|
32
|
-
'=!' => '!='
|
33
|
-
}.freeze
|
28
|
+
MISTAKES = { '=-' => '-=', '=+' => '+=', '=*' => '*=', '=!' => '!=' }.freeze
|
34
29
|
|
35
30
|
def on_asgn(node)
|
36
31
|
return unless (rhs = rhs(node))
|
@@ -6,6 +6,8 @@ module RuboCop
|
|
6
6
|
# This cop checks for ambiguous block association with method
|
7
7
|
# when param passed without parentheses.
|
8
8
|
#
|
9
|
+
# This cop can customize ignored methods with `IgnoredMethods`.
|
10
|
+
#
|
9
11
|
# @example
|
10
12
|
#
|
11
13
|
# # bad
|
@@ -26,7 +28,14 @@ module RuboCop
|
|
26
28
|
# # good
|
27
29
|
# # Lambda arguments require no disambiguation
|
28
30
|
# foo = ->(bar) { bar.baz }
|
31
|
+
#
|
32
|
+
# @example IgnoredMethods: [change]
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
# expect { do_something }.to change { object.attribute }
|
29
36
|
class AmbiguousBlockAssociation < Base
|
37
|
+
include IgnoredMethods
|
38
|
+
|
30
39
|
MSG = 'Parenthesize the param `%<param>s` to make sure that the ' \
|
31
40
|
'block will be associated with the `%<method>s` method ' \
|
32
41
|
'call.'
|
@@ -35,8 +44,7 @@ module RuboCop
|
|
35
44
|
return unless node.arguments?
|
36
45
|
|
37
46
|
return unless ambiguous_block_association?(node)
|
38
|
-
return if node.parenthesized? ||
|
39
|
-
node.last_argument.lambda? || allowed_method?(node)
|
47
|
+
return if node.parenthesized? || node.last_argument.lambda? || allowed_method?(node)
|
40
48
|
|
41
49
|
message = message(node)
|
42
50
|
|
@@ -47,19 +55,18 @@ module RuboCop
|
|
47
55
|
private
|
48
56
|
|
49
57
|
def ambiguous_block_association?(send_node)
|
50
|
-
send_node.last_argument.block_type? &&
|
51
|
-
!send_node.last_argument.send_node.arguments?
|
58
|
+
send_node.last_argument.block_type? && !send_node.last_argument.send_node.arguments?
|
52
59
|
end
|
53
60
|
|
54
61
|
def allowed_method?(node)
|
55
|
-
node.assignment? || node.operator_method? || node.method?(:[])
|
62
|
+
node.assignment? || node.operator_method? || node.method?(:[]) ||
|
63
|
+
ignored_method?(node.last_argument.send_node.source)
|
56
64
|
end
|
57
65
|
|
58
66
|
def message(send_node)
|
59
67
|
block_param = send_node.last_argument
|
60
68
|
|
61
|
-
format(MSG, param: block_param.source,
|
62
|
-
method: block_param.send_node.source)
|
69
|
+
format(MSG, param: block_param.source, method: block_param.send_node.source)
|
63
70
|
end
|
64
71
|
end
|
65
72
|
end
|
@@ -24,8 +24,7 @@ module RuboCop
|
|
24
24
|
class BooleanSymbol < Base
|
25
25
|
extend AutoCorrector
|
26
26
|
|
27
|
-
MSG = 'Symbol with a boolean name - '
|
28
|
-
'you probably meant to use `%<boolean>s`.'
|
27
|
+
MSG = 'Symbol with a boolean name - you probably meant to use `%<boolean>s`.'
|
29
28
|
|
30
29
|
# @!method boolean_symbol?(node)
|
31
30
|
def_node_matcher :boolean_symbol?, '(sym {:true :false})'
|
@@ -73,8 +73,7 @@ module RuboCop
|
|
73
73
|
|
74
74
|
def const_name?(name)
|
75
75
|
name = name.to_s
|
76
|
-
(allowed_names.empty? || allowed_names.include?(name)) &&
|
77
|
-
!ignored_names.include?(name)
|
76
|
+
(allowed_names.empty? || allowed_names.include?(name)) && !ignored_names.include?(name)
|
78
77
|
end
|
79
78
|
|
80
79
|
def allowed_names
|
@@ -12,6 +12,8 @@ module RuboCop
|
|
12
12
|
# File.exists?(some_path)
|
13
13
|
# Dir.exists?(some_path)
|
14
14
|
# iterator?
|
15
|
+
# Socket.gethostbyname(host)
|
16
|
+
# Socket.gethostbyaddr(host)
|
15
17
|
#
|
16
18
|
# @example
|
17
19
|
#
|
@@ -20,21 +22,23 @@ module RuboCop
|
|
20
22
|
# File.exist?(some_path)
|
21
23
|
# Dir.exist?(some_path)
|
22
24
|
# block_given?
|
25
|
+
# Addrinfo.getaddrinfo(nodename, service)
|
26
|
+
# Addrinfo.tcp(host, port).getnameinfo
|
23
27
|
class DeprecatedClassMethods < Base
|
24
28
|
extend AutoCorrector
|
25
29
|
|
26
30
|
# Inner class to DeprecatedClassMethods.
|
27
|
-
# This class exists to add abstraction and clean naming
|
28
|
-
#
|
31
|
+
# This class exists to add abstraction and clean naming
|
32
|
+
# to the deprecated objects
|
29
33
|
class DeprecatedClassMethod
|
30
34
|
include RuboCop::AST::Sexp
|
31
35
|
|
32
|
-
attr_reader :
|
36
|
+
attr_reader :method, :class_constant
|
33
37
|
|
34
|
-
def initialize(
|
35
|
-
@
|
36
|
-
@replacement_method = replacement
|
38
|
+
def initialize(method, class_constant: nil, correctable: true)
|
39
|
+
@method = method
|
37
40
|
@class_constant = class_constant
|
41
|
+
@correctable = correctable
|
38
42
|
end
|
39
43
|
|
40
44
|
def class_nodes
|
@@ -48,29 +52,80 @@ module RuboCop
|
|
48
52
|
[nil]
|
49
53
|
end
|
50
54
|
end
|
55
|
+
|
56
|
+
def correctable?
|
57
|
+
@correctable
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_s
|
61
|
+
[class_constant, method].compact.join(delimeter)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def delimeter
|
67
|
+
CLASS_METHOD_DELIMETER
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Inner class to DeprecatedClassMethods.
|
72
|
+
# This class exists to add abstraction and clean naming
|
73
|
+
# to the replacements for deprecated objects
|
74
|
+
class Replacement
|
75
|
+
attr_reader :method, :class_constant
|
76
|
+
|
77
|
+
def initialize(method, class_constant: nil, instance_method: false)
|
78
|
+
@method = method
|
79
|
+
@class_constant = class_constant
|
80
|
+
@instance_method = instance_method
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_s
|
84
|
+
[class_constant, method].compact.join(delimeter)
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def delimeter
|
90
|
+
instance_method? ? INSTANCE_METHOD_DELIMETER : CLASS_METHOD_DELIMETER
|
91
|
+
end
|
92
|
+
|
93
|
+
def instance_method?
|
94
|
+
@instance_method
|
95
|
+
end
|
51
96
|
end
|
52
97
|
|
53
98
|
MSG = '`%<current>s` is deprecated in favor of `%<prefer>s`.'
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
99
|
+
|
100
|
+
DEPRECATED_METHODS_OBJECT = {
|
101
|
+
DeprecatedClassMethod.new(:exists?, class_constant: :File) =>
|
102
|
+
Replacement.new(:exist?, class_constant: :File),
|
103
|
+
|
104
|
+
DeprecatedClassMethod.new(:exists?, class_constant: :Dir) =>
|
105
|
+
Replacement.new(:exist?, class_constant: :Dir),
|
106
|
+
|
107
|
+
DeprecatedClassMethod.new(:iterator?) => Replacement.new(:block_given?),
|
108
|
+
|
109
|
+
DeprecatedClassMethod.new(:gethostbyaddr, class_constant: :Socket, correctable: false) =>
|
110
|
+
Replacement.new(:getnameinfo, class_constant: :Addrinfo, instance_method: true),
|
111
|
+
|
112
|
+
DeprecatedClassMethod.new(:gethostbyname, class_constant: :Socket, correctable: false) =>
|
113
|
+
Replacement.new(:getaddrinfo, class_constant: :Addrinfo, instance_method: true)
|
114
|
+
}.freeze
|
115
|
+
|
116
|
+
RESTRICT_ON_SEND = DEPRECATED_METHODS_OBJECT.keys.map(&:method).freeze
|
117
|
+
|
118
|
+
CLASS_METHOD_DELIMETER = '.'
|
119
|
+
INSTANCE_METHOD_DELIMETER = '#'
|
66
120
|
|
67
121
|
def on_send(node)
|
68
|
-
check(node) do |
|
69
|
-
message = format(MSG, current:
|
70
|
-
prefer: replacement_method(data))
|
122
|
+
check(node) do |deprecated|
|
123
|
+
message = format(MSG, current: deprecated, prefer: replacement(deprecated))
|
71
124
|
|
72
125
|
add_offense(node.loc.selector, message: message) do |corrector|
|
73
|
-
|
126
|
+
if deprecated.correctable?
|
127
|
+
corrector.replace(node.loc.selector, replacement(deprecated).method)
|
128
|
+
end
|
74
129
|
end
|
75
130
|
end
|
76
131
|
end
|
@@ -78,29 +133,16 @@ module RuboCop
|
|
78
133
|
private
|
79
134
|
|
80
135
|
def check(node)
|
81
|
-
DEPRECATED_METHODS_OBJECT.
|
82
|
-
next unless
|
83
|
-
next unless node.method?(
|
136
|
+
DEPRECATED_METHODS_OBJECT.each_key do |deprecated|
|
137
|
+
next unless deprecated.class_nodes.include?(node.receiver)
|
138
|
+
next unless node.method?(deprecated.method)
|
84
139
|
|
85
|
-
yield
|
140
|
+
yield deprecated
|
86
141
|
end
|
87
142
|
end
|
88
143
|
|
89
|
-
def
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
def replacement_method(data)
|
94
|
-
method_call(data.class_constant, data.replacement_method)
|
95
|
-
end
|
96
|
-
|
97
|
-
def method_call(class_constant, method)
|
98
|
-
if class_constant
|
99
|
-
format('%<constant>s.%<method>s', constant: class_constant,
|
100
|
-
method: method)
|
101
|
-
else
|
102
|
-
format('%<method>s', method: method)
|
103
|
-
end
|
144
|
+
def replacement(deprecated)
|
145
|
+
DEPRECATED_METHODS_OBJECT[deprecated]
|
104
146
|
end
|
105
147
|
end
|
106
148
|
end
|
@@ -42,7 +42,7 @@ module RuboCop
|
|
42
42
|
# Maybe further investigation of RuboCop AST will lead to an essential solution.
|
43
43
|
return unless node.loc
|
44
44
|
|
45
|
-
constant = node.absolute? ?
|
45
|
+
constant = node.absolute? ? constant_name(node, node.short_name.to_s) : node.source
|
46
46
|
return unless (deprecated_constant = deprecated_constants[constant])
|
47
47
|
|
48
48
|
alternative = deprecated_constant['Alternative']
|
@@ -55,10 +55,10 @@ module RuboCop
|
|
55
55
|
|
56
56
|
private
|
57
57
|
|
58
|
-
def
|
58
|
+
def constant_name(node, nested_constant_name)
|
59
59
|
return nested_constant_name unless node.namespace.const_type?
|
60
60
|
|
61
|
-
|
61
|
+
constant_name(node.namespace, "#{node.namespace.short_name}::#{nested_constant_name}")
|
62
62
|
end
|
63
63
|
|
64
64
|
def message(good, bad, deprecated_version)
|
@@ -41,8 +41,7 @@ module RuboCop
|
|
41
41
|
include RangeHelp
|
42
42
|
extend AutoCorrector
|
43
43
|
|
44
|
-
MSG = 'Use `%<constant>s.%<method>s(%<replacement_args>s)`'
|
45
|
-
' instead of `%<original>s`.'
|
44
|
+
MSG = 'Use `%<constant>s.%<method>s(%<replacement_args>s)` instead of `%<original>s`.'
|
46
45
|
|
47
46
|
NO_ARG_ALGORITHM = %w[BF DES IDEA RC4].freeze
|
48
47
|
|
@@ -62,9 +61,7 @@ module RuboCop
|
|
62
61
|
|
63
62
|
message = message(node)
|
64
63
|
|
65
|
-
add_offense(node, message: message)
|
66
|
-
autocorrect(corrector, node)
|
67
|
-
end
|
64
|
+
add_offense(node, message: message) { |corrector| autocorrect(corrector, node) }
|
68
65
|
end
|
69
66
|
|
70
67
|
private
|
@@ -104,8 +104,7 @@ module RuboCop
|
|
104
104
|
def offense_range(duplicate_branch)
|
105
105
|
parent = duplicate_branch.parent
|
106
106
|
|
107
|
-
if parent.respond_to?(:else_branch) &&
|
108
|
-
parent.else_branch.equal?(duplicate_branch)
|
107
|
+
if parent.respond_to?(:else_branch) && parent.else_branch.equal?(duplicate_branch)
|
109
108
|
if parent.if_type? && parent.ternary?
|
110
109
|
duplicate_branch.source_range
|
111
110
|
else
|
@@ -50,11 +50,9 @@ module RuboCop
|
|
50
50
|
#
|
51
51
|
# alias bar foo
|
52
52
|
class DuplicateMethods < Base
|
53
|
-
MSG = 'Method `%<method>s` is defined at both %<defined>s and '
|
54
|
-
'%<current>s.'
|
53
|
+
MSG = 'Method `%<method>s` is defined at both %<defined>s and %<current>s.'
|
55
54
|
|
56
|
-
RESTRICT_ON_SEND = %i[alias_method attr_reader attr_writer
|
57
|
-
attr_accessor attr].freeze
|
55
|
+
RESTRICT_ON_SEND = %i[alias_method attr_reader attr_writer attr_accessor attr].freeze
|
58
56
|
|
59
57
|
def initialize(config = nil, options = nil)
|
60
58
|
super
|
@@ -192,9 +190,7 @@ module RuboCop
|
|
192
190
|
namespace, mod_name = *ancestor.defined_module
|
193
191
|
loop do
|
194
192
|
if mod_name == const_name
|
195
|
-
return qualified_name(ancestor.parent_module_name,
|
196
|
-
namespace,
|
197
|
-
mod_name)
|
193
|
+
return qualified_name(ancestor.parent_module_name, namespace, mod_name)
|
198
194
|
end
|
199
195
|
|
200
196
|
break if namespace.nil?
|
@@ -74,9 +74,7 @@ module RuboCop
|
|
74
74
|
return unless first_else
|
75
75
|
return unless first_else.source_range.line == node.loc.else.line
|
76
76
|
|
77
|
-
add_offense(first_else)
|
78
|
-
autocorrect(corrector, node, first_else)
|
79
|
-
end
|
77
|
+
add_offense(first_else) { |corrector| autocorrect(corrector, node, first_else) }
|
80
78
|
end
|
81
79
|
|
82
80
|
def autocorrect(corrector, node, first_else)
|
@@ -7,7 +7,11 @@ module RuboCop
|
|
7
7
|
# Such empty blocks are typically an oversight or we should provide a comment
|
8
8
|
# be clearer what we're aiming for.
|
9
9
|
#
|
10
|
-
# Empty lambdas are ignored by default.
|
10
|
+
# Empty lambdas and procs are ignored by default.
|
11
|
+
#
|
12
|
+
# NOTE: For backwards compatibility, the configuration that allows/disallows
|
13
|
+
# empty lambdas and procs is called `AllowEmptyLambdas`, even though it also
|
14
|
+
# applies to procs.
|
11
15
|
#
|
12
16
|
# @example
|
13
17
|
# # bad
|
@@ -40,6 +44,10 @@ module RuboCop
|
|
40
44
|
# end
|
41
45
|
# (callable || placeholder).call
|
42
46
|
#
|
47
|
+
# proc { }
|
48
|
+
#
|
49
|
+
# Proc.new { }
|
50
|
+
#
|
43
51
|
# @example AllowEmptyLambdas: false
|
44
52
|
# # bad
|
45
53
|
# allow(subject).to receive(:callable).and_return(-> {})
|
@@ -48,12 +56,16 @@ module RuboCop
|
|
48
56
|
# end
|
49
57
|
# (callable || placeholder).call
|
50
58
|
#
|
59
|
+
# proc { }
|
60
|
+
#
|
61
|
+
# Proc.new { }
|
62
|
+
#
|
51
63
|
class EmptyBlock < Base
|
52
64
|
MSG = 'Empty block detected.'
|
53
65
|
|
54
66
|
def on_block(node)
|
55
67
|
return if node.body
|
56
|
-
return if allow_empty_lambdas? && node
|
68
|
+
return if allow_empty_lambdas? && lambda_or_proc?(node)
|
57
69
|
return if cop_config['AllowComments'] && allow_comment?(node)
|
58
70
|
|
59
71
|
add_offense(node)
|
@@ -76,6 +88,10 @@ module RuboCop
|
|
76
88
|
regexp_pattern = "# rubocop : (disable|todo) ([^,],)* (all|#{cop_name})"
|
77
89
|
Regexp.new(regexp_pattern.gsub(' ', '\s*')).match?(comment)
|
78
90
|
end
|
91
|
+
|
92
|
+
def lambda_or_proc?(node)
|
93
|
+
node.lambda? || node.proc?
|
94
|
+
end
|
79
95
|
end
|
80
96
|
end
|
81
97
|
end
|
@@ -50,9 +50,7 @@ module RuboCop
|
|
50
50
|
def on_ensure(node)
|
51
51
|
return if node.body
|
52
52
|
|
53
|
-
add_offense(node.loc.keyword)
|
54
|
-
corrector.remove(node.loc.keyword)
|
55
|
-
end
|
53
|
+
add_offense(node.loc.keyword) { |corrector| corrector.remove(node.loc.keyword) }
|
56
54
|
end
|
57
55
|
end
|
58
56
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# This cop checks for the presence of `in` pattern branches without a body.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# case condition
|
12
|
+
# in [a]
|
13
|
+
# do_something
|
14
|
+
# in [a, b]
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# case condition
|
19
|
+
# in [a]
|
20
|
+
# do_something
|
21
|
+
# in [a, b]
|
22
|
+
# nil
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# @example AllowComments: true (default)
|
26
|
+
#
|
27
|
+
# # good
|
28
|
+
# case condition
|
29
|
+
# in [a]
|
30
|
+
# do_something
|
31
|
+
# in [a, b]
|
32
|
+
# # noop
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# @example AllowComments: false
|
36
|
+
#
|
37
|
+
# # bad
|
38
|
+
# case condition
|
39
|
+
# in [a]
|
40
|
+
# do_something
|
41
|
+
# in [a, b]
|
42
|
+
# # noop
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
class EmptyInPattern < Base
|
46
|
+
extend TargetRubyVersion
|
47
|
+
|
48
|
+
MSG = 'Avoid `in` branches without a body.'
|
49
|
+
|
50
|
+
minimum_target_ruby_version 2.7
|
51
|
+
|
52
|
+
def on_case_match(node)
|
53
|
+
node.in_pattern_branches.each do |branch|
|
54
|
+
next if branch.body || cop_config['AllowComments'] && comment_lines?(node)
|
55
|
+
|
56
|
+
add_offense(branch)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|