rubocop 0.80.1 → 0.85.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 +4 -4
- data/config/default.yml +202 -49
- data/lib/rubocop.rb +20 -61
- data/lib/rubocop/ast_aliases.rb +8 -0
- data/lib/rubocop/cli.rb +13 -7
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +2 -2
- data/lib/rubocop/cli/command/show_cops.rb +2 -6
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +14 -2
- data/lib/rubocop/config_loader.rb +37 -33
- data/lib/rubocop/config_loader_resolver.rb +45 -6
- data/lib/rubocop/config_obsoletion.rb +2 -0
- data/lib/rubocop/config_store.rb +12 -2
- data/lib/rubocop/config_validator.rb +18 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -2
- data/lib/rubocop/cop/badge.rb +5 -5
- data/lib/rubocop/cop/bundler/gem_comment.rb +70 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
- data/lib/rubocop/cop/commissioner.rb +0 -21
- data/lib/rubocop/cop/cop.rb +14 -6
- data/lib/rubocop/cop/corrector.rb +48 -24
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +4 -8
- data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -2
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +4 -4
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
- data/lib/rubocop/cop/correctors/string_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
- data/lib/rubocop/cop/generator.rb +4 -3
- data/lib/rubocop/cop/ignored_node.rb +1 -3
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/array_alignment.rb +53 -10
- data/lib/rubocop/cop/layout/block_end_newline.rb +5 -3
- data/lib/rubocop/cop/layout/case_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/class_structure.rb +19 -16
- data/lib/rubocop/cop/layout/condition_position.rb +12 -2
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +8 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +126 -0
- data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -3
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +14 -10
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +6 -6
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +5 -9
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +20 -103
- data/lib/rubocop/cop/layout/{tab.rb → indentation_style.rb} +48 -6
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +23 -20
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +13 -4
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -3
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +131 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +19 -2
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +1 -3
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_range_literal.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -3
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +41 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +14 -0
- data/lib/rubocop/cop/lint/boolean_symbol.rb +12 -0
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +137 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -5
- data/lib/rubocop/cop/lint/empty_when.rb +29 -6
- data/lib/rubocop/cop/lint/ensure_return.rb +19 -2
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +2 -4
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
- data/lib/rubocop/cop/lint/interpolation_check.rb +1 -1
- data/lib/rubocop/cop/lint/literal_as_condition.rb +10 -13
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/loop.rb +7 -5
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +62 -0
- data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +7 -7
- data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +33 -11
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
- data/lib/rubocop/cop/lint/raise_exception.rb +75 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -6
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
- data/lib/rubocop/cop/lint/struct_new_override.rb +58 -0
- data/lib/rubocop/cop/lint/suppressed_exception.rb +23 -26
- data/lib/rubocop/cop/lint/syntax.rb +1 -3
- data/lib/rubocop/cop/lint/unified_integer.rb +0 -2
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/unused_method_argument.rb +32 -6
- data/lib/rubocop/cop/lint/uri_regexp.rb +4 -4
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +13 -3
- data/lib/rubocop/cop/lint/useless_assignment.rb +3 -2
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +6 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/migration/department_name.rb +22 -9
- data/lib/rubocop/cop/mixin/alignment.rb +1 -3
- data/lib/rubocop/cop/mixin/array_min_size.rb +1 -3
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -9
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +2 -4
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +6 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +10 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +9 -2
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +3 -2
- data/lib/rubocop/cop/mixin/method_complexity.rb +5 -0
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -1
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +16 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -22
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +1 -1
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
- data/lib/rubocop/cop/naming/constant_name.rb +2 -1
- data/lib/rubocop/cop/naming/file_name.rb +27 -14
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +26 -0
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
- data/lib/rubocop/cop/registry.rb +12 -7
- data/lib/rubocop/cop/severity.rb +1 -3
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -6
- data/lib/rubocop/cop/style/alias.rb +4 -4
- data/lib/rubocop/cop/style/and_or.rb +7 -8
- data/lib/rubocop/cop/style/array_join.rb +2 -2
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -8
- data/lib/rubocop/cop/style/case_equality.rb +24 -1
- data/lib/rubocop/cop/style/character_literal.rb +2 -2
- data/lib/rubocop/cop/style/collection_methods.rb +2 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +9 -11
- data/lib/rubocop/cop/style/copyright.rb +3 -3
- data/lib/rubocop/cop/style/dir.rb +1 -1
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +49 -0
- data/lib/rubocop/cop/style/documentation.rb +43 -5
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +41 -4
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
- data/lib/rubocop/cop/style/each_with_object.rb +3 -3
- data/lib/rubocop/cop/style/empty_literal.rb +1 -3
- data/lib/rubocop/cop/style/empty_method.rb +2 -6
- data/lib/rubocop/cop/style/end_block.rb +6 -0
- data/lib/rubocop/cop/style/even_odd.rb +1 -1
- data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -3
- data/lib/rubocop/cop/style/exponential_notation.rb +119 -0
- data/lib/rubocop/cop/style/format_string.rb +2 -2
- data/lib/rubocop/cop/style/format_string_token.rb +2 -3
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -6
- data/lib/rubocop/cop/style/guard_clause.rb +25 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +6 -4
- data/lib/rubocop/cop/style/hash_syntax.rb +19 -12
- data/lib/rubocop/cop/style/hash_transform_keys.rb +6 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +6 -5
- data/lib/rubocop/cop/style/if_unless_modifier.rb +23 -3
- data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -0
- data/lib/rubocop/cop/style/inline_comment.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
- data/lib/rubocop/cop/style/lambda.rb +3 -2
- data/lib/rubocop/cop/style/lambda_call.rb +1 -21
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/module_function.rb +58 -12
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +16 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +2 -4
- data/lib/rubocop/cop/style/negated_if.rb +3 -3
- data/lib/rubocop/cop/style/negated_unless.rb +3 -3
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -2
- data/lib/rubocop/cop/style/next.rb +2 -2
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
- data/lib/rubocop/cop/style/non_nil_check.rb +5 -5
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
- data/lib/rubocop/cop/style/one_line_conditional.rb +6 -9
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
- data/lib/rubocop/cop/style/or_assignment.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
- data/lib/rubocop/cop/style/redundant_condition.rb +3 -4
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +3 -3
- data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -6
- data/lib/rubocop/cop/style/redundant_percent_q.rb +3 -3
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +89 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +130 -0
- data/lib/rubocop/cop/style/redundant_return.rb +5 -7
- data/lib/rubocop/cop/style/redundant_self.rb +1 -1
- data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/return_nil.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +3 -7
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +39 -0
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -7
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -4
- data/lib/rubocop/cop/style/string_hash_keys.rb +1 -1
- data/lib/rubocop/cop/style/symbol_array.rb +2 -2
- data/lib/rubocop/cop/style/symbol_literal.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -5
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +35 -0
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +41 -0
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +88 -0
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +44 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -3
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +0 -4
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +1 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -1
- data/lib/rubocop/cop/team.rb +61 -25
- data/lib/rubocop/cop/util.rb +25 -1
- data/lib/rubocop/cop/variable_force.rb +3 -9
- data/lib/rubocop/cop/variable_force/assignment.rb +1 -0
- data/lib/rubocop/cop/variable_force/branch.rb +1 -3
- data/lib/rubocop/cop/variable_force/scope.rb +1 -0
- data/lib/rubocop/cop/variable_force/variable.rb +3 -6
- data/lib/rubocop/ext/processed_source.rb +18 -0
- data/lib/rubocop/formatter/base_formatter.rb +0 -4
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -12
- data/lib/rubocop/formatter/formatter_set.rb +1 -4
- data/lib/rubocop/formatter/junit_formatter.rb +27 -6
- data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
- data/lib/rubocop/formatter/tap_formatter.rb +1 -1
- data/lib/rubocop/magic_comment.rb +1 -1
- data/lib/rubocop/name_similarity.rb +12 -9
- data/lib/rubocop/options.rb +33 -12
- data/lib/rubocop/remote_config.rb +1 -3
- data/lib/rubocop/result_cache.rb +5 -7
- data/lib/rubocop/rspec/cop_helper.rb +3 -26
- data/lib/rubocop/rspec/expect_offense.rb +46 -16
- data/lib/rubocop/rspec/shared_contexts.rb +54 -20
- data/lib/rubocop/runner.rb +21 -14
- data/lib/rubocop/target_finder.rb +7 -7
- data/lib/rubocop/target_ruby.rb +5 -2
- data/lib/rubocop/version.rb +5 -3
- metadata +50 -77
- data/lib/rubocop/ast/builder.rb +0 -83
- data/lib/rubocop/ast/node.rb +0 -632
- data/lib/rubocop/ast/node/alias_node.rb +0 -24
- data/lib/rubocop/ast/node/and_node.rb +0 -29
- data/lib/rubocop/ast/node/args_node.rb +0 -29
- data/lib/rubocop/ast/node/array_node.rb +0 -57
- data/lib/rubocop/ast/node/block_node.rb +0 -117
- data/lib/rubocop/ast/node/break_node.rb +0 -17
- data/lib/rubocop/ast/node/case_node.rb +0 -56
- data/lib/rubocop/ast/node/class_node.rb +0 -31
- data/lib/rubocop/ast/node/def_node.rb +0 -82
- data/lib/rubocop/ast/node/defined_node.rb +0 -17
- data/lib/rubocop/ast/node/ensure_node.rb +0 -17
- data/lib/rubocop/ast/node/float_node.rb +0 -12
- data/lib/rubocop/ast/node/for_node.rb +0 -53
- data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
- data/lib/rubocop/ast/node/hash_node.rb +0 -109
- data/lib/rubocop/ast/node/if_node.rb +0 -175
- data/lib/rubocop/ast/node/int_node.rb +0 -12
- data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
- data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
- data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
- data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -261
- data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
- data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
- data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
- data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
- data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
- data/lib/rubocop/ast/node/module_node.rb +0 -24
- data/lib/rubocop/ast/node/or_node.rb +0 -29
- data/lib/rubocop/ast/node/pair_node.rb +0 -63
- data/lib/rubocop/ast/node/range_node.rb +0 -18
- data/lib/rubocop/ast/node/regexp_node.rb +0 -33
- data/lib/rubocop/ast/node/resbody_node.rb +0 -24
- data/lib/rubocop/ast/node/retry_node.rb +0 -17
- data/lib/rubocop/ast/node/return_node.rb +0 -24
- data/lib/rubocop/ast/node/self_class_node.rb +0 -24
- data/lib/rubocop/ast/node/send_node.rb +0 -13
- data/lib/rubocop/ast/node/str_node.rb +0 -16
- data/lib/rubocop/ast/node/super_node.rb +0 -21
- data/lib/rubocop/ast/node/symbol_node.rb +0 -12
- data/lib/rubocop/ast/node/until_node.rb +0 -35
- data/lib/rubocop/ast/node/when_node.rb +0 -53
- data/lib/rubocop/ast/node/while_node.rb +0 -35
- data/lib/rubocop/ast/node/yield_node.rb +0 -21
- data/lib/rubocop/ast/sexp.rb +0 -16
- data/lib/rubocop/ast/traversal.rb +0 -200
- data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
- data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
- data/lib/rubocop/node_pattern.rb +0 -887
- data/lib/rubocop/processed_source.rb +0 -216
- data/lib/rubocop/string_util.rb +0 -14
- data/lib/rubocop/token.rb +0 -114
data/lib/rubocop.rb
CHANGED
@@ -1,73 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'parser'
|
4
3
|
require 'rainbow'
|
5
4
|
|
6
5
|
require 'English'
|
7
6
|
require 'set'
|
8
7
|
require 'forwardable'
|
8
|
+
require 'regexp_parser'
|
9
9
|
require 'unicode/display_width/no_string_ext'
|
10
|
+
require 'rubocop-ast'
|
11
|
+
require_relative 'rubocop/ast_aliases'
|
10
12
|
|
11
13
|
require_relative 'rubocop/version'
|
12
14
|
|
13
15
|
require_relative 'rubocop/core_ext/string'
|
16
|
+
require_relative 'rubocop/ext/processed_source'
|
17
|
+
|
14
18
|
require_relative 'rubocop/path_util'
|
15
19
|
require_relative 'rubocop/file_finder'
|
16
20
|
require_relative 'rubocop/platform'
|
17
|
-
require_relative 'rubocop/string_util'
|
18
21
|
require_relative 'rubocop/name_similarity'
|
19
|
-
require_relative 'rubocop/node_pattern'
|
20
22
|
require_relative 'rubocop/string_interpreter'
|
21
|
-
require_relative 'rubocop/ast/sexp'
|
22
|
-
require_relative 'rubocop/ast/node'
|
23
|
-
require_relative 'rubocop/ast/node/mixin/method_identifier_predicates'
|
24
|
-
require_relative 'rubocop/ast/node/mixin/binary_operator_node'
|
25
|
-
require_relative 'rubocop/ast/node/mixin/collection_node'
|
26
|
-
require_relative 'rubocop/ast/node/mixin/conditional_node'
|
27
|
-
require_relative 'rubocop/ast/node/mixin/hash_element_node'
|
28
|
-
require_relative 'rubocop/ast/node/mixin/method_dispatch_node'
|
29
|
-
require_relative 'rubocop/ast/node/mixin/modifier_node'
|
30
|
-
require_relative 'rubocop/ast/node/mixin/numeric_node'
|
31
|
-
require_relative 'rubocop/ast/node/mixin/parameterized_node'
|
32
|
-
require_relative 'rubocop/ast/node/mixin/predicate_operator_node'
|
33
|
-
require_relative 'rubocop/ast/node/mixin/basic_literal_node'
|
34
|
-
require_relative 'rubocop/ast/node/alias_node'
|
35
|
-
require_relative 'rubocop/ast/node/and_node'
|
36
|
-
require_relative 'rubocop/ast/node/args_node'
|
37
|
-
require_relative 'rubocop/ast/node/array_node'
|
38
|
-
require_relative 'rubocop/ast/node/block_node'
|
39
|
-
require_relative 'rubocop/ast/node/break_node'
|
40
|
-
require_relative 'rubocop/ast/node/case_node'
|
41
|
-
require_relative 'rubocop/ast/node/class_node'
|
42
|
-
require_relative 'rubocop/ast/node/def_node'
|
43
|
-
require_relative 'rubocop/ast/node/defined_node'
|
44
|
-
require_relative 'rubocop/ast/node/ensure_node'
|
45
|
-
require_relative 'rubocop/ast/node/for_node'
|
46
|
-
require_relative 'rubocop/ast/node/forward_args_node'
|
47
|
-
require_relative 'rubocop/ast/node/float_node'
|
48
|
-
require_relative 'rubocop/ast/node/hash_node'
|
49
|
-
require_relative 'rubocop/ast/node/if_node'
|
50
|
-
require_relative 'rubocop/ast/node/int_node'
|
51
|
-
require_relative 'rubocop/ast/node/keyword_splat_node'
|
52
|
-
require_relative 'rubocop/ast/node/module_node'
|
53
|
-
require_relative 'rubocop/ast/node/or_node'
|
54
|
-
require_relative 'rubocop/ast/node/pair_node'
|
55
|
-
require_relative 'rubocop/ast/node/range_node'
|
56
|
-
require_relative 'rubocop/ast/node/regexp_node'
|
57
|
-
require_relative 'rubocop/ast/node/resbody_node'
|
58
|
-
require_relative 'rubocop/ast/node/retry_node'
|
59
|
-
require_relative 'rubocop/ast/node/return_node'
|
60
|
-
require_relative 'rubocop/ast/node/self_class_node'
|
61
|
-
require_relative 'rubocop/ast/node/send_node'
|
62
|
-
require_relative 'rubocop/ast/node/str_node'
|
63
|
-
require_relative 'rubocop/ast/node/super_node'
|
64
|
-
require_relative 'rubocop/ast/node/symbol_node'
|
65
|
-
require_relative 'rubocop/ast/node/until_node'
|
66
|
-
require_relative 'rubocop/ast/node/when_node'
|
67
|
-
require_relative 'rubocop/ast/node/while_node'
|
68
|
-
require_relative 'rubocop/ast/node/yield_node'
|
69
|
-
require_relative 'rubocop/ast/builder'
|
70
|
-
require_relative 'rubocop/ast/traversal'
|
71
23
|
require_relative 'rubocop/error'
|
72
24
|
require_relative 'rubocop/warning'
|
73
25
|
|
@@ -146,6 +98,7 @@ require_relative 'rubocop/cop/mixin/percent_literal'
|
|
146
98
|
require_relative 'rubocop/cop/mixin/preceding_following_alignment'
|
147
99
|
require_relative 'rubocop/cop/mixin/preferred_delimiters'
|
148
100
|
require_relative 'rubocop/cop/mixin/rational_literal'
|
101
|
+
require_relative 'rubocop/cop/mixin/regexp_literal_help'
|
149
102
|
require_relative 'rubocop/cop/mixin/rescue_node'
|
150
103
|
require_relative 'rubocop/cop/mixin/safe_assignment'
|
151
104
|
require_relative 'rubocop/cop/mixin/space_after_punctuation'
|
@@ -212,10 +165,11 @@ require_relative 'rubocop/cop/layout/empty_line_after_magic_comment'
|
|
212
165
|
require_relative 'rubocop/cop/layout/empty_line_between_defs'
|
213
166
|
require_relative 'rubocop/cop/layout/empty_lines_around_access_modifier'
|
214
167
|
require_relative 'rubocop/cop/layout/empty_lines_around_arguments'
|
168
|
+
require_relative 'rubocop/cop/layout/empty_lines_around_attribute_accessor'
|
215
169
|
require_relative 'rubocop/cop/layout/empty_lines_around_begin_body'
|
216
170
|
require_relative 'rubocop/cop/layout/empty_lines_around_block_body'
|
217
171
|
require_relative 'rubocop/cop/layout/empty_lines_around_class_body'
|
218
|
-
require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords'
|
172
|
+
require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords'
|
219
173
|
require_relative 'rubocop/cop/layout/empty_lines_around_method_body'
|
220
174
|
require_relative 'rubocop/cop/layout/empty_lines_around_module_body'
|
221
175
|
require_relative 'rubocop/cop/layout/empty_lines'
|
@@ -234,6 +188,7 @@ require_relative 'rubocop/cop/layout/hash_alignment'
|
|
234
188
|
require_relative 'rubocop/cop/layout/heredoc_argument_closing_parenthesis'
|
235
189
|
require_relative 'rubocop/cop/layout/heredoc_indentation'
|
236
190
|
require_relative 'rubocop/cop/layout/indentation_consistency'
|
191
|
+
require_relative 'rubocop/cop/layout/indentation_style'
|
237
192
|
require_relative 'rubocop/cop/layout/indentation_width'
|
238
193
|
require_relative 'rubocop/cop/layout/initial_indentation'
|
239
194
|
require_relative 'rubocop/cop/layout/leading_comment_space'
|
@@ -260,6 +215,7 @@ require_relative 'rubocop/cop/layout/space_after_semicolon'
|
|
260
215
|
require_relative 'rubocop/cop/layout/space_around_block_parameters'
|
261
216
|
require_relative 'rubocop/cop/layout/space_around_equals_in_parameter_default'
|
262
217
|
require_relative 'rubocop/cop/layout/space_around_keyword'
|
218
|
+
require_relative 'rubocop/cop/layout/space_around_method_call_operator'
|
263
219
|
require_relative 'rubocop/cop/layout/space_around_operators'
|
264
220
|
require_relative 'rubocop/cop/layout/space_before_block_braces'
|
265
221
|
require_relative 'rubocop/cop/layout/space_before_comma'
|
@@ -276,7 +232,6 @@ require_relative 'rubocop/cop/layout/space_inside_percent_literal_delimiters'
|
|
276
232
|
require_relative 'rubocop/cop/layout/space_inside_range_literal'
|
277
233
|
require_relative 'rubocop/cop/layout/space_inside_reference_brackets'
|
278
234
|
require_relative 'rubocop/cop/layout/space_inside_string_interpolation'
|
279
|
-
require_relative 'rubocop/cop/layout/tab'
|
280
235
|
require_relative 'rubocop/cop/layout/trailing_empty_lines'
|
281
236
|
require_relative 'rubocop/cop/layout/trailing_whitespace'
|
282
237
|
|
@@ -289,6 +244,7 @@ require_relative 'rubocop/cop/lint/boolean_symbol'
|
|
289
244
|
require_relative 'rubocop/cop/lint/circular_argument_reference'
|
290
245
|
require_relative 'rubocop/cop/lint/debugger'
|
291
246
|
require_relative 'rubocop/cop/lint/deprecated_class_methods'
|
247
|
+
require_relative 'rubocop/cop/lint/deprecated_open_ssl_constant'
|
292
248
|
require_relative 'rubocop/cop/lint/disjunctive_assignment_in_constructor'
|
293
249
|
require_relative 'rubocop/cop/lint/duplicate_case_condition'
|
294
250
|
require_relative 'rubocop/cop/lint/duplicate_hash_key'
|
@@ -299,7 +255,6 @@ require_relative 'rubocop/cop/lint/empty_ensure'
|
|
299
255
|
require_relative 'rubocop/cop/lint/empty_expression'
|
300
256
|
require_relative 'rubocop/cop/lint/empty_interpolation'
|
301
257
|
require_relative 'rubocop/cop/lint/empty_when'
|
302
|
-
require_relative 'rubocop/cop/lint/end_in_method'
|
303
258
|
require_relative 'rubocop/cop/lint/ensure_return'
|
304
259
|
require_relative 'rubocop/cop/lint/erb_new_arguments'
|
305
260
|
require_relative 'rubocop/cop/lint/flip_flop'
|
@@ -314,6 +269,7 @@ require_relative 'rubocop/cop/lint/literal_as_condition'
|
|
314
269
|
require_relative 'rubocop/cop/lint/literal_in_interpolation'
|
315
270
|
require_relative 'rubocop/cop/lint/loop'
|
316
271
|
require_relative 'rubocop/cop/lint/missing_cop_enable_directive'
|
272
|
+
require_relative 'rubocop/cop/lint/mixed_regexp_capture_types'
|
317
273
|
require_relative 'rubocop/cop/lint/multiple_comparison'
|
318
274
|
require_relative 'rubocop/cop/lint/nested_method_definition'
|
319
275
|
require_relative 'rubocop/cop/lint/nested_percent_literal'
|
@@ -325,6 +281,7 @@ require_relative 'rubocop/cop/lint/ordered_magic_comments'
|
|
325
281
|
require_relative 'rubocop/cop/lint/parentheses_as_grouped_expression'
|
326
282
|
require_relative 'rubocop/cop/lint/percent_string_array'
|
327
283
|
require_relative 'rubocop/cop/lint/percent_symbol_array'
|
284
|
+
require_relative 'rubocop/cop/lint/raise_exception'
|
328
285
|
require_relative 'rubocop/cop/lint/rand_one'
|
329
286
|
require_relative 'rubocop/cop/lint/redundant_cop_disable_directive'
|
330
287
|
require_relative 'rubocop/cop/lint/redundant_cop_enable_directive'
|
@@ -346,6 +303,7 @@ require_relative 'rubocop/cop/lint/send_with_mixin_argument'
|
|
346
303
|
require_relative 'rubocop/cop/lint/shadowed_argument'
|
347
304
|
require_relative 'rubocop/cop/lint/shadowed_exception'
|
348
305
|
require_relative 'rubocop/cop/lint/shadowing_outer_local_variable'
|
306
|
+
require_relative 'rubocop/cop/lint/struct_new_override'
|
349
307
|
require_relative 'rubocop/cop/lint/suppressed_exception'
|
350
308
|
require_relative 'rubocop/cop/lint/syntax'
|
351
309
|
require_relative 'rubocop/cop/lint/to_json'
|
@@ -421,6 +379,7 @@ require_relative 'rubocop/cop/style/copyright'
|
|
421
379
|
require_relative 'rubocop/cop/style/date_time'
|
422
380
|
require_relative 'rubocop/cop/style/def_with_parentheses'
|
423
381
|
require_relative 'rubocop/cop/style/dir'
|
382
|
+
require_relative 'rubocop/cop/style/disable_cops_within_source_code_directive'
|
424
383
|
require_relative 'rubocop/cop/style/documentation_method'
|
425
384
|
require_relative 'rubocop/cop/style/documentation'
|
426
385
|
require_relative 'rubocop/cop/style/double_cop_disable_directive'
|
@@ -438,6 +397,7 @@ require_relative 'rubocop/cop/style/end_block'
|
|
438
397
|
require_relative 'rubocop/cop/style/eval_with_location'
|
439
398
|
require_relative 'rubocop/cop/style/even_odd'
|
440
399
|
require_relative 'rubocop/cop/style/expand_path_arguments'
|
400
|
+
require_relative 'rubocop/cop/style/exponential_notation'
|
441
401
|
require_relative 'rubocop/cop/style/float_division'
|
442
402
|
require_relative 'rubocop/cop/style/for'
|
443
403
|
require_relative 'rubocop/cop/style/format_string'
|
@@ -463,11 +423,9 @@ require_relative 'rubocop/cop/style/lambda'
|
|
463
423
|
require_relative 'rubocop/cop/style/lambda_call'
|
464
424
|
require_relative 'rubocop/cop/style/line_end_concatenation'
|
465
425
|
require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
|
466
|
-
# rubocop:disable Layout/LineLength
|
467
426
|
require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
|
468
427
|
require_relative 'rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses'
|
469
428
|
require_relative 'rubocop/cop/style/method_call_with_args_parentheses/require_parentheses'
|
470
|
-
# rubocop:enable Layout/LineLength
|
471
429
|
require_relative 'rubocop/cop/style/method_called_on_do_end_block'
|
472
430
|
require_relative 'rubocop/cop/style/method_def_parentheses'
|
473
431
|
require_relative 'rubocop/cop/style/method_missing_super'
|
@@ -521,6 +479,8 @@ require_relative 'rubocop/cop/style/redundant_freeze'
|
|
521
479
|
require_relative 'rubocop/cop/style/redundant_interpolation'
|
522
480
|
require_relative 'rubocop/cop/style/redundant_parentheses'
|
523
481
|
require_relative 'rubocop/cop/style/redundant_percent_q'
|
482
|
+
require_relative 'rubocop/cop/style/redundant_regexp_character_class'
|
483
|
+
require_relative 'rubocop/cop/style/redundant_regexp_escape'
|
524
484
|
require_relative 'rubocop/cop/style/redundant_return'
|
525
485
|
require_relative 'rubocop/cop/style/redundant_self'
|
526
486
|
require_relative 'rubocop/cop/style/redundant_sort'
|
@@ -537,6 +497,7 @@ require_relative 'rubocop/cop/style/send'
|
|
537
497
|
require_relative 'rubocop/cop/style/signal_exception'
|
538
498
|
require_relative 'rubocop/cop/style/single_line_block_params'
|
539
499
|
require_relative 'rubocop/cop/style/single_line_methods'
|
500
|
+
require_relative 'rubocop/cop/style/slicing_with_range'
|
540
501
|
require_relative 'rubocop/cop/style/special_global_vars'
|
541
502
|
require_relative 'rubocop/cop/style/stabby_lambda_parentheses'
|
542
503
|
require_relative 'rubocop/cop/style/stderr_puts'
|
@@ -555,6 +516,7 @@ require_relative 'rubocop/cop/style/trailing_body_on_method_definition'
|
|
555
516
|
require_relative 'rubocop/cop/style/trailing_body_on_module'
|
556
517
|
require_relative 'rubocop/cop/style/trailing_comma_in_arguments'
|
557
518
|
require_relative 'rubocop/cop/style/trailing_comma_in_array_literal'
|
519
|
+
require_relative 'rubocop/cop/style/trailing_comma_in_block_args'
|
558
520
|
require_relative 'rubocop/cop/style/trailing_comma_in_hash_literal'
|
559
521
|
require_relative 'rubocop/cop/style/trailing_method_end_statement'
|
560
522
|
require_relative 'rubocop/cop/style/trailing_underscore_variable'
|
@@ -582,7 +544,6 @@ require_relative 'rubocop/formatter/simple_text_formatter'
|
|
582
544
|
# relies on simple text
|
583
545
|
require_relative 'rubocop/formatter/clang_style_formatter'
|
584
546
|
require_relative 'rubocop/formatter/disabled_config_formatter'
|
585
|
-
require_relative 'rubocop/formatter/disabled_lines_formatter'
|
586
547
|
require_relative 'rubocop/formatter/emacs_style_formatter'
|
587
548
|
require_relative 'rubocop/formatter/file_list_formatter'
|
588
549
|
require_relative 'rubocop/formatter/fuubar_style_formatter'
|
@@ -608,10 +569,8 @@ require_relative 'rubocop/config_obsoletion'
|
|
608
569
|
require_relative 'rubocop/config_store'
|
609
570
|
require_relative 'rubocop/config_validator'
|
610
571
|
require_relative 'rubocop/target_finder'
|
611
|
-
require_relative 'rubocop/token'
|
612
572
|
require_relative 'rubocop/comment_config'
|
613
573
|
require_relative 'rubocop/magic_comment'
|
614
|
-
require_relative 'rubocop/processed_source'
|
615
574
|
require_relative 'rubocop/result_cache'
|
616
575
|
require_relative 'rubocop/runner'
|
617
576
|
require_relative 'rubocop/cli'
|
data/lib/rubocop/cli.rb
CHANGED
@@ -35,8 +35,8 @@ module RuboCop
|
|
35
35
|
if @options[:init]
|
36
36
|
run_command(:init)
|
37
37
|
else
|
38
|
-
validate_options_vs_config
|
39
38
|
act_on_options
|
39
|
+
validate_options_vs_config
|
40
40
|
apply_default_formatter
|
41
41
|
execute_runners
|
42
42
|
end
|
@@ -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_dir(Dir.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.'
|
@@ -83,10 +83,7 @@ module RuboCop
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def act_on_options
|
86
|
-
|
87
|
-
ConfigLoader.auto_gen_config = @options[:auto_gen_config]
|
88
|
-
ConfigLoader.ignore_parent_exclusion = @options[:ignore_parent_exclusion]
|
89
|
-
ConfigLoader.options_config = @options[:config]
|
86
|
+
set_options_to_config_loader
|
90
87
|
|
91
88
|
@config_store.options_config = @options[:config] if @options[:config]
|
92
89
|
@config_store.force_default_config! if @options[:force_default_config]
|
@@ -102,6 +99,15 @@ module RuboCop
|
|
102
99
|
end
|
103
100
|
end
|
104
101
|
|
102
|
+
def set_options_to_config_loader
|
103
|
+
ConfigLoader.debug = @options[:debug]
|
104
|
+
ConfigLoader.auto_gen_config = @options[:auto_gen_config]
|
105
|
+
ConfigLoader.disable_pending_cops = @options[:disable_pending_cops]
|
106
|
+
ConfigLoader.enable_pending_cops = @options[:enable_pending_cops]
|
107
|
+
ConfigLoader.ignore_parent_exclusion = @options[:ignore_parent_exclusion]
|
108
|
+
ConfigLoader.options_config = @options[:config]
|
109
|
+
end
|
110
|
+
|
105
111
|
def handle_exiting_options
|
106
112
|
return unless Options::EXITING_OPTIONS.any? { |o| @options.key? o }
|
107
113
|
|
@@ -117,7 +123,7 @@ module RuboCop
|
|
117
123
|
if @options[:auto_gen_config]
|
118
124
|
formatter = 'autogenconf'
|
119
125
|
else
|
120
|
-
cfg = @config_store.
|
126
|
+
cfg = @config_store.for_dir(Dir.pwd).for_all_cops
|
121
127
|
formatter = cfg['DefaultFormatter'] || 'progress'
|
122
128
|
end
|
123
129
|
[[formatter, @options[:output_path]]]
|
@@ -25,10 +25,10 @@ module RuboCop
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def maybe_run_line_length_cop
|
28
|
-
if !line_length_enabled?(@config_store.
|
28
|
+
if !line_length_enabled?(@config_store.for_dir(Dir.pwd))
|
29
29
|
skip_line_length_cop(PHASE_1_DISABLED)
|
30
30
|
elsif !same_max_line_length?(
|
31
|
-
@config_store.
|
31
|
+
@config_store.for_dir(Dir.pwd), ConfigLoader.default_configuration
|
32
32
|
)
|
33
33
|
skip_line_length_cop(PHASE_1_OVERRIDDEN)
|
34
34
|
else
|
@@ -42,18 +42,14 @@ module RuboCop
|
|
42
42
|
selected_cops_of_department(registry, department)
|
43
43
|
end
|
44
44
|
|
45
|
-
if show_all
|
46
|
-
puts "# Department '#{department}' (#{selected_cops.length}):"
|
47
|
-
end
|
45
|
+
puts "# Department '#{department}' (#{selected_cops.length}):" if show_all
|
48
46
|
|
49
47
|
print_cop_details(selected_cops)
|
50
48
|
end
|
51
49
|
|
52
50
|
def print_cop_details(cops)
|
53
51
|
cops.each do |cop|
|
54
|
-
if cop.new(@config).support_autocorrect?
|
55
|
-
puts '# Supports --auto-correct'
|
56
|
-
end
|
52
|
+
puts '# Supports --auto-correct' if cop.new(@config).support_autocorrect?
|
57
53
|
puts "#{cop.cop_name}:"
|
58
54
|
puts config_lines(cop)
|
59
55
|
puts
|
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
|
50
|
+
:map, :merge, :to_h, :to_hash, :transform_values
|
51
51
|
def_delegators :@validator, :validate, :target_ruby_version
|
52
52
|
|
53
53
|
def to_s
|
@@ -116,6 +116,14 @@ module RuboCop
|
|
116
116
|
@for_all_cops ||= self['AllCops'] || {}
|
117
117
|
end
|
118
118
|
|
119
|
+
def disabled_new_cops?
|
120
|
+
for_all_cops['NewCops'] == 'disable'
|
121
|
+
end
|
122
|
+
|
123
|
+
def enabled_new_cops?
|
124
|
+
for_all_cops['NewCops'] == 'enable'
|
125
|
+
end
|
126
|
+
|
119
127
|
def file_to_include?(file)
|
120
128
|
relative_file_path = path_relative_to_config(file)
|
121
129
|
|
@@ -253,9 +261,13 @@ module RuboCop
|
|
253
261
|
|
254
262
|
def enable_cop?(qualified_cop_name, cop_options)
|
255
263
|
department = department_of(qualified_cop_name)
|
264
|
+
cop_enabled = cop_options.fetch('Enabled') do
|
265
|
+
!for_all_cops['DisabledByDefault']
|
266
|
+
end
|
267
|
+
return true if cop_enabled == 'override_department'
|
256
268
|
return false if department && department['Enabled'] == false
|
257
269
|
|
258
|
-
|
270
|
+
cop_enabled
|
259
271
|
end
|
260
272
|
|
261
273
|
def department_of(qualified_cop_name)
|
@@ -24,7 +24,7 @@ module RuboCop
|
|
24
24
|
include FileFinder
|
25
25
|
|
26
26
|
attr_accessor :debug, :auto_gen_config, :ignore_parent_exclusion,
|
27
|
-
:options_config
|
27
|
+
:options_config, :disable_pending_cops, :enable_pending_cops
|
28
28
|
attr_writer :default_configuration
|
29
29
|
|
30
30
|
alias debug? debug
|
@@ -36,7 +36,7 @@ module RuboCop
|
|
36
36
|
FileFinder.root_level = nil
|
37
37
|
end
|
38
38
|
|
39
|
-
def load_file(file)
|
39
|
+
def load_file(file) # rubocop:disable Metrics/AbcSize
|
40
40
|
path = File.absolute_path(file.is_a?(RemoteConfig) ? file.file : file)
|
41
41
|
|
42
42
|
hash = load_yaml_configuration(path)
|
@@ -46,6 +46,7 @@ module RuboCop
|
|
46
46
|
|
47
47
|
add_missing_namespaces(path, hash)
|
48
48
|
|
49
|
+
resolver.override_department_setting_for_cops({}, hash)
|
49
50
|
resolver.resolve_inheritance_from_gems(hash)
|
50
51
|
resolver.resolve_inheritance(path, hash, file, debug?)
|
51
52
|
|
@@ -55,7 +56,10 @@ module RuboCop
|
|
55
56
|
end
|
56
57
|
|
57
58
|
def add_missing_namespaces(path, hash)
|
58
|
-
hash.
|
59
|
+
# Using `hash.each_key` will cause the
|
60
|
+
# `can't add a new key into hash during iteration` error
|
61
|
+
hash_keys = hash.keys
|
62
|
+
hash_keys.each do |key|
|
59
63
|
q = Cop::Cop.qualified_cop_name(key, path)
|
60
64
|
next if q == key
|
61
65
|
|
@@ -76,30 +80,33 @@ module RuboCop
|
|
76
80
|
# user's home directory is checked. If there's no .rubocop.yml
|
77
81
|
# there either, the path to the default file is returned.
|
78
82
|
def configuration_file_for(target_dir)
|
79
|
-
find_project_dotfile(target_dir) ||
|
80
|
-
|
81
|
-
find_user_xdg_config ||
|
82
|
-
DEFAULT_FILE
|
83
|
+
find_project_dotfile(target_dir) || find_user_dotfile ||
|
84
|
+
find_user_xdg_config || DEFAULT_FILE
|
83
85
|
end
|
84
86
|
|
85
87
|
def configuration_from_file(config_file)
|
86
|
-
|
87
|
-
return config if config_file == DEFAULT_FILE
|
88
|
+
return ConfigLoader.default_configuration if config_file == DEFAULT_FILE
|
88
89
|
|
90
|
+
config = load_file(config_file)
|
89
91
|
if ignore_parent_exclusion?
|
90
92
|
print 'Ignoring AllCops/Exclude from parent folders' if debug?
|
91
93
|
else
|
92
94
|
add_excludes_from_files(config, config_file)
|
93
95
|
end
|
96
|
+
|
94
97
|
merge_with_default(config, config_file).tap do |merged_config|
|
95
|
-
warn_on_pending_cops(merged_config.pending_cops)
|
98
|
+
warn_on_pending_cops(merged_config.pending_cops) unless possible_new_cops?(config)
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
102
|
+
def possible_new_cops?(config)
|
103
|
+
disable_pending_cops || enable_pending_cops ||
|
104
|
+
config.disabled_new_cops? || config.enabled_new_cops?
|
105
|
+
end
|
106
|
+
|
99
107
|
def add_excludes_from_files(config, config_file)
|
100
|
-
found_files =
|
101
|
-
|
102
|
-
[find_user_dotfile, find_user_xdg_config].compact
|
108
|
+
found_files = find_files_upwards(DOTFILE, config_file) +
|
109
|
+
[find_user_dotfile, find_user_xdg_config].compact
|
103
110
|
|
104
111
|
return if found_files.empty?
|
105
112
|
return if PathUtil.relative_path(found_files.last) ==
|
@@ -124,12 +131,12 @@ module RuboCop
|
|
124
131
|
'`false` in your `.rubocop.yml` file:').yellow
|
125
132
|
|
126
133
|
pending_cops.each do |cop|
|
127
|
-
|
128
|
-
|
129
|
-
).yellow
|
134
|
+
version = cop.metadata['VersionAdded'] || 'N/A'
|
135
|
+
|
136
|
+
warn Rainbow(" - #{cop.name} (#{version})").yellow
|
130
137
|
end
|
131
138
|
|
132
|
-
warn Rainbow('For more information: https://docs.rubocop.org/
|
139
|
+
warn Rainbow('For more information: https://docs.rubocop.org/rubocop/versioning.html').yellow
|
133
140
|
end
|
134
141
|
|
135
142
|
# Merges the given configuration with the default one. If
|
@@ -198,7 +205,7 @@ module RuboCop
|
|
198
205
|
def write_config_file(file_name, file_string, rubocop_yml_contents)
|
199
206
|
File.open(file_name, 'w') do |f|
|
200
207
|
f.write "inherit_from:#{file_string}\n"
|
201
|
-
f.write "\n#{rubocop_yml_contents}" if
|
208
|
+
f.write "\n#{rubocop_yml_contents}" if /\S/.match?(rubocop_yml_contents)
|
202
209
|
end
|
203
210
|
end
|
204
211
|
|
@@ -207,15 +214,16 @@ module RuboCop
|
|
207
214
|
end
|
208
215
|
|
209
216
|
def load_yaml_configuration(absolute_path)
|
210
|
-
|
217
|
+
file_contents = read_file(absolute_path)
|
218
|
+
yaml_code = Dir.chdir(File.dirname(absolute_path)) do
|
219
|
+
ERB.new(file_contents).result
|
220
|
+
end
|
211
221
|
check_duplication(yaml_code, absolute_path)
|
212
222
|
hash = yaml_safe_load(yaml_code, absolute_path) || {}
|
213
223
|
|
214
224
|
puts "configuration from #{absolute_path}" if debug?
|
215
225
|
|
216
|
-
unless hash.is_a?(Hash)
|
217
|
-
raise(TypeError, "Malformed configuration in #{absolute_path}")
|
218
|
-
end
|
226
|
+
raise(TypeError, "Malformed configuration in #{absolute_path}") unless hash.is_a?(Hash)
|
219
227
|
|
220
228
|
hash
|
221
229
|
end
|
@@ -231,8 +239,7 @@ module RuboCop
|
|
231
239
|
"#{smart_path}:#{line1}: " \
|
232
240
|
"`#{value}` is concealed by line #{line2}"
|
233
241
|
else
|
234
|
-
"#{smart_path}: "
|
235
|
-
"`#{value}` is concealed by duplicate"
|
242
|
+
"#{smart_path}: `#{value}` is concealed by duplicate"
|
236
243
|
end
|
237
244
|
warn Rainbow(message).yellow
|
238
245
|
end
|
@@ -250,17 +257,14 @@ module RuboCop
|
|
250
257
|
|
251
258
|
def yaml_safe_load(yaml_code, filename)
|
252
259
|
if defined?(SafeYAML) && SafeYAML.respond_to?(:load)
|
253
|
-
SafeYAML.load(yaml_code, filename,
|
254
|
-
whitelisted_tags: %w[!ruby/regexp])
|
260
|
+
SafeYAML.load(yaml_code, filename, whitelisted_tags: %w[!ruby/regexp])
|
255
261
|
# Ruby 2.6+
|
256
262
|
elsif Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
|
257
|
-
YAML.safe_load(
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
filename: filename
|
263
|
-
)
|
263
|
+
YAML.safe_load(yaml_code,
|
264
|
+
permitted_classes: [Regexp, Symbol],
|
265
|
+
permitted_symbols: [],
|
266
|
+
aliases: true,
|
267
|
+
filename: filename)
|
264
268
|
else
|
265
269
|
YAML.safe_load(yaml_code, [Regexp, Symbol], [], true, filename)
|
266
270
|
end
|