rubocop 0.85.1 → 0.89.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -4
- data/bin/rubocop-profile +32 -0
- data/config/default.yml +227 -26
- data/lib/rubocop.rb +33 -5
- data/lib/rubocop/cli.rb +2 -4
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +42 -7
- data/lib/rubocop/cli/command/base.rb +1 -0
- data/lib/rubocop/cli/command/execute_runner.rb +1 -1
- data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
- data/lib/rubocop/cli/command/show_cops.rb +2 -2
- data/lib/rubocop/cli/command/version.rb +2 -2
- data/lib/rubocop/comment_config.rb +2 -2
- data/lib/rubocop/config.rb +20 -3
- data/lib/rubocop/config_loader.rb +40 -68
- data/lib/rubocop/config_loader_resolver.rb +4 -4
- data/lib/rubocop/config_obsoletion.rb +6 -2
- data/lib/rubocop/config_store.rb +4 -0
- data/lib/rubocop/config_validator.rb +1 -3
- data/lib/rubocop/cop/autocorrect_logic.rb +14 -24
- data/lib/rubocop/cop/badge.rb +1 -1
- data/lib/rubocop/cop/base.rb +407 -0
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +10 -20
- data/lib/rubocop/cop/commissioner.rb +47 -50
- data/lib/rubocop/cop/cop.rb +85 -236
- data/lib/rubocop/cop/corrector.rb +38 -115
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +26 -0
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/punctuation_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +15 -18
- data/lib/rubocop/cop/force.rb +1 -0
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +39 -13
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/generator.rb +1 -1
- data/lib/rubocop/cop/generator/configuration_injector.rb +3 -3
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +4 -12
- data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +11 -14
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +8 -8
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +10 -7
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +7 -8
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -2
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/case_indentation.rb +18 -19
- data/lib/rubocop/cop/layout/class_structure.rb +2 -37
- data/lib/rubocop/cop/layout/comment_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines.rb +0 -2
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +1 -0
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +3 -8
- data/lib/rubocop/cop/layout/end_alignment.rb +3 -2
- data/lib/rubocop/cop/layout/end_of_line.rb +1 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +9 -16
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/hash_alignment.rb +2 -3
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/indentation_style.rb +0 -2
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +17 -7
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +0 -2
- data/lib/rubocop/cop/layout/space_after_colon.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +22 -27
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +33 -66
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +14 -0
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +4 -3
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -2
- data/lib/rubocop/cop/legacy/corrections_proxy.rb +49 -0
- data/lib/rubocop/cop/legacy/corrector.rb +29 -0
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +7 -4
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +15 -10
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +11 -13
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +2 -2
- data/lib/rubocop/cop/lint/big_decimal_new.rb +10 -10
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +49 -0
- data/lib/rubocop/cop/lint/boolean_symbol.rb +16 -11
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +1 -1
- data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
- data/lib/rubocop/cop/lint/debugger.rb +7 -1
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +9 -10
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +21 -17
- data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +8 -2
- data/lib/rubocop/cop/lint/duplicate_case_condition.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_elsif_condition.rb +39 -0
- data/lib/rubocop/cop/lint/duplicate_hash_key.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +9 -6
- data/lib/rubocop/cop/lint/duplicate_rescue_exception.rb +60 -0
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
- data/lib/rubocop/cop/lint/else_layout.rb +1 -1
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +67 -0
- data/lib/rubocop/cop/lint/empty_ensure.rb +5 -5
- data/lib/rubocop/cop/lint/empty_expression.rb +2 -2
- data/lib/rubocop/cop/lint/empty_interpolation.rb +5 -6
- data/lib/rubocop/cop/lint/empty_when.rb +2 -2
- data/lib/rubocop/cop/lint/ensure_return.rb +27 -29
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +11 -10
- data/lib/rubocop/cop/lint/flip_flop.rb +1 -1
- data/lib/rubocop/cop/lint/float_comparison.rb +93 -0
- data/lib/rubocop/cop/lint/float_out_of_range.rb +2 -2
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +11 -5
- data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +13 -14
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +5 -4
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +8 -8
- data/lib/rubocop/cop/lint/inherit_exception.rb +12 -7
- data/lib/rubocop/cop/lint/interpolation_check.rb +21 -5
- data/lib/rubocop/cop/lint/literal_as_condition.rb +14 -2
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +7 -7
- data/lib/rubocop/cop/lint/loop.rb +23 -2
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +6 -5
- data/lib/rubocop/cop/lint/missing_super.rb +99 -0
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -1
- data/lib/rubocop/cop/lint/multiple_comparison.rb +6 -9
- data/lib/rubocop/cop/lint/nested_method_definition.rb +15 -21
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +84 -13
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +2 -2
- data/lib/rubocop/cop/lint/number_conversion.rb +6 -9
- data/lib/rubocop/cop/lint/ordered_magic_comments.rb +11 -13
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +61 -0
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +12 -13
- data/lib/rubocop/cop/lint/percent_string_array.rb +14 -13
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +14 -13
- data/lib/rubocop/cop/lint/raise_exception.rb +15 -5
- data/lib/rubocop/cop/lint/rand_one.rb +3 -3
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +31 -25
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +7 -11
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +4 -7
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +15 -11
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +6 -13
- data/lib/rubocop/cop/lint/redundant_with_index.rb +11 -14
- data/lib/rubocop/cop/lint/redundant_with_object.rb +11 -14
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -2
- data/lib/rubocop/cop/lint/require_parentheses.rb +2 -2
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +8 -8
- data/lib/rubocop/cop/lint/return_in_void_context.rb +2 -4
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +3 -6
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +14 -10
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +10 -2
- data/lib/rubocop/cop/lint/script_permission.rb +10 -7
- data/lib/rubocop/cop/lint/self_assignment.rb +78 -0
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +5 -11
- data/lib/rubocop/cop/lint/shadowed_argument.rb +3 -3
- data/lib/rubocop/cop/lint/shadowed_exception.rb +2 -2
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +3 -3
- data/lib/rubocop/cop/lint/struct_new_override.rb +1 -1
- data/lib/rubocop/cop/lint/suppressed_exception.rb +4 -7
- data/lib/rubocop/cop/lint/syntax.rb +11 -26
- data/lib/rubocop/cop/lint/to_json.rb +4 -6
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +34 -0
- data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +4 -4
- data/lib/rubocop/cop/lint/unified_integer.rb +4 -6
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_loop.rb +174 -0
- data/lib/rubocop/cop/lint/unused_block_argument.rb +8 -3
- data/lib/rubocop/cop/lint/unused_method_argument.rb +9 -4
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -1
- data/lib/rubocop/cop/lint/uri_regexp.rb +11 -31
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +26 -16
- data/lib/rubocop/cop/lint/useless_assignment.rb +4 -4
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +6 -15
- data/lib/rubocop/cop/lint/useless_setter_call.rb +4 -6
- data/lib/rubocop/cop/lint/void.rb +3 -7
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/block_length.rb +24 -2
- data/lib/rubocop/cop/metrics/block_nesting.rb +2 -2
- data/lib/rubocop/cop/metrics/class_length.rb +26 -3
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +37 -4
- data/lib/rubocop/cop/metrics/method_length.rb +25 -2
- data/lib/rubocop/cop/metrics/module_length.rb +26 -3
- data/lib/rubocop/cop/metrics/parameter_lists.rb +2 -6
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +7 -8
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +47 -4
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +157 -0
- data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
- data/lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb +37 -0
- data/lib/rubocop/cop/migration/department_name.rb +13 -15
- data/lib/rubocop/cop/mixin/allowed_methods.rb +19 -0
- data/lib/rubocop/cop/mixin/array_min_size.rb +1 -1
- data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/code_length.rb +26 -5
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +5 -1
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
- data/lib/rubocop/cop/mixin/method_complexity.rb +10 -2
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/nil_methods.rb +3 -5
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +6 -1
- data/lib/rubocop/cop/mixin/parentheses.rb +1 -2
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +1 -1
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +27 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +38 -9
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/surrounding_space.rb +7 -27
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +12 -17
- data/lib/rubocop/cop/mixin/unused_argument.rb +4 -6
- data/lib/rubocop/cop/mixin/visibility_help.rb +50 -0
- data/lib/rubocop/cop/naming/accessor_method_name.rb +4 -2
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +29 -6
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +4 -4
- data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +2 -2
- data/lib/rubocop/cop/naming/constant_name.rb +2 -2
- data/lib/rubocop/cop/naming/file_name.rb +4 -6
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +2 -2
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +3 -3
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -2
- data/lib/rubocop/cop/naming/method_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_parameter_name.rb +2 -2
- data/lib/rubocop/cop/naming/predicate_name.rb +6 -10
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +12 -11
- data/lib/rubocop/cop/naming/variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/variable_number.rb +1 -1
- data/lib/rubocop/cop/offense.rb +16 -2
- data/lib/rubocop/cop/registry.rb +3 -3
- data/lib/rubocop/cop/security/eval.rb +2 -2
- data/lib/rubocop/cop/security/json_load.rb +6 -8
- data/lib/rubocop/cop/security/marshal_load.rb +2 -4
- data/lib/rubocop/cop/security/open.rb +2 -2
- data/lib/rubocop/cop/security/yaml_load.rb +6 -6
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +11 -1
- data/lib/rubocop/cop/style/accessor_grouping.rb +149 -0
- data/lib/rubocop/cop/style/alias.rb +7 -3
- data/lib/rubocop/cop/style/array_coercion.rb +63 -0
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +3 -2
- data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +144 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -4
- data/lib/rubocop/cop/style/case_equality.rb +22 -3
- data/lib/rubocop/cop/style/case_like_if.rb +217 -0
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/class_vars.rb +21 -0
- data/lib/rubocop/cop/style/colon_method_call.rb +3 -3
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +5 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +11 -2
- data/lib/rubocop/cop/style/copyright.rb +3 -3
- data/lib/rubocop/cop/style/date_time.rb +1 -1
- data/lib/rubocop/cop/style/dir.rb +2 -2
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +6 -6
- data/lib/rubocop/cop/style/each_with_object.rb +0 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +8 -6
- data/lib/rubocop/cop/style/empty_literal.rb +5 -5
- data/lib/rubocop/cop/style/empty_method.rb +5 -5
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +4 -0
- data/lib/rubocop/cop/style/expand_path_arguments.rb +6 -2
- data/lib/rubocop/cop/style/explicit_block_argument.rb +102 -0
- data/lib/rubocop/cop/style/exponential_notation.rb +8 -10
- data/lib/rubocop/cop/style/float_division.rb +7 -10
- data/lib/rubocop/cop/style/format_string.rb +4 -0
- data/lib/rubocop/cop/style/format_string_token.rb +6 -5
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/global_std_stream.rb +65 -0
- data/lib/rubocop/cop/style/guard_clause.rb +2 -2
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +69 -0
- data/lib/rubocop/cop/style/hash_like_case.rb +76 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +6 -3
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +8 -28
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -0
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +3 -4
- data/lib/rubocop/cop/style/ip_addresses.rb +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +5 -0
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/missing_else.rb +1 -11
- data/lib/rubocop/cop/style/missing_respond_to_missing.rb +9 -2
- data/lib/rubocop/cop/style/multiline_block_chain.rb +10 -1
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_memoization.rb +2 -2
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +17 -6
- data/lib/rubocop/cop/style/mutable_constant.rb +4 -4
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -5
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +27 -0
- data/lib/rubocop/cop/style/next.rb +2 -2
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -2
- data/lib/rubocop/cop/style/numeric_predicate.rb +7 -4
- data/lib/rubocop/cop/style/optional_boolean_parameter.rb +42 -0
- data/lib/rubocop/cop/style/parallel_assignment.rb +5 -5
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -2
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +5 -10
- data/lib/rubocop/cop/style/redundant_assignment.rb +117 -0
- data/lib/rubocop/cop/style/redundant_condition.rb +15 -3
- data/lib/rubocop/cop/style/redundant_exception.rb +18 -10
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +122 -0
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +50 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +8 -2
- data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +4 -3
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +23 -32
- data/lib/rubocop/cop/style/redundant_self.rb +6 -9
- data/lib/rubocop/cop/style/redundant_sort.rb +28 -12
- data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -1
- data/lib/rubocop/cop/style/sample.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +1 -1
- data/lib/rubocop/cop/style/signal_exception.rb +3 -1
- data/lib/rubocop/cop/style/single_argument_dig.rb +54 -0
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +3 -2
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/string_concatenation.rb +92 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +23 -2
- data/lib/rubocop/cop/style/symbol_array.rb +6 -6
- data/lib/rubocop/cop/style/symbol_proc.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +9 -32
- data/lib/rubocop/cop/style/trivial_accessors.rb +8 -7
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +18 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +12 -8
- data/lib/rubocop/cop/team.rb +98 -82
- data/lib/rubocop/cop/tokens_util.rb +84 -0
- data/lib/rubocop/cop/util.rb +3 -15
- data/lib/rubocop/cop/utils/format_string.rb +2 -3
- data/lib/rubocop/cop/variable_force.rb +0 -2
- data/lib/rubocop/cop/variable_force/branch.rb +1 -0
- data/lib/rubocop/cop/variable_force/variable.rb +7 -5
- data/lib/rubocop/cops_documentation_generator.rb +282 -0
- data/lib/rubocop/error.rb +1 -0
- data/lib/rubocop/file_finder.rb +12 -12
- data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -2
- data/lib/rubocop/formatter/formatter_set.rb +2 -1
- data/lib/rubocop/name_similarity.rb +7 -3
- data/lib/rubocop/options.rb +15 -8
- data/lib/rubocop/path_util.rb +19 -19
- data/lib/rubocop/platform.rb +1 -1
- data/lib/rubocop/rake_task.rb +7 -9
- data/lib/rubocop/result_cache.rb +12 -8
- data/lib/rubocop/rspec/cop_helper.rb +4 -4
- data/lib/rubocop/rspec/expect_offense.rb +63 -22
- data/lib/rubocop/rspec/shared_contexts.rb +19 -16
- data/lib/rubocop/runner.rb +34 -33
- data/lib/rubocop/target_finder.rb +14 -11
- data/lib/rubocop/target_ruby.rb +2 -2
- data/lib/rubocop/version.rb +2 -2
- metadata +49 -11
- data/lib/rubocop/cop/lint/useless_comparison.rb +0 -28
- data/lib/rubocop/cop/mixin/classish_length.rb +0 -37
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +0 -37
- data/lib/rubocop/cop/mixin/too_many_lines.rb +0 -35
- data/lib/rubocop/cop/style/method_missing_super.rb +0 -34
data/lib/rubocop.rb
CHANGED
@@ -23,6 +23,7 @@ require_relative 'rubocop/string_interpreter'
|
|
23
23
|
require_relative 'rubocop/error'
|
24
24
|
require_relative 'rubocop/warning'
|
25
25
|
|
26
|
+
require_relative 'rubocop/cop/tokens_util'
|
26
27
|
require_relative 'rubocop/cop/util'
|
27
28
|
require_relative 'rubocop/cop/offense'
|
28
29
|
require_relative 'rubocop/cop/message_annotator'
|
@@ -30,6 +31,7 @@ require_relative 'rubocop/cop/ignored_node'
|
|
30
31
|
require_relative 'rubocop/cop/autocorrect_logic'
|
31
32
|
require_relative 'rubocop/cop/badge'
|
32
33
|
require_relative 'rubocop/cop/registry'
|
34
|
+
require_relative 'rubocop/cop/base'
|
33
35
|
require_relative 'rubocop/cop/cop'
|
34
36
|
require_relative 'rubocop/cop/commissioner'
|
35
37
|
require_relative 'rubocop/cop/corrector'
|
@@ -52,11 +54,12 @@ require_relative 'rubocop/cop/mixin/annotation_comment'
|
|
52
54
|
require_relative 'rubocop/cop/mixin/array_min_size'
|
53
55
|
require_relative 'rubocop/cop/mixin/array_syntax'
|
54
56
|
require_relative 'rubocop/cop/mixin/alignment'
|
57
|
+
require_relative 'rubocop/cop/mixin/allowed_methods'
|
58
|
+
require_relative 'rubocop/cop/mixin/auto_corrector'
|
55
59
|
require_relative 'rubocop/cop/mixin/check_assignment'
|
56
60
|
require_relative 'rubocop/cop/mixin/check_line_breakable'
|
57
61
|
require_relative 'rubocop/cop/mixin/configurable_max'
|
58
62
|
require_relative 'rubocop/cop/mixin/code_length' # relies on configurable_max
|
59
|
-
require_relative 'rubocop/cop/mixin/classish_length' # relies on code_length
|
60
63
|
require_relative 'rubocop/cop/mixin/configurable_enforced_style'
|
61
64
|
require_relative 'rubocop/cop/mixin/configurable_formatting'
|
62
65
|
require_relative 'rubocop/cop/mixin/configurable_naming'
|
@@ -79,6 +82,7 @@ require_relative 'rubocop/cop/mixin/integer_node'
|
|
79
82
|
require_relative 'rubocop/cop/mixin/interpolation'
|
80
83
|
require_relative 'rubocop/cop/mixin/line_length_help'
|
81
84
|
require_relative 'rubocop/cop/mixin/match_range'
|
85
|
+
require_relative 'rubocop/cop/metrics/utils/repeated_csend_discount'
|
82
86
|
require_relative 'rubocop/cop/mixin/method_complexity'
|
83
87
|
require_relative 'rubocop/cop/mixin/method_preference'
|
84
88
|
require_relative 'rubocop/cop/mixin/min_body_length'
|
@@ -92,7 +96,6 @@ require_relative 'rubocop/cop/mixin/nil_methods'
|
|
92
96
|
require_relative 'rubocop/cop/mixin/on_normal_if_unless'
|
93
97
|
require_relative 'rubocop/cop/mixin/ordered_gem_node'
|
94
98
|
require_relative 'rubocop/cop/mixin/parentheses'
|
95
|
-
require_relative 'rubocop/cop/mixin/parser_diagnostic'
|
96
99
|
require_relative 'rubocop/cop/mixin/percent_array'
|
97
100
|
require_relative 'rubocop/cop/mixin/percent_literal'
|
98
101
|
require_relative 'rubocop/cop/mixin/preceding_following_alignment'
|
@@ -108,11 +111,11 @@ require_relative 'rubocop/cop/mixin/statement_modifier'
|
|
108
111
|
require_relative 'rubocop/cop/mixin/string_help'
|
109
112
|
require_relative 'rubocop/cop/mixin/string_literals_help'
|
110
113
|
require_relative 'rubocop/cop/mixin/target_ruby_version'
|
111
|
-
require_relative 'rubocop/cop/mixin/too_many_lines'
|
112
114
|
require_relative 'rubocop/cop/mixin/trailing_body'
|
113
115
|
require_relative 'rubocop/cop/mixin/trailing_comma'
|
114
116
|
require_relative 'rubocop/cop/mixin/uncommunicative_name'
|
115
117
|
require_relative 'rubocop/cop/mixin/unused_argument'
|
118
|
+
require_relative 'rubocop/cop/mixin/visibility_help'
|
116
119
|
|
117
120
|
require_relative 'rubocop/cop/utils/format_string'
|
118
121
|
|
@@ -240,17 +243,22 @@ require_relative 'rubocop/cop/lint/ambiguous_operator'
|
|
240
243
|
require_relative 'rubocop/cop/lint/ambiguous_regexp_literal'
|
241
244
|
require_relative 'rubocop/cop/lint/assignment_in_condition'
|
242
245
|
require_relative 'rubocop/cop/lint/big_decimal_new'
|
246
|
+
require_relative 'rubocop/cop/lint/binary_operator_with_identical_operands'
|
243
247
|
require_relative 'rubocop/cop/lint/boolean_symbol'
|
244
248
|
require_relative 'rubocop/cop/lint/circular_argument_reference'
|
249
|
+
require_relative 'rubocop/cop/lint/constant_resolution'
|
245
250
|
require_relative 'rubocop/cop/lint/debugger'
|
246
251
|
require_relative 'rubocop/cop/lint/deprecated_class_methods'
|
247
252
|
require_relative 'rubocop/cop/lint/deprecated_open_ssl_constant'
|
248
253
|
require_relative 'rubocop/cop/lint/disjunctive_assignment_in_constructor'
|
249
254
|
require_relative 'rubocop/cop/lint/duplicate_case_condition'
|
255
|
+
require_relative 'rubocop/cop/lint/duplicate_elsif_condition'
|
250
256
|
require_relative 'rubocop/cop/lint/duplicate_hash_key'
|
251
257
|
require_relative 'rubocop/cop/lint/duplicate_methods'
|
258
|
+
require_relative 'rubocop/cop/lint/duplicate_rescue_exception'
|
252
259
|
require_relative 'rubocop/cop/lint/each_with_object_argument'
|
253
260
|
require_relative 'rubocop/cop/lint/else_layout'
|
261
|
+
require_relative 'rubocop/cop/lint/empty_conditional_body'
|
254
262
|
require_relative 'rubocop/cop/lint/empty_ensure'
|
255
263
|
require_relative 'rubocop/cop/lint/empty_expression'
|
256
264
|
require_relative 'rubocop/cop/lint/empty_interpolation'
|
@@ -258,6 +266,7 @@ require_relative 'rubocop/cop/lint/empty_when'
|
|
258
266
|
require_relative 'rubocop/cop/lint/ensure_return'
|
259
267
|
require_relative 'rubocop/cop/lint/erb_new_arguments'
|
260
268
|
require_relative 'rubocop/cop/lint/flip_flop'
|
269
|
+
require_relative 'rubocop/cop/lint/float_comparison'
|
261
270
|
require_relative 'rubocop/cop/lint/float_out_of_range'
|
262
271
|
require_relative 'rubocop/cop/lint/format_parameter_mismatch'
|
263
272
|
require_relative 'rubocop/cop/lint/heredoc_method_call_position'
|
@@ -269,6 +278,7 @@ require_relative 'rubocop/cop/lint/literal_as_condition'
|
|
269
278
|
require_relative 'rubocop/cop/lint/literal_in_interpolation'
|
270
279
|
require_relative 'rubocop/cop/lint/loop'
|
271
280
|
require_relative 'rubocop/cop/lint/missing_cop_enable_directive'
|
281
|
+
require_relative 'rubocop/cop/lint/missing_super'
|
272
282
|
require_relative 'rubocop/cop/lint/mixed_regexp_capture_types'
|
273
283
|
require_relative 'rubocop/cop/lint/multiple_comparison'
|
274
284
|
require_relative 'rubocop/cop/lint/nested_method_definition'
|
@@ -278,6 +288,7 @@ require_relative 'rubocop/cop/lint/non_deterministic_require_order'
|
|
278
288
|
require_relative 'rubocop/cop/lint/non_local_exit_from_iterator'
|
279
289
|
require_relative 'rubocop/cop/lint/number_conversion'
|
280
290
|
require_relative 'rubocop/cop/lint/ordered_magic_comments'
|
291
|
+
require_relative 'rubocop/cop/lint/out_of_range_regexp_ref'
|
281
292
|
require_relative 'rubocop/cop/lint/parentheses_as_grouped_expression'
|
282
293
|
require_relative 'rubocop/cop/lint/percent_string_array'
|
283
294
|
require_relative 'rubocop/cop/lint/percent_symbol_array'
|
@@ -299,6 +310,7 @@ require_relative 'rubocop/cop/lint/safe_navigation_consistency'
|
|
299
310
|
require_relative 'rubocop/cop/lint/safe_navigation_chain'
|
300
311
|
require_relative 'rubocop/cop/lint/safe_navigation_with_empty'
|
301
312
|
require_relative 'rubocop/cop/lint/script_permission'
|
313
|
+
require_relative 'rubocop/cop/lint/self_assignment'
|
302
314
|
require_relative 'rubocop/cop/lint/send_with_mixin_argument'
|
303
315
|
require_relative 'rubocop/cop/lint/shadowed_argument'
|
304
316
|
require_relative 'rubocop/cop/lint/shadowed_exception'
|
@@ -307,23 +319,26 @@ require_relative 'rubocop/cop/lint/struct_new_override'
|
|
307
319
|
require_relative 'rubocop/cop/lint/suppressed_exception'
|
308
320
|
require_relative 'rubocop/cop/lint/syntax'
|
309
321
|
require_relative 'rubocop/cop/lint/to_json'
|
322
|
+
require_relative 'rubocop/cop/lint/top_level_return_with_argument'
|
310
323
|
require_relative 'rubocop/cop/lint/underscore_prefixed_variable_name'
|
311
324
|
require_relative 'rubocop/cop/lint/unified_integer'
|
312
325
|
require_relative 'rubocop/cop/lint/unreachable_code'
|
326
|
+
require_relative 'rubocop/cop/lint/unreachable_loop'
|
313
327
|
require_relative 'rubocop/cop/lint/unused_block_argument'
|
314
328
|
require_relative 'rubocop/cop/lint/unused_method_argument'
|
315
329
|
require_relative 'rubocop/cop/lint/uri_escape_unescape'
|
316
330
|
require_relative 'rubocop/cop/lint/uri_regexp'
|
317
331
|
require_relative 'rubocop/cop/lint/useless_access_modifier'
|
318
332
|
require_relative 'rubocop/cop/lint/useless_assignment'
|
319
|
-
require_relative 'rubocop/cop/lint/useless_comparison'
|
320
333
|
require_relative 'rubocop/cop/lint/useless_else_without_rescue'
|
321
334
|
require_relative 'rubocop/cop/lint/useless_setter_call'
|
322
335
|
require_relative 'rubocop/cop/lint/void'
|
323
336
|
|
337
|
+
require_relative 'rubocop/cop/metrics/utils/iterating_block'
|
324
338
|
require_relative 'rubocop/cop/metrics/cyclomatic_complexity'
|
325
339
|
# relies on cyclomatic_complexity
|
326
340
|
require_relative 'rubocop/cop/metrics/utils/abc_size_calculator'
|
341
|
+
require_relative 'rubocop/cop/metrics/utils/code_length_calculator'
|
327
342
|
require_relative 'rubocop/cop/metrics/abc_size'
|
328
343
|
require_relative 'rubocop/cop/metrics/block_length'
|
329
344
|
require_relative 'rubocop/cop/metrics/block_nesting'
|
@@ -351,17 +366,21 @@ require_relative 'rubocop/cop/naming/variable_name'
|
|
351
366
|
require_relative 'rubocop/cop/naming/variable_number'
|
352
367
|
|
353
368
|
require_relative 'rubocop/cop/style/access_modifier_declarations'
|
369
|
+
require_relative 'rubocop/cop/style/accessor_grouping'
|
354
370
|
require_relative 'rubocop/cop/style/alias'
|
355
371
|
require_relative 'rubocop/cop/style/and_or'
|
372
|
+
require_relative 'rubocop/cop/style/array_coercion'
|
356
373
|
require_relative 'rubocop/cop/style/array_join'
|
357
374
|
require_relative 'rubocop/cop/style/ascii_comments'
|
358
375
|
require_relative 'rubocop/cop/style/attr'
|
359
376
|
require_relative 'rubocop/cop/style/auto_resource_cleanup'
|
360
377
|
require_relative 'rubocop/cop/style/bare_percent_literals'
|
361
378
|
require_relative 'rubocop/cop/style/begin_block'
|
379
|
+
require_relative 'rubocop/cop/style/bisected_attr_accessor'
|
362
380
|
require_relative 'rubocop/cop/style/block_comments'
|
363
381
|
require_relative 'rubocop/cop/style/block_delimiters'
|
364
382
|
require_relative 'rubocop/cop/style/case_equality'
|
383
|
+
require_relative 'rubocop/cop/style/case_like_if'
|
365
384
|
require_relative 'rubocop/cop/style/character_literal'
|
366
385
|
require_relative 'rubocop/cop/style/class_and_module_children'
|
367
386
|
require_relative 'rubocop/cop/style/class_check'
|
@@ -397,15 +416,19 @@ require_relative 'rubocop/cop/style/end_block'
|
|
397
416
|
require_relative 'rubocop/cop/style/eval_with_location'
|
398
417
|
require_relative 'rubocop/cop/style/even_odd'
|
399
418
|
require_relative 'rubocop/cop/style/expand_path_arguments'
|
419
|
+
require_relative 'rubocop/cop/style/explicit_block_argument'
|
400
420
|
require_relative 'rubocop/cop/style/exponential_notation'
|
401
421
|
require_relative 'rubocop/cop/style/float_division'
|
402
422
|
require_relative 'rubocop/cop/style/for'
|
403
423
|
require_relative 'rubocop/cop/style/format_string'
|
404
424
|
require_relative 'rubocop/cop/style/format_string_token'
|
405
425
|
require_relative 'rubocop/cop/style/frozen_string_literal_comment'
|
426
|
+
require_relative 'rubocop/cop/style/global_std_stream'
|
406
427
|
require_relative 'rubocop/cop/style/global_vars'
|
407
428
|
require_relative 'rubocop/cop/style/guard_clause'
|
429
|
+
require_relative 'rubocop/cop/style/hash_as_last_array_item'
|
408
430
|
require_relative 'rubocop/cop/style/hash_each_methods'
|
431
|
+
require_relative 'rubocop/cop/style/hash_like_case'
|
409
432
|
require_relative 'rubocop/cop/style/hash_syntax'
|
410
433
|
require_relative 'rubocop/cop/style/hash_transform_keys'
|
411
434
|
require_relative 'rubocop/cop/style/hash_transform_values'
|
@@ -424,11 +447,13 @@ require_relative 'rubocop/cop/style/lambda_call'
|
|
424
447
|
require_relative 'rubocop/cop/style/line_end_concatenation'
|
425
448
|
require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
|
426
449
|
require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
|
450
|
+
require_relative 'rubocop/cop/style/redundant_assignment'
|
451
|
+
require_relative 'rubocop/cop/style/redundant_fetch_block'
|
452
|
+
require_relative 'rubocop/cop/style/redundant_file_extension_in_require'
|
427
453
|
require_relative 'rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses'
|
428
454
|
require_relative 'rubocop/cop/style/method_call_with_args_parentheses/require_parentheses'
|
429
455
|
require_relative 'rubocop/cop/style/method_called_on_do_end_block'
|
430
456
|
require_relative 'rubocop/cop/style/method_def_parentheses'
|
431
|
-
require_relative 'rubocop/cop/style/method_missing_super'
|
432
457
|
require_relative 'rubocop/cop/style/min_max'
|
433
458
|
require_relative 'rubocop/cop/style/missing_else'
|
434
459
|
require_relative 'rubocop/cop/style/missing_respond_to_missing'
|
@@ -461,6 +486,7 @@ require_relative 'rubocop/cop/style/one_line_conditional'
|
|
461
486
|
require_relative 'rubocop/cop/style/or_assignment'
|
462
487
|
require_relative 'rubocop/cop/style/option_hash'
|
463
488
|
require_relative 'rubocop/cop/style/optional_arguments'
|
489
|
+
require_relative 'rubocop/cop/style/optional_boolean_parameter'
|
464
490
|
require_relative 'rubocop/cop/style/parallel_assignment'
|
465
491
|
require_relative 'rubocop/cop/style/parentheses_around_condition'
|
466
492
|
require_relative 'rubocop/cop/style/percent_literal_delimiters'
|
@@ -495,12 +521,14 @@ require_relative 'rubocop/cop/style/self_assignment'
|
|
495
521
|
require_relative 'rubocop/cop/style/semicolon'
|
496
522
|
require_relative 'rubocop/cop/style/send'
|
497
523
|
require_relative 'rubocop/cop/style/signal_exception'
|
524
|
+
require_relative 'rubocop/cop/style/single_argument_dig'
|
498
525
|
require_relative 'rubocop/cop/style/single_line_block_params'
|
499
526
|
require_relative 'rubocop/cop/style/single_line_methods'
|
500
527
|
require_relative 'rubocop/cop/style/slicing_with_range'
|
501
528
|
require_relative 'rubocop/cop/style/special_global_vars'
|
502
529
|
require_relative 'rubocop/cop/style/stabby_lambda_parentheses'
|
503
530
|
require_relative 'rubocop/cop/style/stderr_puts'
|
531
|
+
require_relative 'rubocop/cop/style/string_concatenation'
|
504
532
|
require_relative 'rubocop/cop/style/string_hash_keys'
|
505
533
|
require_relative 'rubocop/cop/style/string_literals'
|
506
534
|
require_relative 'rubocop/cop/style/string_literals_in_interpolation'
|
data/lib/rubocop/cli.rb
CHANGED
@@ -75,7 +75,7 @@ module RuboCop
|
|
75
75
|
|
76
76
|
def validate_options_vs_config
|
77
77
|
if @options[:parallel] &&
|
78
|
-
!@config_store.
|
78
|
+
!@config_store.for_pwd.for_all_cops['UseCache']
|
79
79
|
raise OptionArgumentError, '-P/--parallel uses caching to speed up ' \
|
80
80
|
'execution, so combining with AllCops: ' \
|
81
81
|
'UseCache: false is not allowed.'
|
@@ -101,11 +101,9 @@ module RuboCop
|
|
101
101
|
|
102
102
|
def set_options_to_config_loader
|
103
103
|
ConfigLoader.debug = @options[:debug]
|
104
|
-
ConfigLoader.auto_gen_config = @options[:auto_gen_config]
|
105
104
|
ConfigLoader.disable_pending_cops = @options[:disable_pending_cops]
|
106
105
|
ConfigLoader.enable_pending_cops = @options[:enable_pending_cops]
|
107
106
|
ConfigLoader.ignore_parent_exclusion = @options[:ignore_parent_exclusion]
|
108
|
-
ConfigLoader.options_config = @options[:config]
|
109
107
|
end
|
110
108
|
|
111
109
|
def handle_exiting_options
|
@@ -123,7 +121,7 @@ module RuboCop
|
|
123
121
|
if @options[:auto_gen_config]
|
124
122
|
formatter = 'autogenconf'
|
125
123
|
else
|
126
|
-
cfg = @config_store.
|
124
|
+
cfg = @config_store.for_pwd.for_all_cops
|
127
125
|
formatter = cfg['DefaultFormatter'] || 'progress'
|
128
126
|
end
|
129
127
|
[[formatter, @options[:output_path]]]
|
@@ -7,6 +7,8 @@ module RuboCop
|
|
7
7
|
class AutoGenerateConfig < Base
|
8
8
|
self.command_name = :auto_gen_config
|
9
9
|
|
10
|
+
AUTO_GENERATED_FILE = '.rubocop_todo.yml'
|
11
|
+
|
10
12
|
PHASE_1 = 'Phase 1 of 2: run Layout/LineLength cop'
|
11
13
|
PHASE_2 = 'Phase 2 of 2: run all cops'
|
12
14
|
|
@@ -25,10 +27,10 @@ module RuboCop
|
|
25
27
|
private
|
26
28
|
|
27
29
|
def maybe_run_line_length_cop
|
28
|
-
if !line_length_enabled?(@config_store.
|
30
|
+
if !line_length_enabled?(@config_store.for_pwd)
|
29
31
|
skip_line_length_cop(PHASE_1_DISABLED)
|
30
32
|
elsif !same_max_line_length?(
|
31
|
-
@config_store.
|
33
|
+
@config_store.for_pwd, ConfigLoader.default_configuration
|
32
34
|
)
|
33
35
|
skip_line_length_cop(PHASE_1_OVERRIDDEN)
|
34
36
|
else
|
@@ -67,7 +69,7 @@ module RuboCop
|
|
67
69
|
@options.delete(:only)
|
68
70
|
@config_store = ConfigStore.new
|
69
71
|
# Save the todo configuration of the LineLength cop.
|
70
|
-
IO.read(
|
72
|
+
IO.read(AUTO_GENERATED_FILE)
|
71
73
|
.lines
|
72
74
|
.drop_while { |line| line.start_with?('#') }
|
73
75
|
.join
|
@@ -78,7 +80,7 @@ module RuboCop
|
|
78
80
|
result = execute_runner
|
79
81
|
# This run was made with the current maximum length allowed, so append
|
80
82
|
# the saved setting for LineLength.
|
81
|
-
File.open(
|
83
|
+
File.open(AUTO_GENERATED_FILE, 'a') do |f|
|
82
84
|
f.write(line_length_contents)
|
83
85
|
end
|
84
86
|
result
|
@@ -87,18 +89,51 @@ module RuboCop
|
|
87
89
|
def reset_config_and_auto_gen_file
|
88
90
|
@config_store = ConfigStore.new
|
89
91
|
@config_store.options_config = @options[:config] if @options[:config]
|
90
|
-
File.open(
|
91
|
-
|
92
|
+
File.open(AUTO_GENERATED_FILE, 'w') {}
|
93
|
+
add_inheritance_from_auto_generated_file(@options[:config])
|
92
94
|
end
|
93
95
|
|
94
96
|
def add_formatter
|
95
97
|
@options[:formatters] << [Formatter::DisabledConfigFormatter,
|
96
|
-
|
98
|
+
AUTO_GENERATED_FILE]
|
97
99
|
end
|
98
100
|
|
99
101
|
def execute_runner
|
100
102
|
Environment.new(@options, @config_store, @paths).run(:execute_runner)
|
101
103
|
end
|
104
|
+
|
105
|
+
def add_inheritance_from_auto_generated_file(config_file)
|
106
|
+
file_string = " #{AUTO_GENERATED_FILE}"
|
107
|
+
|
108
|
+
config_file ||= ConfigLoader::DOTFILE
|
109
|
+
|
110
|
+
if File.exist?(config_file)
|
111
|
+
files = Array(ConfigLoader.load_yaml_configuration(config_file)['inherit_from'])
|
112
|
+
|
113
|
+
return if files.include?(AUTO_GENERATED_FILE)
|
114
|
+
|
115
|
+
files.unshift(AUTO_GENERATED_FILE)
|
116
|
+
file_string = "\n - #{files.join("\n - ")}" if files.size > 1
|
117
|
+
rubocop_yml_contents = existing_configuration(config_file)
|
118
|
+
end
|
119
|
+
|
120
|
+
write_config_file(config_file, file_string, rubocop_yml_contents)
|
121
|
+
|
122
|
+
puts "Added inheritance from `#{AUTO_GENERATED_FILE}` in `#{ConfigLoader::DOTFILE}`."
|
123
|
+
end
|
124
|
+
|
125
|
+
def existing_configuration(config_file)
|
126
|
+
IO.read(config_file, encoding: Encoding::UTF_8)
|
127
|
+
.sub(/^inherit_from: *[^\n]+/, '')
|
128
|
+
.sub(/^inherit_from: *(\n *- *[^\n]+)+/, '')
|
129
|
+
end
|
130
|
+
|
131
|
+
def write_config_file(file_name, file_string, rubocop_yml_contents)
|
132
|
+
File.open(file_name, 'w') do |f|
|
133
|
+
f.write "inherit_from:#{file_string}\n"
|
134
|
+
f.write "\n#{rubocop_yml_contents}" if /\S/.match?(rubocop_yml_contents)
|
135
|
+
end
|
136
|
+
end
|
102
137
|
end
|
103
138
|
end
|
104
139
|
end
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
# RuboCop will start looking for the configuration file in the directory
|
28
28
|
# where the inspected file is and continue its way up to the root directory.
|
29
29
|
#
|
30
|
-
# See https://
|
30
|
+
# See https://docs.rubocop.org/rubocop/configuration
|
31
31
|
DESC
|
32
32
|
|
33
33
|
File.open(DOTFILE, 'w') do |f|
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
49
49
|
|
50
50
|
def print_cop_details(cops)
|
51
51
|
cops.each do |cop|
|
52
|
-
puts '# Supports --auto-correct' if cop.
|
52
|
+
puts '# Supports --auto-correct' if cop.support_autocorrect?
|
53
53
|
puts "#{cop.cop_name}:"
|
54
54
|
puts config_lines(cop)
|
55
55
|
puts
|
@@ -68,7 +68,7 @@ module RuboCop
|
|
68
68
|
|
69
69
|
def config_lines(cop)
|
70
70
|
cnf = @config.for_cop(cop)
|
71
|
-
cnf.to_yaml.lines.to_a.drop(1).map { |line|
|
71
|
+
cnf.to_yaml.lines.to_a.drop(1).map { |line| " #{line}" }
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -8,8 +8,8 @@ module RuboCop
|
|
8
8
|
self.command_name = :version
|
9
9
|
|
10
10
|
def run
|
11
|
-
puts RuboCop::Version.version(false) if @options[:version]
|
12
|
-
puts RuboCop::Version.version(true) if @options[:verbose_version]
|
11
|
+
puts RuboCop::Version.version(debug: false) if @options[:version]
|
12
|
+
puts RuboCop::Version.version(debug: true) if @options[:verbose_version]
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -11,7 +11,7 @@ module RuboCop
|
|
11
11
|
COPS_PATTERN = "(all|#{COP_NAMES_PATTERN})"
|
12
12
|
|
13
13
|
COMMENT_DIRECTIVE_REGEXP = Regexp.new(
|
14
|
-
|
14
|
+
"# rubocop : ((?:disable|enable|todo))\\b #{COPS_PATTERN}"
|
15
15
|
.gsub(' ', '\s*')
|
16
16
|
)
|
17
17
|
|
@@ -55,7 +55,7 @@ module RuboCop
|
|
55
55
|
extras
|
56
56
|
end
|
57
57
|
|
58
|
-
def analyze
|
58
|
+
def analyze # rubocop:todo Metrics/AbcSize
|
59
59
|
analyses = Hash.new { |hash, key| hash[key] = CopAnalysis.new([], nil) }
|
60
60
|
|
61
61
|
each_mentioned_cop do |cop_name, disabled, line, single_line|
|
data/lib/rubocop/config.rb
CHANGED
@@ -47,7 +47,7 @@ module RuboCop
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def_delegators :@hash, :[], :[]=, :delete, :each, :key?, :keys, :each_key,
|
50
|
-
:map, :merge, :to_h, :to_hash, :transform_values
|
50
|
+
:fetch, :map, :merge, :to_h, :to_hash, :transform_values
|
51
51
|
def_delegators :@validator, :validate, :target_ruby_version
|
52
52
|
|
53
53
|
def to_s
|
@@ -104,12 +104,29 @@ module RuboCop
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
+
# @return [Config] for the given cop / cop name.
|
108
|
+
# Note: the 'Enabled' attribute is calculated according to the department's
|
109
|
+
# and 'AllCops' configuration; other attributes are not inherited.
|
107
110
|
def for_cop(cop)
|
108
111
|
@for_cop[cop.respond_to?(:cop_name) ? cop.cop_name : cop]
|
109
112
|
end
|
110
113
|
|
114
|
+
# @return [Config] for the given cop merged with that of its department (if any)
|
115
|
+
# Note: the 'Enabled' attribute is same as that returned by `for_cop`
|
116
|
+
def for_badge(badge)
|
117
|
+
cop_config = for_cop(badge.to_s)
|
118
|
+
fetch(badge.department.to_s) { return cop_config }
|
119
|
+
.merge(cop_config)
|
120
|
+
end
|
121
|
+
|
122
|
+
# @return [Config] for the given department name.
|
123
|
+
# Note: the 'Enabled' attribute will be present only if specified
|
124
|
+
# at the department's level
|
111
125
|
def for_department(department_name)
|
112
|
-
@
|
126
|
+
@for_department ||= Hash.new do |h, dept|
|
127
|
+
h[dept] = self[dept] || {}
|
128
|
+
end
|
129
|
+
@for_department[department_name.to_s]
|
113
130
|
end
|
114
131
|
|
115
132
|
def for_all_cops
|
@@ -152,7 +169,7 @@ module RuboCop
|
|
152
169
|
return true if File.extname(file) == '.gemspec'
|
153
170
|
|
154
171
|
file_to_include?(file) do |pattern, relative_path, absolute_path|
|
155
|
-
|
172
|
+
/[A-Z]/.match?(pattern.to_s) &&
|
156
173
|
(match_path?(pattern, relative_path) ||
|
157
174
|
match_path?(pattern, absolute_path))
|
158
175
|
end
|