rubocop 0.89.1 → 0.93.0
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 +2 -2
- data/config/default.yml +160 -14
- data/lib/rubocop.rb +33 -5
- data/lib/rubocop/cached_data.rb +3 -1
- data/lib/rubocop/cli/command.rb +1 -0
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +1 -0
- data/lib/rubocop/cli/command/base.rb +1 -0
- data/lib/rubocop/cli/command/execute_runner.rb +9 -0
- data/lib/rubocop/cli/command/init_dotfile.rb +1 -0
- data/lib/rubocop/cli/command/show_cops.rb +1 -0
- data/lib/rubocop/cli/command/version.rb +1 -0
- data/lib/rubocop/cli/environment.rb +1 -0
- data/lib/rubocop/comment_config.rb +14 -5
- data/lib/rubocop/config_loader.rb +20 -9
- data/lib/rubocop/config_loader_resolver.rb +1 -0
- data/lib/rubocop/config_obsoletion.rb +1 -0
- data/lib/rubocop/config_regeneration.rb +33 -0
- data/lib/rubocop/config_store.rb +3 -3
- data/lib/rubocop/config_validator.rb +3 -0
- data/lib/rubocop/cop/base.rb +23 -0
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +5 -1
- data/lib/rubocop/cop/bundler/gem_comment.rb +8 -3
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -0
- data/lib/rubocop/cop/commissioner.rb +47 -7
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +4 -4
- data/lib/rubocop/cop/correctors/condition_corrector.rb +3 -5
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +9 -10
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +4 -4
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +8 -3
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +5 -8
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +4 -9
- data/lib/rubocop/cop/correctors/punctuation_corrector.rb +8 -10
- data/lib/rubocop/cop/documentation.rb +22 -0
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +10 -10
- data/lib/rubocop/cop/generator.rb +2 -1
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -0
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/begin_end_alignment.rb +77 -0
- data/lib/rubocop/cop/layout/block_alignment.rb +23 -19
- data/lib/rubocop/cop/layout/case_indentation.rb +4 -7
- data/lib/rubocop/cop/layout/class_structure.rb +11 -10
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +4 -6
- data/lib/rubocop/cop/layout/condition_position.rb +13 -15
- data/lib/rubocop/cop/layout/def_end_alignment.rb +8 -5
- data/lib/rubocop/cop/layout/dot_position.rb +21 -20
- data/lib/rubocop/cop/layout/empty_comment.rb +30 -23
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +21 -18
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +13 -13
- data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +136 -0
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +21 -23
- data/lib/rubocop/cop/layout/empty_lines.rb +6 -7
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +17 -14
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +7 -8
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +5 -8
- data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +2 -5
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +2 -5
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +2 -5
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +3 -7
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +2 -5
- data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +2 -5
- data/lib/rubocop/cop/layout/end_alignment.rb +11 -17
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +2 -5
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +2 -5
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +4 -8
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +2 -5
- data/lib/rubocop/cop/layout/hash_alignment.rb +17 -20
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +15 -14
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +14 -11
- data/lib/rubocop/cop/layout/initial_indentation.rb +6 -7
- data/lib/rubocop/cop/layout/leading_comment_space.rb +11 -9
- data/lib/rubocop/cop/layout/leading_empty_lines.rb +6 -11
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +2 -5
- data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +2 -5
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +10 -14
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +21 -19
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +2 -5
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +2 -5
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +5 -9
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +2 -5
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +2 -5
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +41 -22
- data/lib/rubocop/cop/layout/space_after_colon.rb +11 -7
- data/lib/rubocop/cop/layout/space_after_comma.rb +2 -5
- data/lib/rubocop/cop/layout/space_after_method_name.rb +5 -6
- data/lib/rubocop/cop/layout/space_after_not.rb +9 -11
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +2 -5
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +17 -21
- data/lib/rubocop/cop/layout/space_around_keyword.rb +17 -18
- data/lib/rubocop/cop/layout/space_around_operators.rb +17 -16
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +23 -22
- data/lib/rubocop/cop/layout/space_before_comma.rb +3 -5
- data/lib/rubocop/cop/layout/space_before_comment.rb +10 -7
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +7 -7
- data/lib/rubocop/cop/layout/space_before_semicolon.rb +2 -5
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -17
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +20 -23
- data/lib/rubocop/cop/layout/space_inside_array_percent_literal.rb +3 -8
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +13 -16
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +19 -37
- data/lib/rubocop/cop/layout/space_inside_parens.rb +9 -14
- data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +5 -10
- data/lib/rubocop/cop/layout/space_inside_range_literal.rb +8 -17
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +16 -24
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +12 -13
- data/lib/rubocop/cop/layout/trailing_empty_lines.rb +10 -15
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +11 -11
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +2 -0
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +2 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +15 -1
- data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -2
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +1 -1
- data/lib/rubocop/cop/lint/boolean_symbol.rb +3 -0
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +74 -0
- data/lib/rubocop/cop/lint/constant_resolution.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +2 -3
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -3
- data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -4
- data/lib/rubocop/cop/lint/duplicate_require.rb +46 -0
- data/lib/rubocop/cop/lint/duplicate_rescue_exception.rb +2 -15
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
- data/lib/rubocop/cop/lint/empty_file.rb +50 -0
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +2 -0
- data/lib/rubocop/cop/lint/float_comparison.rb +2 -2
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +2 -2
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +37 -0
- data/lib/rubocop/cop/lint/identity_comparison.rb +51 -0
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +2 -5
- data/lib/rubocop/cop/lint/inherit_exception.rb +2 -2
- data/lib/rubocop/cop/lint/missing_super.rb +2 -2
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +3 -35
- data/lib/rubocop/cop/lint/multiple_comparison.rb +3 -1
- data/lib/rubocop/cop/lint/number_conversion.rb +1 -0
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +9 -20
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/percent_string_array.rb +8 -12
- data/lib/rubocop/cop/lint/raise_exception.rb +1 -0
- data/lib/rubocop/cop/lint/rand_one.rb +2 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +22 -12
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +14 -4
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +45 -0
- data/lib/rubocop/cop/lint/rescue_type.rb +0 -1
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +3 -1
- data/lib/rubocop/cop/lint/shadowed_exception.rb +6 -6
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +4 -4
- data/lib/rubocop/cop/lint/struct_new_override.rb +1 -0
- data/lib/rubocop/cop/lint/to_json.rb +16 -5
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +57 -0
- data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -6
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +3 -1
- data/lib/rubocop/cop/lint/uri_regexp.rb +2 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +3 -9
- data/lib/rubocop/cop/lint/useless_method_definition.rb +70 -0
- data/lib/rubocop/cop/lint/useless_times.rb +106 -0
- data/lib/rubocop/cop/metrics/block_length.rb +3 -1
- data/lib/rubocop/cop/metrics/class_length.rb +8 -6
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +27 -16
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -0
- data/lib/rubocop/cop/mixin/alignment.rb +3 -0
- data/lib/rubocop/cop/mixin/allowed_methods.rb +2 -0
- data/lib/rubocop/cop/mixin/annotation_comment.rb +5 -0
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +16 -7
- data/lib/rubocop/cop/mixin/comments_help.rb +48 -0
- data/lib/rubocop/cop/mixin/configurable_naming.rb +2 -2
- data/lib/rubocop/cop/mixin/configurable_numbering.rb +3 -3
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +8 -7
- data/lib/rubocop/cop/mixin/empty_parameter.rb +3 -1
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +12 -1
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +3 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +27 -2
- data/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb +3 -1
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +12 -10
- data/lib/rubocop/cop/mixin/negative_conditional.rb +2 -2
- data/lib/rubocop/cop/mixin/percent_array.rb +14 -3
- data/lib/rubocop/cop/mixin/rescue_node.rb +11 -1
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +4 -3
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +4 -3
- data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -3
- data/lib/rubocop/cop/mixin/surrounding_space.rb +8 -4
- data/lib/rubocop/cop/mixin/trailing_comma.rb +7 -7
- data/lib/rubocop/cop/mixin/visibility_help.rb +4 -16
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/file_name.rb +1 -1
- data/lib/rubocop/cop/offense.rb +16 -2
- data/lib/rubocop/cop/security/eval.rb +1 -0
- data/lib/rubocop/cop/security/json_load.rb +1 -0
- data/lib/rubocop/cop/security/marshal_load.rb +1 -0
- data/lib/rubocop/cop/security/open.rb +1 -0
- data/lib/rubocop/cop/security/yaml_load.rb +1 -0
- data/lib/rubocop/cop/severity.rb +0 -8
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +7 -11
- data/lib/rubocop/cop/style/accessor_grouping.rb +3 -0
- data/lib/rubocop/cop/style/alias.rb +2 -0
- data/lib/rubocop/cop/style/array_coercion.rb +4 -0
- data/lib/rubocop/cop/style/array_join.rb +1 -0
- data/lib/rubocop/cop/style/attr.rb +1 -0
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +2 -0
- data/lib/rubocop/cop/style/case_equality.rb +11 -3
- data/lib/rubocop/cop/style/case_like_if.rb +40 -8
- data/lib/rubocop/cop/style/class_and_module_children.rb +2 -0
- data/lib/rubocop/cop/style/class_check.rb +6 -9
- data/lib/rubocop/cop/style/class_equality_comparison.rb +49 -0
- data/lib/rubocop/cop/style/class_methods_definitions.rb +157 -0
- data/lib/rubocop/cop/style/class_vars.rb +1 -2
- data/lib/rubocop/cop/style/combinable_loops.rb +91 -0
- data/lib/rubocop/cop/style/comment_annotation.rb +6 -0
- data/lib/rubocop/cop/style/commented_keyword.rb +7 -8
- data/lib/rubocop/cop/style/conditional_assignment.rb +49 -60
- data/lib/rubocop/cop/style/date_time.rb +12 -1
- data/lib/rubocop/cop/style/dir.rb +1 -0
- data/lib/rubocop/cop/style/double_negation.rb +1 -0
- data/lib/rubocop/cop/style/empty_block_parameter.rb +9 -10
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +9 -10
- data/lib/rubocop/cop/style/empty_literal.rb +3 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -3
- data/lib/rubocop/cop/style/even_odd.rb +1 -0
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
- data/lib/rubocop/cop/style/explicit_block_argument.rb +7 -3
- data/lib/rubocop/cop/style/float_division.rb +2 -0
- data/lib/rubocop/cop/style/for.rb +0 -4
- data/lib/rubocop/cop/style/format_string.rb +1 -4
- data/lib/rubocop/cop/style/format_string_token.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +1 -0
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +24 -5
- data/lib/rubocop/cop/style/hash_syntax.rb +6 -5
- data/lib/rubocop/cop/style/hash_transform_keys.rb +16 -9
- data/lib/rubocop/cop/style/hash_transform_values.rb +16 -9
- data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -6
- data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -0
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +53 -0
- data/lib/rubocop/cop/style/lambda_call.rb +3 -1
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +10 -1
- data/lib/rubocop/cop/style/method_def_parentheses.rb +0 -4
- data/lib/rubocop/cop/style/mixin_usage.rb +8 -27
- data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -2
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +14 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +3 -2
- data/lib/rubocop/cop/style/negated_if.rb +6 -6
- data/lib/rubocop/cop/style/negated_unless.rb +6 -6
- data/lib/rubocop/cop/style/negated_while.rb +7 -15
- data/lib/rubocop/cop/style/nested_modifier.rb +10 -13
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +11 -11
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +16 -16
- data/lib/rubocop/cop/style/next.rb +10 -14
- data/lib/rubocop/cop/style/nil_comparison.rb +13 -11
- data/lib/rubocop/cop/style/non_nil_check.rb +34 -26
- data/lib/rubocop/cop/style/not.rb +20 -26
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +4 -9
- data/lib/rubocop/cop/style/numeric_predicate.rb +5 -14
- data/lib/rubocop/cop/style/one_line_conditional.rb +73 -23
- data/lib/rubocop/cop/style/option_hash.rb +1 -1
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
- data/lib/rubocop/cop/style/optional_boolean_parameter.rb +12 -1
- data/lib/rubocop/cop/style/or_assignment.rb +13 -10
- data/lib/rubocop/cop/style/parallel_assignment.rb +14 -14
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +6 -6
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +13 -19
- data/lib/rubocop/cop/style/percent_q_literals.rb +8 -10
- data/lib/rubocop/cop/style/perl_backrefs.rb +8 -10
- data/lib/rubocop/cop/style/preferred_hash_methods.rb +11 -14
- data/lib/rubocop/cop/style/proc.rb +6 -6
- data/lib/rubocop/cop/style/raise_args.rb +12 -24
- data/lib/rubocop/cop/style/random_with_offset.rb +19 -19
- data/lib/rubocop/cop/style/redundant_assignment.rb +8 -18
- data/lib/rubocop/cop/style/redundant_begin.rb +28 -12
- data/lib/rubocop/cop/style/redundant_capital_w.rb +6 -9
- data/lib/rubocop/cop/style/redundant_condition.rb +10 -7
- data/lib/rubocop/cop/style/redundant_conditional.rb +4 -5
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -3
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +3 -12
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +9 -8
- data/lib/rubocop/cop/style/redundant_freeze.rb +5 -7
- data/lib/rubocop/cop/style/redundant_interpolation.rb +31 -25
- data/lib/rubocop/cop/style/redundant_parentheses.rb +21 -15
- data/lib/rubocop/cop/style/redundant_percent_q.rb +9 -11
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +44 -36
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +13 -29
- data/lib/rubocop/cop/style/redundant_return.rb +17 -17
- data/lib/rubocop/cop/style/redundant_self.rb +9 -11
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +116 -0
- data/lib/rubocop/cop/style/redundant_sort.rb +12 -29
- data/lib/rubocop/cop/style/redundant_sort_by.rb +5 -9
- data/lib/rubocop/cop/style/regexp_literal.rb +10 -21
- data/lib/rubocop/cop/style/rescue_modifier.rb +29 -9
- data/lib/rubocop/cop/style/rescue_standard_error.rb +20 -16
- data/lib/rubocop/cop/style/return_nil.rb +5 -5
- data/lib/rubocop/cop/style/safe_navigation.rb +18 -12
- data/lib/rubocop/cop/style/sample.rb +12 -14
- data/lib/rubocop/cop/style/self_assignment.rb +26 -22
- data/lib/rubocop/cop/style/semicolon.rb +6 -9
- data/lib/rubocop/cop/style/send.rb +4 -5
- data/lib/rubocop/cop/style/signal_exception.rb +23 -19
- data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
- data/lib/rubocop/cop/style/single_line_block_params.rb +4 -2
- data/lib/rubocop/cop/style/single_line_methods.rb +17 -16
- data/lib/rubocop/cop/style/slicing_with_range.rb +6 -8
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +66 -0
- data/lib/rubocop/cop/style/special_global_vars.rb +10 -15
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +17 -21
- data/lib/rubocop/cop/style/stderr_puts.rb +5 -6
- data/lib/rubocop/cop/style/string_concatenation.rb +17 -3
- data/lib/rubocop/cop/style/string_hash_keys.rb +6 -7
- data/lib/rubocop/cop/style/string_methods.rb +7 -17
- data/lib/rubocop/cop/style/strip.rb +9 -14
- data/lib/rubocop/cop/style/struct_inheritance.rb +3 -6
- data/lib/rubocop/cop/style/symbol_array.rb +5 -16
- data/lib/rubocop/cop/style/symbol_literal.rb +4 -6
- data/lib/rubocop/cop/style/symbol_proc.rb +14 -18
- data/lib/rubocop/cop/style/ternary_parentheses.rb +22 -22
- data/lib/rubocop/cop/style/trailing_body_on_class.rb +3 -6
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +4 -7
- data/lib/rubocop/cop/style/trailing_body_on_module.rb +3 -6
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +2 -5
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +2 -5
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +11 -9
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +2 -5
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +8 -17
- data/lib/rubocop/cop/style/trivial_accessors.rb +26 -30
- data/lib/rubocop/cop/style/unless_else.rb +5 -8
- data/lib/rubocop/cop/style/unpack_first.rb +5 -8
- data/lib/rubocop/cop/style/variable_interpolation.rb +7 -10
- data/lib/rubocop/cop/style/when_then.rb +4 -6
- data/lib/rubocop/cop/style/while_until_do.rb +6 -16
- data/lib/rubocop/cop/style/while_until_modifier.rb +6 -20
- data/lib/rubocop/cop/style/word_array.rb +5 -23
- data/lib/rubocop/cop/style/yoda_condition.rb +4 -15
- data/lib/rubocop/cop/style/zero_length_predicate.rb +12 -18
- data/lib/rubocop/cop/team.rb +1 -0
- data/lib/rubocop/cop/util.rb +1 -2
- data/lib/rubocop/cop/utils/format_string.rb +3 -5
- data/lib/rubocop/cop/variable_force.rb +2 -0
- data/lib/rubocop/cop/variable_force/branch.rb +0 -4
- data/lib/rubocop/cops_documentation_generator.rb +4 -2
- data/lib/rubocop/core_ext/string.rb +2 -2
- data/lib/rubocop/directive_comment.rb +32 -0
- data/lib/rubocop/ext/regexp_node.rb +62 -0
- data/lib/rubocop/file_finder.rb +1 -0
- data/lib/rubocop/formatter/auto_gen_config_formatter.rb +2 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +12 -5
- data/lib/rubocop/formatter/html_formatter.rb +2 -0
- data/lib/rubocop/formatter/progress_formatter.rb +2 -1
- data/lib/rubocop/formatter/quiet_formatter.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +36 -6
- data/lib/rubocop/name_similarity.rb +1 -0
- data/lib/rubocop/options.rb +40 -17
- data/lib/rubocop/remote_config.rb +1 -0
- data/lib/rubocop/result_cache.rb +39 -15
- data/lib/rubocop/rspec/cop_helper.rb +5 -2
- data/lib/rubocop/rspec/expect_offense.rb +14 -9
- data/lib/rubocop/rspec/shared_contexts.rb +12 -0
- data/lib/rubocop/runner.rb +38 -18
- data/lib/rubocop/string_interpreter.rb +3 -0
- data/lib/rubocop/target_finder.rb +28 -26
- data/lib/rubocop/target_ruby.rb +7 -1
- data/lib/rubocop/version.rb +7 -1
- data/lib/rubocop/yaml_duplication_checker.rb +1 -0
- metadata +31 -17
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +0 -43
- data/lib/rubocop/cop/tokens_util.rb +0 -84
@@ -33,27 +33,14 @@ module RuboCop
|
|
33
33
|
def on_rescue(node)
|
34
34
|
return if rescue_modifier?(node)
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
resbodies.each_with_object(Set.new) do |resbody, previous|
|
39
|
-
rescued_exceptions = rescued_exceptions(resbody)
|
36
|
+
node.resbody_branches.each_with_object(Set.new) do |resbody, previous|
|
37
|
+
rescued_exceptions = resbody.exceptions
|
40
38
|
|
41
39
|
rescued_exceptions.each do |exception|
|
42
40
|
add_offense(exception) unless previous.add?(exception)
|
43
41
|
end
|
44
42
|
end
|
45
43
|
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def rescued_exceptions(resbody)
|
50
|
-
rescue_group, = *resbody
|
51
|
-
if rescue_group
|
52
|
-
rescue_group.values
|
53
|
-
else
|
54
|
-
[]
|
55
|
-
end
|
56
|
-
end
|
57
44
|
end
|
58
45
|
end
|
59
46
|
end
|
@@ -23,6 +23,7 @@ module RuboCop
|
|
23
23
|
# sum = numbers.each_with_object(num) { |e, a| a += e }
|
24
24
|
class EachWithObjectArgument < Base
|
25
25
|
MSG = 'The argument to each_with_object cannot be immutable.'
|
26
|
+
RESTRICT_ON_SEND = %i[each_with_object].freeze
|
26
27
|
|
27
28
|
def_node_matcher :each_with_object?, <<~PATTERN
|
28
29
|
({send csend} _ :each_with_object $_)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# This cop enforces that Ruby source files are not empty.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# # Empty file
|
11
|
+
#
|
12
|
+
# # good
|
13
|
+
# # File containing non commented source lines
|
14
|
+
#
|
15
|
+
# @example AllowComments: true (default)
|
16
|
+
# # good
|
17
|
+
# # File consisting only of comments
|
18
|
+
#
|
19
|
+
# @example AllowComments: false
|
20
|
+
# # bad
|
21
|
+
# # File consisting only of comments
|
22
|
+
#
|
23
|
+
class EmptyFile < Base
|
24
|
+
include RangeHelp
|
25
|
+
|
26
|
+
MSG = 'Empty file detected.'
|
27
|
+
|
28
|
+
def on_new_investigation
|
29
|
+
add_global_offense(MSG) if offending?
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def offending?
|
35
|
+
empty_file? || (!cop_config['AllowComments'] && contains_only_comments?)
|
36
|
+
end
|
37
|
+
|
38
|
+
def empty_file?
|
39
|
+
processed_source.buffer.source.empty?
|
40
|
+
end
|
41
|
+
|
42
|
+
def contains_only_comments?
|
43
|
+
processed_source.lines.all? do |line|
|
44
|
+
line.blank? || comment_line?(line)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -35,9 +35,9 @@ module RuboCop
|
|
35
35
|
FLOAT_RETURNING_METHODS = %i[to_f Float fdiv].freeze
|
36
36
|
FLOAT_INSTANCE_METHODS = %i[@- abs magnitude modulo next_float prev_float quo].to_set.freeze
|
37
37
|
|
38
|
-
|
39
|
-
return unless EQUALITY_METHODS.include?(node.method_name)
|
38
|
+
RESTRICT_ON_SEND = EQUALITY_METHODS
|
40
39
|
|
40
|
+
def on_send(node)
|
41
41
|
lhs, _method, rhs = *node
|
42
42
|
add_offense(node) if float?(lhs) || float?(rhs)
|
43
43
|
end
|
@@ -44,10 +44,10 @@ module RuboCop
|
|
44
44
|
KERNEL = 'Kernel'
|
45
45
|
SHOVEL = '<<'
|
46
46
|
STRING_TYPES = %i[str dstr].freeze
|
47
|
-
|
47
|
+
RESTRICT_ON_SEND = %i[format sprintf %].freeze
|
48
48
|
|
49
49
|
def on_send(node)
|
50
|
-
return unless
|
50
|
+
return unless format_string?(node)
|
51
51
|
|
52
52
|
if invalid_format_string?(node)
|
53
53
|
add_offense(node.loc.selector, message: MSG_INVALID)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# Prefer using `Hash#compare_by_identity` than using `object_id` for hash keys.
|
7
|
+
#
|
8
|
+
# This cop is marked as unsafe as a hash possibly can contain other keys
|
9
|
+
# besides `object_id`s.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# # bad
|
13
|
+
# hash = {}
|
14
|
+
# hash[foo.object_id] = :bar
|
15
|
+
# hash.key?(baz.object_id)
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# hash = {}.compare_by_identity
|
19
|
+
# hash[foo] = :bar
|
20
|
+
# hash.key?(baz)
|
21
|
+
#
|
22
|
+
class HashCompareByIdentity < Base
|
23
|
+
RESTRICT_ON_SEND = %i[key? has_key? fetch [] []=].freeze
|
24
|
+
|
25
|
+
MSG = 'Use `Hash#compare_by_identity` instead of using `object_id` for keys.'
|
26
|
+
|
27
|
+
def_node_matcher :id_as_hash_key?, <<~PATTERN
|
28
|
+
(send _ {:key? :has_key? :fetch :[] :[]=} (send _ :object_id) ...)
|
29
|
+
PATTERN
|
30
|
+
|
31
|
+
def on_send(node)
|
32
|
+
add_offense(node) if id_as_hash_key?(node)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
#
|
7
|
+
# Prefer `equal?` over `==` when comparing `object_id`.
|
8
|
+
#
|
9
|
+
# `Object#equal?` is provided to compare objects for identity, and in contrast
|
10
|
+
# `Object#==` is provided for the purpose of doing value comparison.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# # bad
|
14
|
+
# foo.object_id == bar.object_id
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# foo.equal?(bar)
|
18
|
+
#
|
19
|
+
class IdentityComparison < Base
|
20
|
+
extend AutoCorrector
|
21
|
+
|
22
|
+
MSG = 'Use `equal?` instead `==` when comparing `object_id`.'
|
23
|
+
RESTRICT_ON_SEND = %i[==].freeze
|
24
|
+
|
25
|
+
def on_send(node)
|
26
|
+
return unless compare_between_object_id_by_double_equal?(node)
|
27
|
+
|
28
|
+
add_offense(node) do |corrector|
|
29
|
+
receiver = node.receiver.receiver
|
30
|
+
argument = node.first_argument.receiver
|
31
|
+
return unless receiver && argument
|
32
|
+
|
33
|
+
replacement = "#{receiver.source}.equal?(#{argument.source})"
|
34
|
+
|
35
|
+
corrector.replace(node, replacement)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def compare_between_object_id_by_double_equal?(node)
|
42
|
+
object_id_method?(node.receiver) && object_id_method?(node.first_argument)
|
43
|
+
end
|
44
|
+
|
45
|
+
def object_id_method?(node)
|
46
|
+
node.send_type? && node.method?(:object_id)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -58,12 +58,9 @@ module RuboCop
|
|
58
58
|
PATTERN
|
59
59
|
|
60
60
|
def on_class(node)
|
61
|
-
check_node(node.
|
62
|
-
end
|
63
|
-
|
64
|
-
def on_module(node)
|
65
|
-
check_node(node.children[1]) # module body
|
61
|
+
check_node(node.body)
|
66
62
|
end
|
63
|
+
alias on_module on_class
|
67
64
|
|
68
65
|
private
|
69
66
|
|
@@ -56,6 +56,8 @@ module RuboCop
|
|
56
56
|
SystemExit
|
57
57
|
].freeze
|
58
58
|
|
59
|
+
RESTRICT_ON_SEND = %i[new].freeze
|
60
|
+
|
59
61
|
def_node_matcher :class_new_call?, <<~PATTERN
|
60
62
|
(send
|
61
63
|
(const {cbase nil?} :Class) :new
|
@@ -74,8 +76,6 @@ module RuboCop
|
|
74
76
|
end
|
75
77
|
|
76
78
|
def on_send(node)
|
77
|
-
return unless node.method?(:new)
|
78
|
-
|
79
79
|
constant = class_new_call?(node)
|
80
80
|
return unless constant && illegal_class_name?(constant)
|
81
81
|
|
@@ -56,8 +56,8 @@ module RuboCop
|
|
56
56
|
def on_def(node)
|
57
57
|
return unless offender?(node)
|
58
58
|
|
59
|
-
if node.method?(:initialize)
|
60
|
-
add_offense(node, message: CONSTRUCTOR_MSG)
|
59
|
+
if node.method?(:initialize) && inside_class_with_stateful_parent?(node)
|
60
|
+
add_offense(node, message: CONSTRUCTOR_MSG)
|
61
61
|
elsif callback_method_def?(node)
|
62
62
|
add_offense(node, message: CALLBACK_MSG)
|
63
63
|
end
|
@@ -25,44 +25,12 @@ module RuboCop
|
|
25
25
|
'in a Regexp literal.'
|
26
26
|
|
27
27
|
def on_regexp(node)
|
28
|
-
return if
|
29
|
-
|
30
|
-
|
31
|
-
tree = Regexp::Parser.parse(node.content)
|
32
|
-
# Returns if a regular expression that cannot be processed by regexp_parser gem.
|
33
|
-
# https://github.com/rubocop-hq/rubocop/issues/8083
|
34
|
-
rescue Regexp::Scanner::ScannerError
|
35
|
-
return
|
36
|
-
end
|
37
|
-
|
38
|
-
return unless named_capture?(tree)
|
39
|
-
return unless numbered_capture?(tree)
|
28
|
+
return if node.interpolation?
|
29
|
+
return if node.each_capture(named: false).none?
|
30
|
+
return if node.each_capture(named: true).none?
|
40
31
|
|
41
32
|
add_offense(node)
|
42
33
|
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def contain_non_literal?(node)
|
47
|
-
if node.respond_to?(:type) && (node.variable? || node.send_type? || node.const_type?)
|
48
|
-
return true
|
49
|
-
end
|
50
|
-
return false unless node.respond_to?(:children)
|
51
|
-
|
52
|
-
node.children.any? { |child| contain_non_literal?(child) }
|
53
|
-
end
|
54
|
-
|
55
|
-
def named_capture?(tree)
|
56
|
-
tree.each_expression.any? do |e|
|
57
|
-
e.instance_of?(Regexp::Expression::Group::Capture)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def numbered_capture?(tree)
|
62
|
-
tree.each_expression.any? do |e|
|
63
|
-
e.instance_of?(Regexp::Expression::Group::Named)
|
64
|
-
end
|
65
|
-
end
|
66
34
|
end
|
67
35
|
end
|
68
36
|
end
|
@@ -25,9 +25,11 @@ module RuboCop
|
|
25
25
|
extend AutoCorrector
|
26
26
|
|
27
27
|
MSG = 'Use the `&&` operator to compare multiple values.'
|
28
|
+
COMPARISON_METHODS = %i[< > <= >=].freeze
|
29
|
+
RESTRICT_ON_SEND = COMPARISON_METHODS
|
28
30
|
|
29
31
|
def_node_matcher :multiple_compare?, <<~PATTERN
|
30
|
-
(send (send _ {:< :> :<= :>=} $_) {
|
32
|
+
(send (send _ {:< :> :<= :>=} $_) {:#{COMPARISON_METHODS.join(' :')}} _)
|
31
33
|
PATTERN
|
32
34
|
|
33
35
|
def on_send(node)
|
@@ -32,6 +32,7 @@ module RuboCop
|
|
32
32
|
'class parsing, instead of using '\
|
33
33
|
'%<number_object>s.%<to_method>s, use stricter '\
|
34
34
|
'%<corrected_method>s.'
|
35
|
+
RESTRICT_ON_SEND = CONVERSION_METHOD_CLASS_MAPPING.keys.freeze
|
35
36
|
|
36
37
|
def_node_matcher :to_method, <<~PATTERN
|
37
38
|
(send $_ ${:to_i :to_f :to_c})
|
@@ -25,6 +25,7 @@ module RuboCop
|
|
25
25
|
REGEXP_ARGUMENT_METHODS = %i[=~ match grep gsub gsub! sub sub! [] slice slice! index rindex
|
26
26
|
scan partition rpartition start_with? end_with?].to_set.freeze
|
27
27
|
REGEXP_CAPTURE_METHODS = (REGEXP_RECEIVER_METHODS + REGEXP_ARGUMENT_METHODS).freeze
|
28
|
+
RESTRICT_ON_SEND = REGEXP_CAPTURE_METHODS
|
28
29
|
|
29
30
|
def on_new_investigation
|
30
31
|
@valid_ref = 0
|
@@ -35,8 +36,6 @@ module RuboCop
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def on_send(node)
|
38
|
-
return unless REGEXP_CAPTURE_METHODS.include?(node.method_name)
|
39
|
-
|
40
39
|
@valid_ref = nil
|
41
40
|
|
42
41
|
if node.receiver&.regexp_type?
|
@@ -64,25 +63,15 @@ module RuboCop
|
|
64
63
|
|
65
64
|
private
|
66
65
|
|
67
|
-
def check_regexp(
|
68
|
-
return if
|
69
|
-
|
70
|
-
tree = Regexp::Parser.parse(regexp.content)
|
71
|
-
@valid_ref = regexp_captures(tree)
|
72
|
-
end
|
73
|
-
|
74
|
-
def contain_non_literal?(node)
|
75
|
-
node.children.size != 2 || !node.children.first.str_type?
|
76
|
-
end
|
66
|
+
def check_regexp(node)
|
67
|
+
return if node.interpolation?
|
77
68
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
named_capture.positive? ? named_capture : numbered_capture
|
69
|
+
named_capture = node.each_capture(named: true).count
|
70
|
+
@valid_ref = if named_capture.positive?
|
71
|
+
named_capture
|
72
|
+
else
|
73
|
+
node.each_capture(named: false).count
|
74
|
+
end
|
86
75
|
end
|
87
76
|
end
|
88
77
|
end
|
@@ -39,23 +39,19 @@ module RuboCop
|
|
39
39
|
return unless contains_quotes_or_commas?(node)
|
40
40
|
|
41
41
|
add_offense(node) do |corrector|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
42
|
+
node.each_value do |value|
|
43
|
+
range = value.loc.expression
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
range = value.loc.expression
|
45
|
+
match = range.source.match(TRAILING_QUOTE)
|
46
|
+
corrector.remove_trailing(range, match[0].length) if match
|
51
47
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
corrector.remove_leading(range, 1) if LEADING_QUOTE.match?(range.source)
|
48
|
+
corrector.remove_leading(range, 1) if LEADING_QUOTE.match?(range.source)
|
49
|
+
end
|
56
50
|
end
|
57
51
|
end
|
58
52
|
|
53
|
+
private
|
54
|
+
|
59
55
|
def contains_quotes_or_commas?(node)
|
60
56
|
node.values.any? do |value|
|
61
57
|
literal = value.children.first.to_s.scrub
|
@@ -23,13 +23,14 @@ module RuboCop
|
|
23
23
|
class RandOne < Base
|
24
24
|
MSG = '`%<method>s` always returns `0`. ' \
|
25
25
|
'Perhaps you meant `rand(2)` or `rand`?'
|
26
|
+
RESTRICT_ON_SEND = %i[rand].freeze
|
26
27
|
|
27
28
|
def_node_matcher :rand_one?, <<~PATTERN
|
28
29
|
(send {(const {nil? cbase} :Kernel) nil?} :rand {(int {-1 1}) (float {-1.0 1.0})})
|
29
30
|
PATTERN
|
30
31
|
|
31
32
|
def on_send(node)
|
32
|
-
return unless
|
33
|
+
return unless rand_one?(node)
|
33
34
|
|
34
35
|
add_offense(node)
|
35
36
|
end
|