rubocop 0.83.0 → 0.87.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 +26 -18
- data/config/default.yml +128 -23
- data/lib/rubocop.rb +21 -59
- data/lib/rubocop/ast_aliases.rb +8 -0
- data/lib/rubocop/cli.rb +2 -4
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +42 -7
- data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
- data/lib/rubocop/cli/command/show_cops.rb +2 -6
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/config_loader.rb +24 -70
- data/lib/rubocop/config_loader_resolver.rb +21 -9
- data/lib/rubocop/config_obsoletion.rb +0 -1
- data/lib/rubocop/config_store.rb +12 -2
- data/lib/rubocop/cop/autocorrect_logic.rb +14 -25
- data/lib/rubocop/cop/base.rb +399 -0
- data/lib/rubocop/cop/bundler/gem_comment.rb +70 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +10 -20
- data/lib/rubocop/cop/commissioner.rb +48 -71
- data/lib/rubocop/cop/cop.rb +91 -227
- data/lib/rubocop/cop/corrector.rb +38 -115
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -6
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/generator.rb +2 -2
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/ignored_node.rb +1 -3
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +11 -14
- data/lib/rubocop/cop/layout/case_indentation.rb +21 -22
- data/lib/rubocop/cop/layout/class_structure.rb +19 -16
- 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_around_access_modifier.rb +2 -6
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +57 -4
- data/lib/rubocop/cop/layout/end_of_line.rb +3 -3
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -4
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +1 -3
- 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 -3
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +8 -9
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +3 -7
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +20 -103
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
- data/lib/rubocop/cop/layout/line_length.rb +17 -17
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -2
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
- data/lib/rubocop/cop/layout/space_after_colon.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +19 -25
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -3
- 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_before_comment.rb +1 -3
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +2 -4
- 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/layout/space_inside_reference_brackets.rb +1 -3
- 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_operator.rb +5 -2
- data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +137 -0
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -3
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +38 -2
- data/lib/rubocop/cop/lint/interpolation_check.rb +13 -0
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +69 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
- 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/parentheses_as_grouped_expression.rb +20 -5
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/raise_exception.rb +12 -4
- data/lib/rubocop/cop/lint/rand_one.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +31 -25
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -2
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -0
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +9 -1
- data/lib/rubocop/cop/lint/suppressed_exception.rb +15 -2
- data/lib/rubocop/cop/lint/syntax.rb +11 -28
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -4
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/metrics/block_length.rb +22 -0
- data/lib/rubocop/cop/metrics/class_length.rb +25 -2
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +35 -3
- data/lib/rubocop/cop/metrics/method_length.rb +23 -0
- data/lib/rubocop/cop/metrics/module_length.rb +25 -2
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +129 -0
- data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
- data/lib/rubocop/cop/migration/department_name.rb +7 -7
- data/lib/rubocop/cop/mixin/alignment.rb +1 -3
- data/lib/rubocop/cop/mixin/allowed_methods.rb +19 -0
- data/lib/rubocop/cop/mixin/array_min_size.rb +1 -3
- data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -9
- data/lib/rubocop/cop/mixin/code_length.rb +4 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +3 -5
- 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 +3 -1
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
- 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 +43 -0
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/surrounding_space.rb +10 -5
- data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -13
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +7 -5
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +27 -4
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +3 -3
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
- data/lib/rubocop/cop/naming/file_name.rb +28 -17
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +4 -6
- 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 +63 -10
- data/lib/rubocop/cop/severity.rb +1 -3
- data/lib/rubocop/cop/style/accessor_grouping.rb +136 -0
- data/lib/rubocop/cop/style/and_or.rb +2 -2
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +2 -2
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +121 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +4 -12
- 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/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -4
- data/lib/rubocop/cop/style/copyright.rb +5 -5
- 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 +2 -2
- data/lib/rubocop/cop/style/double_negation.rb +41 -4
- data/lib/rubocop/cop/style/empty_case_condition.rb +8 -6
- data/lib/rubocop/cop/style/empty_literal.rb +6 -8
- data/lib/rubocop/cop/style/empty_method.rb +1 -1
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
- data/lib/rubocop/cop/style/exponential_notation.rb +5 -5
- 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/hash_each_methods.rb +1 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +16 -7
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
- data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -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/ip_addresses.rb +1 -1
- 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/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 +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/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 -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/non_nil_check.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -2
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -6
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +4 -10
- data/lib/rubocop/cop/style/redundant_assignment.rb +117 -0
- data/lib/rubocop/cop/style/redundant_conditional.rb +4 -3
- data/lib/rubocop/cop/style/redundant_exception.rb +14 -10
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +122 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +10 -8
- data/lib/rubocop/cop/style/redundant_percent_q.rb +3 -3
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +90 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +121 -0
- data/lib/rubocop/cop/style/redundant_self.rb +6 -9
- data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -6
- 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 +1 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +2 -6
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +23 -2
- data/lib/rubocop/cop/style/symbol_array.rb +5 -5
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +3 -3
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +3 -3
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +13 -13
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +3 -3
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -3
- data/lib/rubocop/cop/style/trivial_accessors.rb +8 -7
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +1 -1
- 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 +2 -2
- data/lib/rubocop/cop/team.rb +141 -81
- data/lib/rubocop/cop/util.rb +3 -3
- data/lib/rubocop/cop/utils/format_string.rb +19 -2
- data/lib/rubocop/cop/variable_force.rb +3 -9
- data/lib/rubocop/cop/variable_force/branch.rb +1 -3
- data/lib/rubocop/cop/variable_force/variable.rb +2 -6
- data/lib/rubocop/ext/processed_source.rb +18 -0
- data/lib/rubocop/formatter/base_formatter.rb +0 -4
- data/lib/rubocop/formatter/disabled_config_formatter.rb +5 -13
- data/lib/rubocop/formatter/formatter_set.rb +2 -4
- data/lib/rubocop/formatter/junit_formatter.rb +14 -4
- data/lib/rubocop/magic_comment.rb +1 -1
- data/lib/rubocop/name_similarity.rb +7 -3
- data/lib/rubocop/options.rb +30 -15
- data/lib/rubocop/path_util.rb +2 -2
- data/lib/rubocop/platform.rb +1 -1
- data/lib/rubocop/rake_task.rb +6 -9
- data/lib/rubocop/remote_config.rb +1 -3
- data/lib/rubocop/result_cache.rb +5 -7
- data/lib/rubocop/rspec/cop_helper.rb +5 -28
- data/lib/rubocop/rspec/expect_offense.rb +60 -23
- data/lib/rubocop/rspec/shared_contexts.rb +55 -17
- data/lib/rubocop/runner.rb +42 -38
- data/lib/rubocop/target_finder.rb +2 -4
- data/lib/rubocop/target_ruby.rb +5 -2
- data/lib/rubocop/version.rb +5 -3
- metadata +60 -62
- data/lib/rubocop/ast/builder.rb +0 -85
- data/lib/rubocop/ast/node.rb +0 -637
- 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 -70
- data/lib/rubocop/ast/node/block_node.rb +0 -121
- data/lib/rubocop/ast/node/break_node.rb +0 -17
- data/lib/rubocop/ast/node/case_match_node.rb +0 -56
- 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 -269
- 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 -17
- 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 -202
- data/lib/rubocop/cop/mixin/classish_length.rb +0 -37
- data/lib/rubocop/node_pattern.rb +0 -887
- data/lib/rubocop/processed_source.rb +0 -213
- data/lib/rubocop/token.rb +0 -114
data/lib/rubocop/rake_task.rb
CHANGED
@@ -8,14 +8,11 @@ module RuboCop
|
|
8
8
|
#
|
9
9
|
# require 'rubocop/rake_task'
|
10
10
|
# RuboCop::RakeTask.new
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
attr_accessor :patterns
|
16
|
-
attr_accessor :formatters
|
17
|
-
attr_accessor :requires
|
18
|
-
attr_accessor :options
|
11
|
+
#
|
12
|
+
# Use global Rake namespace here to avoid namespace issues with custom
|
13
|
+
# rubocop-rake tasks
|
14
|
+
class RakeTask < ::Rake::TaskLib
|
15
|
+
attr_accessor :name, :verbose, :fail_on_error, :patterns, :formatters, :requires, :options
|
19
16
|
|
20
17
|
def initialize(name = :rubocop, *args, &task_block)
|
21
18
|
setup_ivars(name)
|
@@ -69,7 +66,7 @@ module RuboCop
|
|
69
66
|
task(:auto_correct, *args) do |_, task_args|
|
70
67
|
RakeFileUtils.verbose(verbose) do
|
71
68
|
yield(*[self, task_args].slice(0, task_block.arity)) if block_given?
|
72
|
-
options = full_options.unshift('--auto-correct')
|
69
|
+
options = full_options.unshift('--auto-correct-all')
|
73
70
|
options.delete('--parallel')
|
74
71
|
run_cli(verbose, options)
|
75
72
|
end
|
@@ -56,9 +56,7 @@ module RuboCop
|
|
56
56
|
def generate_request(uri)
|
57
57
|
request = Net::HTTP::Get.new(uri.request_uri)
|
58
58
|
|
59
|
-
if cache_path_exists?
|
60
|
-
request['If-Modified-Since'] = File.stat(cache_path).mtime.rfc2822
|
61
|
-
end
|
59
|
+
request['If-Modified-Since'] = File.stat(cache_path).mtime.rfc2822 if cache_path_exists?
|
62
60
|
|
63
61
|
yield request
|
64
62
|
end
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -33,16 +33,14 @@ module RuboCop
|
|
33
33
|
|
34
34
|
def requires_file_removal?(file_count, config_store)
|
35
35
|
file_count > 1 &&
|
36
|
-
file_count > config_store.
|
36
|
+
file_count > config_store.for_dir('.').for_all_cops['MaxFilesInCache']
|
37
37
|
end
|
38
38
|
|
39
39
|
def remove_oldest_files(files, dirs, cache_root, verbose)
|
40
40
|
# Add 1 to half the number of files, so that we remove the file if
|
41
41
|
# there's only 1 left.
|
42
42
|
remove_count = 1 + files.length / 2
|
43
|
-
if verbose
|
44
|
-
puts "Removing the #{remove_count} oldest files from #{cache_root}"
|
45
|
-
end
|
43
|
+
puts "Removing the #{remove_count} oldest files from #{cache_root}" if verbose
|
46
44
|
sorted = files.sort_by { |path| File.mtime(path) }
|
47
45
|
remove_files(sorted, dirs, remove_count)
|
48
46
|
rescue Errno::ENOENT
|
@@ -62,7 +60,7 @@ module RuboCop
|
|
62
60
|
end
|
63
61
|
|
64
62
|
def self.cache_root(config_store)
|
65
|
-
root = config_store.
|
63
|
+
root = config_store.for_dir('.').for_all_cops['CacheRootDirectory']
|
66
64
|
root ||= if ENV.key?('XDG_CACHE_HOME')
|
67
65
|
# Include user ID in the path to make sure the user has write
|
68
66
|
# access.
|
@@ -74,7 +72,7 @@ module RuboCop
|
|
74
72
|
end
|
75
73
|
|
76
74
|
def self.allow_symlinks_in_cache_location?(config_store)
|
77
|
-
config_store.
|
75
|
+
config_store.for_dir('.').for_all_cops['AllowSymlinksInCacheRootDirectory']
|
78
76
|
end
|
79
77
|
|
80
78
|
def initialize(file, team, options, config_store, cache_root = nil)
|
@@ -145,7 +143,7 @@ module RuboCop
|
|
145
143
|
digester = Digest::SHA1.new
|
146
144
|
mode = File.stat(file).mode
|
147
145
|
digester.update(
|
148
|
-
"#{file}#{mode}#{config_store.
|
146
|
+
"#{file}#{mode}#{config_store.for_file(file).signature}"
|
149
147
|
)
|
150
148
|
digester.file(file)
|
151
149
|
digester.hexdigest
|
@@ -43,37 +43,14 @@ module CopHelper
|
|
43
43
|
processed_source = parse_source(source, file)
|
44
44
|
_investigate(cop, processed_source)
|
45
45
|
|
46
|
-
|
47
|
-
RuboCop::Cop::Corrector.new(processed_source.buffer, cop.corrections)
|
48
|
-
corrector.rewrite
|
49
|
-
end
|
50
|
-
|
51
|
-
def autocorrect_source_with_loop(source, file = nil)
|
52
|
-
cnt = 0
|
53
|
-
loop do
|
54
|
-
cop.instance_variable_set(:@corrections, [])
|
55
|
-
new_source = autocorrect_source(source, file)
|
56
|
-
return new_source if new_source == source
|
57
|
-
|
58
|
-
source = new_source
|
59
|
-
cnt += 1
|
60
|
-
if cnt > RuboCop::Runner::MAX_ITERATIONS
|
61
|
-
raise RuboCop::Runner::InfiniteCorrectionLoop.new(file, [])
|
62
|
-
end
|
63
|
-
end
|
46
|
+
@last_corrector.rewrite
|
64
47
|
end
|
65
48
|
|
66
49
|
def _investigate(cop, processed_source)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
commissioner =
|
74
|
-
RuboCop::Cop::Commissioner.new([cop], forces, raise_error: true)
|
75
|
-
commissioner.investigate(processed_source)
|
76
|
-
commissioner
|
50
|
+
team = RuboCop::Cop::Team.new([cop], nil, raise_error: true)
|
51
|
+
report = team.investigate(processed_source)
|
52
|
+
@last_corrector = report.correctors.first || RuboCop::Cop::Corrector.new(processed_source)
|
53
|
+
report.offenses
|
77
54
|
end
|
78
55
|
end
|
79
56
|
|
@@ -71,9 +71,37 @@ module RuboCop
|
|
71
71
|
# RUBY
|
72
72
|
#
|
73
73
|
# expect_no_corrections
|
74
|
+
#
|
75
|
+
# If your code has variables of different lengths, you can use `%{foo}`,
|
76
|
+
# `^{foo}`, and `_{foo}` to format your template:
|
77
|
+
#
|
78
|
+
# %w[raise fail].each do |keyword|
|
79
|
+
# expect_offense(<<~RUBY, keyword: keyword)
|
80
|
+
# %{keyword}(RuntimeError, msg)
|
81
|
+
# ^{keyword}^^^^^^^^^^^^^^^^^^^ Redundant `RuntimeError` argument can be removed.
|
82
|
+
# RUBY
|
83
|
+
#
|
84
|
+
# %w[has_one has_many].each do |type|
|
85
|
+
# expect_offense(<<~RUBY, type: type)
|
86
|
+
# class Book
|
87
|
+
# %{type} :chapter, foreign_key: 'book_id'
|
88
|
+
# _{type} ^^^^^^^^^^^^^^^^^^^^^^ Specifying the default value is redundant.
|
89
|
+
# end
|
90
|
+
# RUBY
|
91
|
+
# end
|
74
92
|
module ExpectOffense
|
93
|
+
def format_offense(source, **replacements)
|
94
|
+
replacements.each do |keyword, value|
|
95
|
+
source = source.gsub("%{#{keyword}}", value)
|
96
|
+
.gsub("^{#{keyword}}", '^' * value.size)
|
97
|
+
.gsub("_{#{keyword}}", ' ' * value.size)
|
98
|
+
end
|
99
|
+
source
|
100
|
+
end
|
101
|
+
|
75
102
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
76
|
-
def expect_offense(source, file = nil)
|
103
|
+
def expect_offense(source, file = nil, severity: nil, **replacements)
|
104
|
+
source = format_offense(source, **replacements)
|
77
105
|
RuboCop::Formatter::DisabledConfigFormatter
|
78
106
|
.config_to_allow_offenses = {}
|
79
107
|
RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
|
@@ -88,53 +116,62 @@ module RuboCop
|
|
88
116
|
@processed_source = parse_source(expected_annotations.plain_source,
|
89
117
|
file)
|
90
118
|
|
91
|
-
unless @processed_source.valid_syntax?
|
92
|
-
raise 'Error parsing example code'
|
93
|
-
end
|
119
|
+
raise 'Error parsing example code' unless @processed_source.valid_syntax?
|
94
120
|
|
95
|
-
_investigate(cop, @processed_source)
|
121
|
+
offenses = _investigate(cop, @processed_source)
|
96
122
|
actual_annotations =
|
97
|
-
expected_annotations.with_offense_annotations(
|
123
|
+
expected_annotations.with_offense_annotations(offenses)
|
98
124
|
|
99
125
|
expect(actual_annotations.to_s).to eq(expected_annotations.to_s)
|
126
|
+
expect(offenses.map(&:severity).uniq).to eq([severity]) if severity
|
100
127
|
end
|
101
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
102
128
|
|
103
|
-
def expect_correction(correction)
|
104
|
-
unless @processed_source
|
105
|
-
|
106
|
-
|
129
|
+
def expect_correction(correction, loop: true)
|
130
|
+
raise '`expect_correction` must follow `expect_offense`' unless @processed_source
|
131
|
+
|
132
|
+
iteration = 0
|
133
|
+
new_source = loop do
|
134
|
+
iteration += 1
|
135
|
+
|
136
|
+
corrected_source = @last_corrector.rewrite
|
107
137
|
|
108
|
-
|
109
|
-
|
110
|
-
|
138
|
+
break corrected_source unless loop
|
139
|
+
break corrected_source if @last_corrector.empty?
|
140
|
+
break corrected_source if corrected_source == @processed_source.buffer.source
|
141
|
+
|
142
|
+
if iteration > RuboCop::Runner::MAX_ITERATIONS
|
143
|
+
raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [])
|
144
|
+
end
|
145
|
+
|
146
|
+
# Prepare for next loop
|
147
|
+
@processed_source = parse_source(corrected_source,
|
148
|
+
@processed_source.path)
|
149
|
+
_investigate(cop, @processed_source)
|
150
|
+
end
|
111
151
|
|
112
152
|
expect(new_source).to eq(correction)
|
113
153
|
end
|
154
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
114
155
|
|
115
156
|
def expect_no_corrections
|
116
|
-
unless @processed_source
|
117
|
-
raise '`expect_no_corrections` must follow `expect_offense`'
|
118
|
-
end
|
157
|
+
raise '`expect_no_corrections` must follow `expect_offense`' unless @processed_source
|
119
158
|
|
120
|
-
return if
|
159
|
+
return if @last_corrector.empty?
|
121
160
|
|
122
161
|
# In order to print a nice diff, e.g. what source got corrected to,
|
123
162
|
# we need to run the actual corrections
|
124
163
|
|
125
|
-
|
126
|
-
RuboCop::Cop::Corrector.new(@processed_source.buffer, cop.corrections)
|
127
|
-
new_source = corrector.rewrite
|
164
|
+
new_source = @last_corrector.rewrite
|
128
165
|
|
129
166
|
expect(new_source).to eq(@processed_source.buffer.source)
|
130
167
|
end
|
131
168
|
|
132
169
|
def expect_no_offenses(source, file = nil)
|
133
|
-
inspect_source(source, file)
|
170
|
+
offenses = inspect_source(source, file)
|
134
171
|
|
135
172
|
expected_annotations = AnnotatedSource.parse(source)
|
136
173
|
actual_annotations =
|
137
|
-
expected_annotations.with_offense_annotations(
|
174
|
+
expected_annotations.with_offense_annotations(offenses)
|
138
175
|
expect(actual_annotations.to_s).to eq(source)
|
139
176
|
end
|
140
177
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'tmpdir'
|
4
|
-
require 'fileutils'
|
5
4
|
|
6
5
|
RSpec.shared_context 'isolated environment', :isolated_environment do
|
7
6
|
around do |example|
|
@@ -38,28 +37,67 @@ RSpec.shared_context 'isolated environment', :isolated_environment do
|
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
|
-
#
|
42
|
-
RSpec.shared_context 'config', :config do
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
raise '`config` must be used in `describe SomeCopClass do .. end`'
|
47
|
-
end
|
40
|
+
# This context assumes nothing and defines `cop`, among others.
|
41
|
+
RSpec.shared_context 'config', :config do # rubocop:disable Metrics/BlockLength
|
42
|
+
### Meant to be overridden at will
|
43
|
+
|
44
|
+
let(:source) { 'code = {some: :ruby}' }
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
hash[cop_name] = RuboCop::ConfigLoader
|
54
|
-
.default_configuration[cop_name]
|
55
|
-
.merge('Enabled' => true) # in case it is 'pending'
|
56
|
-
.merge(cop_config)
|
46
|
+
let(:cop_class) do
|
47
|
+
unless described_class.is_a?(Class) && described_class < RuboCop::Cop::Base
|
48
|
+
raise 'Specify which cop class to use (e.g `let(:cop_class) { RuboCop::Cop::Base }`, ' \
|
49
|
+
'or RuboCop::Cop::Cop for legacy)'
|
57
50
|
end
|
51
|
+
described_class
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:cop_config) { {} }
|
55
|
+
|
56
|
+
let(:other_cops) { {} }
|
57
|
+
|
58
|
+
let(:cop_options) { {} }
|
59
|
+
|
60
|
+
### Utilities
|
61
|
+
|
62
|
+
def source_range(range, buffer: source_buffer)
|
63
|
+
Parser::Source::Range.new(buffer, range.begin,
|
64
|
+
range.exclude_end? ? range.end : range.end + 1)
|
65
|
+
end
|
66
|
+
|
67
|
+
### Useful intermediary steps (less likely to be overridden)
|
58
68
|
|
59
|
-
|
69
|
+
let(:processed_source) { parse_source(source, 'test') }
|
70
|
+
|
71
|
+
let(:source_buffer) { processed_source.buffer }
|
72
|
+
|
73
|
+
let(:all_cops_config) do
|
74
|
+
rails = { 'TargetRubyVersion' => ruby_version }
|
75
|
+
rails['TargetRailsVersion'] = rails_version if rails_version
|
76
|
+
rails
|
77
|
+
end
|
78
|
+
|
79
|
+
let(:cur_cop_config) do
|
80
|
+
RuboCop::ConfigLoader
|
81
|
+
.default_configuration.for_cop(cop_class)
|
82
|
+
.merge({
|
83
|
+
'Enabled' => true, # in case it is 'pending'
|
84
|
+
'AutoCorrect' => true # in case defaults set it to false
|
85
|
+
})
|
86
|
+
.merge(cop_config)
|
87
|
+
end
|
88
|
+
|
89
|
+
let(:config) do
|
90
|
+
hash = { 'AllCops' => all_cops_config,
|
91
|
+
cop_class.cop_name => cur_cop_config }.merge!(other_cops)
|
60
92
|
|
61
93
|
RuboCop::Config.new(hash, "#{Dir.pwd}/.rubocop.yml")
|
62
94
|
end
|
95
|
+
|
96
|
+
let(:cop) do
|
97
|
+
cop_class.new(config, cop_options).tap do |cop|
|
98
|
+
cop.send :begin_investigation, processed_source
|
99
|
+
end
|
100
|
+
end
|
63
101
|
end
|
64
102
|
|
65
103
|
RSpec.shared_context 'mock console output' do
|
data/lib/rubocop/runner.rb
CHANGED
@@ -80,9 +80,7 @@ module RuboCop
|
|
80
80
|
# OPTIMIZE: Calling `ResultCache.cleanup` takes time. This optimization
|
81
81
|
# mainly targets editors that integrates RuboCop. When RuboCop is run
|
82
82
|
# by an editor, it should be inspecting only one file.
|
83
|
-
if files.size > 1 && cached_run?
|
84
|
-
ResultCache.cleanup(@config_store, @options[:debug])
|
85
|
-
end
|
83
|
+
ResultCache.cleanup(@config_store, @options[:debug]) if files.size > 1 && cached_run?
|
86
84
|
formatter_set.finished(inspected_files.freeze)
|
87
85
|
formatter_set.close_output_files
|
88
86
|
end
|
@@ -122,7 +120,8 @@ module RuboCop
|
|
122
120
|
file_offense_cache(file) do
|
123
121
|
source = get_processed_source(file)
|
124
122
|
source, offenses = do_inspection_loop(file, source)
|
125
|
-
add_redundant_disables(file, offenses.compact.sort, source)
|
123
|
+
offenses = add_redundant_disables(file, offenses.compact.sort, source)
|
124
|
+
offenses.sort.reject(&:disabled?).freeze
|
126
125
|
end
|
127
126
|
end
|
128
127
|
|
@@ -131,7 +130,7 @@ module RuboCop
|
|
131
130
|
end
|
132
131
|
|
133
132
|
def file_offense_cache(file)
|
134
|
-
config = @config_store.
|
133
|
+
config = @config_store.for_file(file)
|
135
134
|
cache = cached_result(file, standby_team(config)) if cached_run?
|
136
135
|
|
137
136
|
if cache&.valid?
|
@@ -153,16 +152,30 @@ module RuboCop
|
|
153
152
|
end
|
154
153
|
|
155
154
|
def add_redundant_disables(file, offenses, source)
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
155
|
+
team_for_redundant_disables(file, offenses, source) do |team|
|
156
|
+
new_offenses, redundant_updated = inspect_file(source, team)
|
157
|
+
offenses += new_offenses
|
158
|
+
if redundant_updated
|
159
|
+
# Do one extra inspection loop if any redundant disables were
|
160
|
+
# removed. This is done in order to find rubocop:enable directives that
|
161
|
+
# have now become useless.
|
162
|
+
_source, new_offenses = do_inspection_loop(file,
|
163
|
+
get_processed_source(file))
|
164
|
+
offenses |= new_offenses
|
162
165
|
end
|
163
166
|
end
|
167
|
+
offenses
|
168
|
+
end
|
169
|
+
|
170
|
+
def team_for_redundant_disables(file, offenses, source)
|
171
|
+
return unless check_for_redundant_disables?(source)
|
164
172
|
|
165
|
-
|
173
|
+
config = @config_store.for_file(file)
|
174
|
+
team = Cop::Team.mobilize([Cop::Lint::RedundantCopDisableDirective], config, @options)
|
175
|
+
return if team.cops.empty?
|
176
|
+
|
177
|
+
team.cops.first.offenses_to_check = offenses
|
178
|
+
yield team
|
166
179
|
end
|
167
180
|
|
168
181
|
def check_for_redundant_disables?(source)
|
@@ -170,7 +183,7 @@ module RuboCop
|
|
170
183
|
end
|
171
184
|
|
172
185
|
def redundant_cop_disable_directive(file)
|
173
|
-
config = @config_store.
|
186
|
+
config = @config_store.for_file(file)
|
174
187
|
if config.for_cop(Cop::Lint::RedundantCopDisableDirective)
|
175
188
|
.fetch('Enabled')
|
176
189
|
cop = Cop::Lint::RedundantCopDisableDirective.new(config, @options)
|
@@ -182,22 +195,6 @@ module RuboCop
|
|
182
195
|
@options[:except] || @options[:only]
|
183
196
|
end
|
184
197
|
|
185
|
-
def autocorrect_redundant_disables(file, source, cop, offenses)
|
186
|
-
cop.processed_source = source
|
187
|
-
|
188
|
-
team = Cop::Team.new(RuboCop::Cop::Registry.new, nil, @options)
|
189
|
-
team.autocorrect(source.buffer, [cop])
|
190
|
-
|
191
|
-
return [] unless team.updated_source_file?
|
192
|
-
|
193
|
-
# Do one extra inspection loop if any redundant disables were
|
194
|
-
# removed. This is done in order to find rubocop:enable directives that
|
195
|
-
# have now become useless.
|
196
|
-
_source, new_offenses = do_inspection_loop(file,
|
197
|
-
get_processed_source(file))
|
198
|
-
new_offenses - offenses
|
199
|
-
end
|
200
|
-
|
201
198
|
def file_started(file)
|
202
199
|
puts "Scanning #{file}" if @options[:debug]
|
203
200
|
formatter_set.file_started(file,
|
@@ -216,7 +213,7 @@ module RuboCop
|
|
216
213
|
@cached_run ||=
|
217
214
|
(@options[:cache] == 'true' ||
|
218
215
|
@options[:cache] != 'false' &&
|
219
|
-
@config_store.
|
216
|
+
@config_store.for_dir(Dir.pwd).for_all_cops['UseCache']) &&
|
220
217
|
# When running --auto-gen-config, there's some processing done in the
|
221
218
|
# cops related to calculating the Max parameters for Metrics cops. We
|
222
219
|
# need to do that processing and cannot use caching.
|
@@ -295,13 +292,16 @@ module RuboCop
|
|
295
292
|
@processed_sources << checksum
|
296
293
|
end
|
297
294
|
|
298
|
-
def inspect_file(processed_source)
|
299
|
-
|
300
|
-
team = Cop::Team.new(mobilized_cop_classes(config), config, @options)
|
301
|
-
offenses = team.inspect_file(processed_source)
|
295
|
+
def inspect_file(processed_source, team = mobilize_team(processed_source))
|
296
|
+
report = team.investigate(processed_source)
|
302
297
|
@errors.concat(team.errors)
|
303
298
|
@warnings.concat(team.warnings)
|
304
|
-
[offenses, team.updated_source_file?]
|
299
|
+
[report.offenses, team.updated_source_file?]
|
300
|
+
end
|
301
|
+
|
302
|
+
def mobilize_team(processed_source)
|
303
|
+
config = @config_store.for_file(processed_source.path)
|
304
|
+
Cop::Team.mobilize(mobilized_cop_classes(config), config, @options)
|
305
305
|
end
|
306
306
|
|
307
307
|
def mobilized_cop_classes(config)
|
@@ -362,12 +362,16 @@ module RuboCop
|
|
362
362
|
end
|
363
363
|
|
364
364
|
def get_processed_source(file)
|
365
|
-
ruby_version = @config_store.
|
365
|
+
ruby_version = @config_store.for_file(file).target_ruby_version
|
366
366
|
|
367
367
|
if @options[:stdin]
|
368
368
|
ProcessedSource.new(@options[:stdin], ruby_version, file)
|
369
369
|
else
|
370
|
-
|
370
|
+
begin
|
371
|
+
ProcessedSource.from_file(file, ruby_version)
|
372
|
+
rescue Errno::ENOENT
|
373
|
+
raise RuboCop::Error, "No such file or directory: #{file}"
|
374
|
+
end
|
371
375
|
end
|
372
376
|
end
|
373
377
|
|
@@ -378,7 +382,7 @@ module RuboCop
|
|
378
382
|
def standby_team(config)
|
379
383
|
@team_by_config ||= {}
|
380
384
|
@team_by_config[config.object_id] ||=
|
381
|
-
Cop::Team.
|
385
|
+
Cop::Team.mobilize(mobilized_cop_classes(config), config, @options)
|
382
386
|
end
|
383
387
|
end
|
384
388
|
end
|