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
@@ -27,11 +27,12 @@ module RuboCop
|
|
27
27
|
#
|
28
28
|
# # bad
|
29
29
|
# %w[foo bar baz]
|
30
|
-
class WordArray <
|
30
|
+
class WordArray < Base
|
31
31
|
include ArrayMinSize
|
32
32
|
include ArraySyntax
|
33
33
|
include ConfigurableEnforcedStyle
|
34
34
|
include PercentArray
|
35
|
+
extend AutoCorrector
|
35
36
|
|
36
37
|
PERCENT_MSG = 'Use `%w` or `%W` for an array of words.'
|
37
38
|
ARRAY_MSG = 'Use `[]` for an array of words.'
|
@@ -44,31 +45,14 @@ module RuboCop
|
|
44
45
|
if bracketed_array_of?(:str, node)
|
45
46
|
return if complex_content?(node.values)
|
46
47
|
|
47
|
-
check_bracketed_array(node)
|
48
|
+
check_bracketed_array(node, 'w')
|
48
49
|
elsif node.percent_literal?(:string)
|
49
50
|
check_percent_array(node)
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
def autocorrect(node)
|
54
|
-
if style == :percent
|
55
|
-
PercentLiteralCorrector
|
56
|
-
.new(@config, @preferred_delimiters)
|
57
|
-
.correct(node, 'w')
|
58
|
-
else
|
59
|
-
correct_bracketed(node)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
54
|
private
|
64
55
|
|
65
|
-
def check_bracketed_array(node)
|
66
|
-
return if allowed_bracket_array?(node)
|
67
|
-
|
68
|
-
array_style_detected(:brackets, node.values.size)
|
69
|
-
add_offense(node) if style == :percent
|
70
|
-
end
|
71
|
-
|
72
56
|
def complex_content?(strings)
|
73
57
|
strings.any? do |s|
|
74
58
|
string = s.str_content.dup.force_encoding(::Encoding::UTF_8)
|
@@ -81,7 +65,7 @@ module RuboCop
|
|
81
65
|
Regexp.new(cop_config['WordRegex'])
|
82
66
|
end
|
83
67
|
|
84
|
-
def correct_bracketed(node)
|
68
|
+
def correct_bracketed(corrector, node)
|
85
69
|
words = node.children.map do |word|
|
86
70
|
if word.dstr_type?
|
87
71
|
string_literal = to_string_literal(word.source)
|
@@ -92,9 +76,7 @@ module RuboCop
|
|
92
76
|
end
|
93
77
|
end
|
94
78
|
|
95
|
-
|
96
|
-
corrector.replace(node, "[#{words.join(', ')}]")
|
97
|
-
end
|
79
|
+
corrector.replace(node, "[#{words.join(', ')}]")
|
98
80
|
end
|
99
81
|
end
|
100
82
|
end
|
@@ -52,9 +52,10 @@ module RuboCop
|
|
52
52
|
# # good
|
53
53
|
# 99 == foo
|
54
54
|
# "bar" != foo
|
55
|
-
class YodaCondition <
|
55
|
+
class YodaCondition < Base
|
56
56
|
include ConfigurableEnforcedStyle
|
57
57
|
include RangeHelp
|
58
|
+
extend AutoCorrector
|
58
59
|
|
59
60
|
MSG = 'Reverse the order of the operands `%<source>s`.'
|
60
61
|
|
@@ -80,11 +81,7 @@ module RuboCop
|
|
80
81
|
return if equality_only? && non_equality_operator?(node) ||
|
81
82
|
file_constant_equal_program_name?(node)
|
82
83
|
|
83
|
-
valid_yoda?(node) || add_offense(node)
|
84
|
-
end
|
85
|
-
|
86
|
-
def autocorrect(node)
|
87
|
-
lambda do |corrector|
|
84
|
+
valid_yoda?(node) || add_offense(node) do |corrector|
|
88
85
|
corrector.replace(actual_code_range(node), corrected_code(node))
|
89
86
|
end
|
90
87
|
end
|
@@ -157,15 +154,7 @@ module RuboCop
|
|
157
154
|
def interpolation?(node)
|
158
155
|
return true if node.dstr_type?
|
159
156
|
|
160
|
-
|
161
|
-
# https://github.com/rubocop-hq/rubocop-ast/pull/18
|
162
|
-
if node.regexp_type?
|
163
|
-
return true if node.children.any? do |child|
|
164
|
-
child.respond_to?(:begin_type?) && child.begin_type?
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
false
|
157
|
+
node.regexp_type? && node.interpolation?
|
169
158
|
end
|
170
159
|
end
|
171
160
|
end
|
@@ -25,29 +25,23 @@ module RuboCop
|
|
25
25
|
# !{a: 1, b: 2}.empty?
|
26
26
|
# !string.empty?
|
27
27
|
# !hash.empty?
|
28
|
-
class ZeroLengthPredicate <
|
28
|
+
class ZeroLengthPredicate < Base
|
29
|
+
extend AutoCorrector
|
30
|
+
|
29
31
|
ZERO_MSG = 'Use `empty?` instead of `%<lhs>s %<opr>s %<rhs>s`.'
|
30
32
|
NONZERO_MSG = 'Use `!empty?` instead of ' \
|
31
33
|
'`%<lhs>s %<opr>s %<rhs>s`.'
|
32
34
|
|
33
|
-
|
35
|
+
RESTRICT_ON_SEND = %i[size length].freeze
|
34
36
|
|
35
37
|
def on_send(node)
|
36
38
|
check_zero_length_predicate(node)
|
37
39
|
check_nonzero_length_predicate(node)
|
38
40
|
end
|
39
41
|
|
40
|
-
def autocorrect(node)
|
41
|
-
lambda do |corrector|
|
42
|
-
corrector.replace(node, replacement(node))
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
42
|
private
|
47
43
|
|
48
44
|
def check_zero_length_predicate(node)
|
49
|
-
return unless LENGTH_METHODS.include?(node.method_name)
|
50
|
-
|
51
45
|
zero_length_predicate = zero_length_predicate(node.parent)
|
52
46
|
return unless zero_length_predicate
|
53
47
|
|
@@ -56,14 +50,13 @@ module RuboCop
|
|
56
50
|
return if non_polymorphic_collection?(node.parent)
|
57
51
|
|
58
52
|
add_offense(
|
59
|
-
node.parent,
|
60
|
-
|
61
|
-
|
53
|
+
node.parent, message: format(ZERO_MSG, lhs: lhs, opr: opr, rhs: rhs)
|
54
|
+
) do |corrector|
|
55
|
+
corrector.replace(node.parent, replacement(node.parent))
|
56
|
+
end
|
62
57
|
end
|
63
58
|
|
64
59
|
def check_nonzero_length_predicate(node)
|
65
|
-
return unless LENGTH_METHODS.include?(node.method_name)
|
66
|
-
|
67
60
|
nonzero_length_predicate = nonzero_length_predicate(node.parent)
|
68
61
|
return unless nonzero_length_predicate
|
69
62
|
|
@@ -72,9 +65,10 @@ module RuboCop
|
|
72
65
|
return if non_polymorphic_collection?(node.parent)
|
73
66
|
|
74
67
|
add_offense(
|
75
|
-
node.parent,
|
76
|
-
|
77
|
-
|
68
|
+
node.parent, message: format(NONZERO_MSG, lhs: lhs, opr: opr, rhs: rhs)
|
69
|
+
) do |corrector|
|
70
|
+
corrector.replace(node.parent, replacement(node.parent))
|
71
|
+
end
|
78
72
|
end
|
79
73
|
|
80
74
|
def_node_matcher :zero_length_predicate, <<~PATTERN
|
data/lib/rubocop/cop/team.rb
CHANGED
data/lib/rubocop/cop/util.rb
CHANGED
@@ -5,7 +5,6 @@ module RuboCop
|
|
5
5
|
# This module contains a collection of useful utility methods.
|
6
6
|
module Util
|
7
7
|
include PathUtil
|
8
|
-
include TokensUtil
|
9
8
|
|
10
9
|
# Match literal regex characters, not including anchors, character
|
11
10
|
# classes, alternatives, groups, repetitions, references, etc
|
@@ -19,7 +18,7 @@ module RuboCop
|
|
19
18
|
/^\s*#/.match?(line_source)
|
20
19
|
end
|
21
20
|
|
22
|
-
# @deprecated Use `ProcessedSource#line_with_comment?`, `contains_comment
|
21
|
+
# @deprecated Use `ProcessedSource#line_with_comment?`, `contains_comment?` or similar
|
23
22
|
def comment_lines?(node)
|
24
23
|
processed_source[line_range(node)].any? { |line| comment_line?(line) }
|
25
24
|
end
|
@@ -111,11 +111,9 @@ module RuboCop
|
|
111
111
|
private
|
112
112
|
|
113
113
|
def parse
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
)
|
118
|
-
end
|
114
|
+
matches = []
|
115
|
+
@source.scan(SEQUENCE) { matches << FormatSequence.new(Regexp.last_match) }
|
116
|
+
matches
|
119
117
|
end
|
120
118
|
|
121
119
|
def mixed_formats?
|
@@ -22,6 +22,8 @@ module RuboCop
|
|
22
22
|
#
|
23
23
|
# def after_declaring_variable(variable, variable_table)
|
24
24
|
# end
|
25
|
+
#
|
26
|
+
# @api private
|
25
27
|
class VariableForce < Force # rubocop:disable Metrics/ClassLength
|
26
28
|
VARIABLE_ASSIGNMENT_TYPE = :lvasgn
|
27
29
|
REGEXP_NAMED_CAPTURE_TYPE = :match_with_lvasgn
|
@@ -20,8 +20,6 @@ module RuboCop
|
|
20
20
|
nil
|
21
21
|
end
|
22
22
|
|
23
|
-
# rubocop:disable Metrics/BlockLength
|
24
|
-
|
25
23
|
# Abstract base class for branch classes.
|
26
24
|
# A branch represents a conditional branch in a scope.
|
27
25
|
#
|
@@ -42,8 +40,6 @@ module RuboCop
|
|
42
40
|
# do_something # no branch
|
43
41
|
# end
|
44
42
|
Base = Struct.new(:child_node, :scope) do
|
45
|
-
# rubocop:enable Metrics/BlockLength
|
46
|
-
|
47
43
|
def self.classes
|
48
44
|
@classes ||= []
|
49
45
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Class for generating documentation of all cops departments
|
4
|
+
# @api private
|
4
5
|
class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
6
|
+
include ::RuboCop::Cop::Documentation
|
5
7
|
# This class will only generate documentation for cops that belong to one of
|
6
8
|
# the departments given in the `departments` array. E.g. if we only wanted
|
7
9
|
# documentation for Lint cops:
|
@@ -210,7 +212,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
210
212
|
selected_cops.each do |cop|
|
211
213
|
content << print_cop_with_doc(cop)
|
212
214
|
end
|
213
|
-
file_name = "#{Dir.pwd}/docs/modules/ROOT/pages
|
215
|
+
file_name = "#{Dir.pwd}/docs/modules/ROOT/pages/#{department_to_basename(department)}.adoc"
|
214
216
|
File.open(file_name, 'w') do |file|
|
215
217
|
puts "* generated #{file_name}"
|
216
218
|
file.write("#{content.strip}\n")
|
@@ -243,7 +245,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
243
245
|
|
244
246
|
def table_of_content_for_department(department)
|
245
247
|
type_title = department[0].upcase + department[1..-1]
|
246
|
-
filename = "
|
248
|
+
filename = "#{department_to_basename(department)}.adoc"
|
247
249
|
content = +"=== Department xref:#{filename}[#{type_title}]\n\n"
|
248
250
|
cops_of_department(department).each do |cop|
|
249
251
|
anchor = cop.cop_name.sub('/', '').downcase
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# Extensions to the core String class
|
4
4
|
class String
|
5
|
-
unless method_defined?
|
5
|
+
unless method_defined?(:blank?) && ' '.blank?
|
6
6
|
# Checks whether a string is blank. A string is considered blank if it
|
7
7
|
# is either empty or contains only whitespace characters.
|
8
8
|
#
|
@@ -17,7 +17,7 @@ class String
|
|
17
17
|
# @example
|
18
18
|
# ' test'.blank? #=> false
|
19
19
|
def blank?
|
20
|
-
empty? ||
|
20
|
+
empty? || lstrip.empty?
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
# This class wraps the `Parser::Source::Comment` object that represents a
|
5
|
+
# special `rubocop:disable` and `rubocop:enable` comment and exposes what
|
6
|
+
# cops it contains.
|
7
|
+
class DirectiveComment
|
8
|
+
attr_reader :comment
|
9
|
+
|
10
|
+
def initialize(comment)
|
11
|
+
@comment = comment
|
12
|
+
end
|
13
|
+
|
14
|
+
# Return all the cops specified in the directive
|
15
|
+
def cops
|
16
|
+
match = comment.text.match(CommentConfig::COMMENT_DIRECTIVE_REGEXP)
|
17
|
+
return unless match
|
18
|
+
|
19
|
+
cops_string = match.captures[1]
|
20
|
+
cops_string.split(/,\s*/).uniq.sort
|
21
|
+
end
|
22
|
+
|
23
|
+
# Checks if this directive contains all the given cop names
|
24
|
+
def match?(cop_names)
|
25
|
+
cops == cop_names.uniq.sort
|
26
|
+
end
|
27
|
+
|
28
|
+
def range
|
29
|
+
comment.location.expression
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Ext
|
5
|
+
# Extensions to AST::RegexpNode for our cached parsed regexp info
|
6
|
+
module RegexpNode
|
7
|
+
ANY = Object.new
|
8
|
+
def ANY.==(_)
|
9
|
+
true
|
10
|
+
end
|
11
|
+
private_constant :ANY
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_reader :parsed_cache
|
15
|
+
end
|
16
|
+
@parsed_cache = {}
|
17
|
+
|
18
|
+
# @return [Regexp::Expression::Root, nil]
|
19
|
+
def parsed_tree
|
20
|
+
str = with_interpolations_blanked
|
21
|
+
Ext::RegexpNode.parsed_cache[str] ||= begin
|
22
|
+
Regexp::Parser.parse(str, options: options)
|
23
|
+
rescue StandardError
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def each_capture(named: ANY)
|
29
|
+
return enum_for(__method__, named: named) unless block_given?
|
30
|
+
|
31
|
+
parsed_tree&.traverse do |event, exp, _index|
|
32
|
+
yield(exp) if event == :enter &&
|
33
|
+
named == exp.respond_to?(:name) &&
|
34
|
+
exp.respond_to?(:capturing?) &&
|
35
|
+
exp.capturing?
|
36
|
+
end
|
37
|
+
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def with_interpolations_blanked
|
44
|
+
# Ignore the trailing regopt node
|
45
|
+
children[0...-1].map do |child|
|
46
|
+
source = child.source
|
47
|
+
|
48
|
+
# We don't want to consider the contents of interpolations as part of the pattern source,
|
49
|
+
# but need to preserve their width, to allow offsets to correctly line up with the
|
50
|
+
# original source: spaces have no effect, and preserve width.
|
51
|
+
if child.begin_type?
|
52
|
+
' ' * source.length
|
53
|
+
else
|
54
|
+
source
|
55
|
+
end
|
56
|
+
end.join
|
57
|
+
end
|
58
|
+
|
59
|
+
AST::RegexpNode.include self
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/rubocop/file_finder.rb
CHANGED
@@ -32,7 +32,6 @@ module RuboCop
|
|
32
32
|
@exclude_limit_option = @options[:exclude_limit]
|
33
33
|
@exclude_limit = Integer(@exclude_limit_option ||
|
34
34
|
RuboCop::Options::DEFAULT_MAXIMUM_EXCLUSION_ITEMS)
|
35
|
-
@show_offense_counts = !@options[:no_offense_counts]
|
36
35
|
end
|
37
36
|
|
38
37
|
def file_finished(file, offenses)
|
@@ -56,6 +55,14 @@ module RuboCop
|
|
56
55
|
|
57
56
|
private
|
58
57
|
|
58
|
+
def show_timestamp?
|
59
|
+
@options.fetch(:auto_gen_timestamp, true)
|
60
|
+
end
|
61
|
+
|
62
|
+
def show_offense_counts?
|
63
|
+
@options.fetch(:offense_counts, true)
|
64
|
+
end
|
65
|
+
|
59
66
|
def command
|
60
67
|
command = 'rubocop --auto-gen-config'
|
61
68
|
|
@@ -66,15 +73,15 @@ module RuboCop
|
|
66
73
|
format(' --exclude-limit %<limit>d',
|
67
74
|
limit: Integer(@exclude_limit_option))
|
68
75
|
end
|
69
|
-
command += ' --no-offense-counts'
|
76
|
+
command += ' --no-offense-counts' unless show_offense_counts?
|
70
77
|
|
71
|
-
command += ' --no-auto-gen-timestamp'
|
78
|
+
command += ' --no-auto-gen-timestamp' unless show_timestamp?
|
72
79
|
|
73
80
|
command
|
74
81
|
end
|
75
82
|
|
76
83
|
def timestamp
|
77
|
-
|
84
|
+
show_timestamp? ? "on #{Time.now.utc} " : ''
|
78
85
|
end
|
79
86
|
|
80
87
|
def output_offenses
|
@@ -112,7 +119,7 @@ module RuboCop
|
|
112
119
|
end
|
113
120
|
|
114
121
|
def output_cop_comments(output_buffer, cfg, cop_name, offense_count)
|
115
|
-
output_buffer.puts "# Offense count: #{offense_count}" if
|
122
|
+
output_buffer.puts "# Offense count: #{offense_count}" if show_offense_counts?
|
116
123
|
|
117
124
|
cop_class = Cop::Registry.global.find_by_cop_name(cop_name)
|
118
125
|
output_buffer.puts '# Cop supports --auto-correct.' if cop_class&.support_autocorrect?
|