rubocop 0.72.0 → 0.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/bin/console +1 -0
- data/config/default.yml +93 -56
- data/lib/rubocop.rb +21 -10
- data/lib/rubocop/ast/builder.rb +1 -0
- data/lib/rubocop/ast/node.rb +12 -14
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +4 -4
- data/lib/rubocop/ast/node/return_node.rb +24 -0
- data/lib/rubocop/ast/traversal.rb +3 -3
- data/lib/rubocop/cli.rb +7 -4
- data/lib/rubocop/comment_config.rb +5 -4
- data/lib/rubocop/config.rb +28 -537
- data/lib/rubocop/config_loader.rb +21 -3
- data/lib/rubocop/config_loader_resolver.rb +4 -3
- data/lib/rubocop/config_obsoletion.rb +222 -0
- data/lib/rubocop/config_validator.rb +248 -0
- data/lib/rubocop/cop/autocorrect_logic.rb +71 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
- data/lib/rubocop/cop/commissioner.rb +18 -16
- data/lib/rubocop/cop/cop.rb +49 -14
- data/lib/rubocop/cop/corrector.rb +10 -10
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +43 -17
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- 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 +4 -4
- data/lib/rubocop/cop/generator/configuration_injector.rb +9 -4
- data/lib/rubocop/cop/generator/require_file_injector.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -2
- data/lib/rubocop/cop/layout/align_hash.rb +6 -2
- data/lib/rubocop/cop/layout/block_alignment.rb +3 -3
- data/lib/rubocop/cop/layout/class_structure.rb +1 -1
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
- data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +22 -7
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +2 -2
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +2 -2
- data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
- data/lib/rubocop/cop/layout/extra_spacing.rb +14 -59
- data/lib/rubocop/cop/layout/indent_assignment.rb +10 -1
- data/lib/rubocop/cop/layout/indent_first_argument.rb +10 -8
- data/lib/rubocop/cop/layout/indent_first_hash_element.rb +1 -1
- data/lib/rubocop/cop/layout/indent_heredoc.rb +4 -3
- data/lib/rubocop/cop/layout/indentation_width.rb +20 -6
- data/lib/rubocop/cop/layout/leading_comment_space.rb +28 -0
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +24 -2
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +20 -4
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +5 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +42 -23
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +8 -5
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +21 -2
- data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +24 -40
- data/lib/rubocop/cop/layout/tab.rb +10 -22
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +17 -4
- data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +4 -6
- data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -3
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
- data/lib/rubocop/cop/lint/empty_interpolation.rb +4 -4
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +62 -5
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +11 -37
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +7 -8
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
- data/lib/rubocop/cop/lint/multiple_compare.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -3
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +1 -1
- data/lib/rubocop/cop/lint/number_conversion.rb +3 -3
- data/lib/rubocop/cop/lint/rand_one.rb +1 -1
- data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +24 -24
- data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +6 -8
- data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +2 -2
- data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +12 -7
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +10 -11
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -1
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +91 -0
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +6 -6
- data/lib/rubocop/cop/lint/unified_integer.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/unused_block_argument.rb +22 -6
- data/lib/rubocop/cop/lint/unused_method_argument.rb +23 -5
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -1
- data/lib/rubocop/cop/lint/uri_regexp.rb +2 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +6 -6
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +7 -26
- data/lib/rubocop/cop/message_annotator.rb +16 -7
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/class_length.rb +1 -1
- data/lib/rubocop/cop/metrics/line_length.rb +7 -4
- data/lib/rubocop/cop/metrics/module_length.rb +1 -1
- data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
- data/lib/rubocop/cop/migration/department_name.rb +44 -0
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +0 -2
- data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +4 -4
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
- data/lib/rubocop/cop/mixin/interpolation.rb +27 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +3 -2
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +3 -3
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +87 -0
- data/lib/rubocop/cop/mixin/safe_mode.rb +2 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +5 -2
- data/lib/rubocop/cop/mixin/surrounding_space.rb +7 -5
- data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -6
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +2 -2
- data/lib/rubocop/cop/naming/file_name.rb +12 -5
- data/lib/rubocop/cop/naming/method_name.rb +12 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
- data/lib/rubocop/cop/naming/variable_name.rb +1 -0
- data/lib/rubocop/cop/offense.rb +18 -7
- data/lib/rubocop/cop/registry.rb +22 -1
- data/lib/rubocop/cop/security/eval.rb +1 -1
- data/lib/rubocop/cop/security/json_load.rb +1 -1
- data/lib/rubocop/cop/security/marshal_load.rb +1 -1
- data/lib/rubocop/cop/security/open.rb +1 -1
- data/lib/rubocop/cop/security/yaml_load.rb +1 -1
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -0
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +2 -2
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -1
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +35 -16
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
- data/lib/rubocop/cop/style/commented_keyword.rb +16 -30
- data/lib/rubocop/cop/style/conditional_assignment.rb +6 -8
- data/lib/rubocop/cop/style/constant_visibility.rb +14 -3
- data/lib/rubocop/cop/style/copyright.rb +11 -7
- data/lib/rubocop/cop/style/date_time.rb +3 -3
- data/lib/rubocop/cop/style/dir.rb +1 -1
- data/lib/rubocop/cop/style/documentation_method.rb +45 -1
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +55 -0
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
- data/lib/rubocop/cop/style/each_with_object.rb +1 -1
- data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +2 -2
- data/lib/rubocop/cop/style/empty_method.rb +5 -5
- data/lib/rubocop/cop/style/eval_with_location.rb +2 -2
- data/lib/rubocop/cop/style/even_odd.rb +1 -1
- data/lib/rubocop/cop/style/expand_path_arguments.rb +4 -4
- data/lib/rubocop/cop/style/float_division.rb +4 -4
- data/lib/rubocop/cop/style/format_string.rb +17 -14
- data/lib/rubocop/cop/style/format_string_token.rb +19 -68
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +28 -33
- data/lib/rubocop/cop/style/guard_clause.rb +39 -10
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -4
- data/lib/rubocop/cop/style/if_unless_modifier.rb +58 -15
- data/lib/rubocop/cop/style/infinite_loop.rb +5 -4
- data/lib/rubocop/cop/style/inverse_methods.rb +21 -15
- data/lib/rubocop/cop/style/lambda.rb +0 -2
- data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +25 -25
- data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
- data/lib/rubocop/cop/style/min_max.rb +1 -1
- data/lib/rubocop/cop/style/mixin_usage.rb +12 -2
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +55 -0
- data/lib/rubocop/cop/style/multiple_comparison.rb +1 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +3 -3
- data/lib/rubocop/cop/style/nested_modifier.rb +22 -4
- data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
- data/lib/rubocop/cop/style/numeric_predicate.rb +3 -3
- data/lib/rubocop/cop/style/option_hash.rb +1 -1
- data/lib/rubocop/cop/style/or_assignment.rb +8 -3
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +15 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +6 -6
- data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
- data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
- data/lib/rubocop/cop/style/redundant_conditional.rb +2 -2
- data/lib/rubocop/cop/style/redundant_exception.rb +2 -2
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +15 -6
- data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +37 -21
- data/lib/rubocop/cop/style/redundant_self.rb +18 -1
- data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +4 -4
- data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -1
- data/lib/rubocop/cop/style/rescue_modifier.rb +24 -0
- data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -2
- data/lib/rubocop/cop/style/return_nil.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +24 -4
- data/lib/rubocop/cop/style/sample.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +13 -2
- data/lib/rubocop/cop/style/single_line_methods.rb +8 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/string_hash_keys.rb +2 -2
- data/lib/rubocop/cop/style/strip.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +3 -3
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +20 -1
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +4 -6
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +6 -16
- data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -5
- data/lib/rubocop/cop/team.rb +15 -14
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/utils/format_string.rb +120 -0
- data/lib/rubocop/cop/variable_force.rb +7 -5
- data/lib/rubocop/cop/variable_force/variable.rb +15 -2
- data/lib/rubocop/core_ext/string.rb +0 -24
- data/lib/rubocop/error.rb +23 -0
- data/lib/rubocop/formatter/clang_style_formatter.rb +8 -3
- data/lib/rubocop/formatter/emacs_style_formatter.rb +22 -9
- data/lib/rubocop/formatter/file_list_formatter.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +16 -15
- data/lib/rubocop/formatter/pacman_formatter.rb +80 -0
- data/lib/rubocop/formatter/simple_text_formatter.rb +16 -4
- data/lib/rubocop/formatter/tap_formatter.rb +17 -4
- data/lib/rubocop/magic_comment.rb +4 -0
- data/lib/rubocop/node_pattern.rb +5 -3
- data/lib/rubocop/options.rb +33 -21
- data/lib/rubocop/path_util.rb +1 -1
- data/lib/rubocop/processed_source.rb +4 -0
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +4 -1
- data/lib/rubocop/rspec/shared_contexts.rb +12 -0
- data/lib/rubocop/runner.rb +42 -31
- data/lib/rubocop/target_finder.rb +12 -4
- data/lib/rubocop/version.rb +1 -1
- metadata +21 -12
- data/lib/rubocop/cop/mixin/ignored_method_patterns.rb +0 -19
@@ -42,9 +42,14 @@ module RuboCop
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def report_offense(file, offense)
|
45
|
-
output.printf(
|
46
|
-
|
47
|
-
|
45
|
+
output.printf(
|
46
|
+
"# %<path>s:%<line>d:%<column>d: %<severity>s: %<message>s\n",
|
47
|
+
path: cyan(smart_path(file)),
|
48
|
+
line: offense.line,
|
49
|
+
column: offense.real_column,
|
50
|
+
severity: colored_severity_code(offense),
|
51
|
+
message: message(offense)
|
52
|
+
)
|
48
53
|
|
49
54
|
# rubocop:disable Lint/HandleExceptions
|
50
55
|
begin
|
@@ -63,7 +68,15 @@ module RuboCop
|
|
63
68
|
end
|
64
69
|
|
65
70
|
def message(offense)
|
66
|
-
message =
|
71
|
+
message =
|
72
|
+
if offense.corrected_with_todo?
|
73
|
+
'[Todo] '
|
74
|
+
elsif offense.corrected?
|
75
|
+
'[Corrected] '
|
76
|
+
else
|
77
|
+
''
|
78
|
+
end
|
79
|
+
|
67
80
|
"#{message}#{annotate_message(offense.message)}"
|
68
81
|
end
|
69
82
|
end
|
data/lib/rubocop/node_pattern.rb
CHANGED
@@ -429,12 +429,13 @@ module RuboCop
|
|
429
429
|
[0..Float::INFINITY, 'true']
|
430
430
|
end
|
431
431
|
|
432
|
+
# rubocop:disable Metrics/AbcSize
|
432
433
|
# rubocop:disable Metrics/MethodLength
|
433
434
|
def compile_any_order(capture_all = nil)
|
434
435
|
rest = capture_rest = nil
|
435
436
|
patterns = []
|
436
437
|
with_temp_variables do |child, matched|
|
437
|
-
tokens_until('>', 'any child')
|
438
|
+
tokens_until('>', 'any child') do
|
438
439
|
fail_due_to 'ellipsis must be at the end of <>' if rest
|
439
440
|
token = tokens.shift
|
440
441
|
case token
|
@@ -448,6 +449,7 @@ module RuboCop
|
|
448
449
|
end
|
449
450
|
end
|
450
451
|
# rubocop:enable Metrics/MethodLength
|
452
|
+
# rubocop:enable Metrics/AbcSize
|
451
453
|
|
452
454
|
def insure_same_captures(enum, what)
|
453
455
|
return to_enum __method__, enum, what unless block_given?
|
@@ -612,7 +614,7 @@ module RuboCop
|
|
612
614
|
end
|
613
615
|
|
614
616
|
def emit_method_code
|
615
|
-
|
617
|
+
<<~RUBY
|
616
618
|
return unless #{@match_code}
|
617
619
|
block_given? ? #{emit_yield_capture} : (return #{emit_retval})
|
618
620
|
RUBY
|
@@ -746,7 +748,7 @@ module RuboCop
|
|
746
748
|
|
747
749
|
def node_search_body(method_name, trailing_params, prelude, match_code,
|
748
750
|
on_match)
|
749
|
-
|
751
|
+
<<~RUBY
|
750
752
|
def #{method_name}(node0#{trailing_params})
|
751
753
|
#{prelude}
|
752
754
|
node0.each_node do |node|
|
data/lib/rubocop/options.rb
CHANGED
@@ -109,6 +109,8 @@ module RuboCop
|
|
109
109
|
@validator.validate_exclude_limit_option
|
110
110
|
end
|
111
111
|
|
112
|
+
option(opts, '--disable-uncorrectable')
|
113
|
+
|
112
114
|
option(opts, '--no-offense-counts') do
|
113
115
|
@options[:no_offense_counts] = true
|
114
116
|
end
|
@@ -253,10 +255,17 @@ module RuboCop
|
|
253
255
|
@options = options
|
254
256
|
end
|
255
257
|
|
258
|
+
def validate_cop_options
|
259
|
+
%i[only except].each do |opt|
|
260
|
+
OptionsValidator.validate_cop_list(@options[opt])
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
# rubocop:disable Metrics/AbcSize
|
256
265
|
def validate_compatibility # rubocop:disable Metrics/MethodLength
|
257
|
-
if
|
258
|
-
raise OptionArgumentError, 'Lint/
|
259
|
-
'be used with --only.'
|
266
|
+
if only_includes_redundant_disable?
|
267
|
+
raise OptionArgumentError, 'Lint/RedundantCopDisableDirective can ' \
|
268
|
+
'not be used with --only.'
|
260
269
|
end
|
261
270
|
if except_syntax?
|
262
271
|
raise OptionArgumentError, 'Syntax checking can not be turned off.'
|
@@ -270,6 +279,7 @@ module RuboCop
|
|
270
279
|
'--display-only-fail-level-offenses'
|
271
280
|
end
|
272
281
|
validate_auto_gen_config
|
282
|
+
validate_auto_correct
|
273
283
|
validate_parallel
|
274
284
|
|
275
285
|
return if incompatible_options.size <= 1
|
@@ -277,6 +287,7 @@ module RuboCop
|
|
277
287
|
raise OptionArgumentError, 'Incompatible cli options: ' \
|
278
288
|
"#{incompatible_options.inspect}"
|
279
289
|
end
|
290
|
+
# rubocop:enable Metrics/AbcSize
|
280
291
|
|
281
292
|
def validate_auto_gen_config
|
282
293
|
return if @options.key?(:auto_gen_config)
|
@@ -292,6 +303,15 @@ module RuboCop
|
|
292
303
|
end
|
293
304
|
end
|
294
305
|
|
306
|
+
def validate_auto_correct
|
307
|
+
return if @options.key?(:auto_correct)
|
308
|
+
return unless @options.key?(:disable_uncorrectable)
|
309
|
+
|
310
|
+
raise OptionArgumentError,
|
311
|
+
format('--%<flag>s can only be used together with --auto-correct.',
|
312
|
+
flag: '--disable-uncorrectable')
|
313
|
+
end
|
314
|
+
|
295
315
|
def validate_parallel
|
296
316
|
return unless @options.key?(:parallel)
|
297
317
|
|
@@ -318,10 +338,10 @@ module RuboCop
|
|
318
338
|
end
|
319
339
|
end
|
320
340
|
|
321
|
-
def
|
341
|
+
def only_includes_redundant_disable?
|
322
342
|
@options.key?(:only) &&
|
323
|
-
(@options[:only] & %w[Lint/
|
324
|
-
|
343
|
+
(@options[:only] & %w[Lint/RedundantCopDisableDirective
|
344
|
+
RedundantCopDisableDirective]).any?
|
325
345
|
end
|
326
346
|
|
327
347
|
def display_only_fail_level_offenses_with_autocorrect?
|
@@ -353,8 +373,9 @@ module RuboCop
|
|
353
373
|
# This module contains help texts for command line options.
|
354
374
|
module OptionsHelp
|
355
375
|
MAX_EXCL = RuboCop::Options::DEFAULT_MAXIMUM_EXCLUSION_ITEMS.to_s
|
356
|
-
|
357
376
|
# rubocop:disable Metrics/LineLength
|
377
|
+
FORMATTER_OPTION_LIST = RuboCop::Formatter::FormatterSet::BUILTIN_FORMATTERS_FOR_KEYS.keys
|
378
|
+
|
358
379
|
TEXT = {
|
359
380
|
only: 'Run only the given cop(s).',
|
360
381
|
only_guide_cops: ['Run only cops for rules that link to a',
|
@@ -378,6 +399,9 @@ module RuboCop
|
|
378
399
|
exclude_limit: ['Used together with --auto-gen-config to',
|
379
400
|
'set the limit for how many Exclude',
|
380
401
|
"properties to generate. Default is #{MAX_EXCL}."],
|
402
|
+
disable_uncorrectable: ['Used with --auto-correct to annotate any',
|
403
|
+
'offenses that do not support autocorrect',
|
404
|
+
'with `rubocop:todo` comments.'],
|
381
405
|
force_exclusion: ['Force excluding files specified in the',
|
382
406
|
'configuration `Exclude` even if they are',
|
383
407
|
'explicitly passed as arguments.'],
|
@@ -390,20 +414,8 @@ module RuboCop
|
|
390
414
|
format: ['Choose an output formatter. This option',
|
391
415
|
'can be specified multiple times to enable',
|
392
416
|
'multiple formatters at the same time.',
|
393
|
-
'
|
394
|
-
|
395
|
-
' [c]lang',
|
396
|
-
' [d]isabled cops via inline comments',
|
397
|
-
' [fu]ubar',
|
398
|
-
' [e]macs',
|
399
|
-
' [j]son',
|
400
|
-
' [h]tml',
|
401
|
-
' [fi]les',
|
402
|
-
' [o]ffenses',
|
403
|
-
' [w]orst',
|
404
|
-
' [t]ap',
|
405
|
-
' [q]uiet',
|
406
|
-
' [a]utogenconf',
|
417
|
+
'[p]rogress is used by default',
|
418
|
+
*FORMATTER_OPTION_LIST.map { |item| " #{item}" },
|
407
419
|
' custom formatter class name'],
|
408
420
|
out: ['Write output to a file instead of STDOUT.',
|
409
421
|
'This option applies to the previously',
|
data/lib/rubocop/path_util.rb
CHANGED
data/lib/rubocop/result_cache.rb
CHANGED
@@ -132,7 +132,10 @@ module RuboCop
|
|
132
132
|
def expect_no_offenses(source, file = nil)
|
133
133
|
inspect_source(source, file)
|
134
134
|
|
135
|
-
|
135
|
+
expected_annotations = AnnotatedSource.parse(source)
|
136
|
+
actual_annotations =
|
137
|
+
expected_annotations.with_offense_annotations(cop.offenses)
|
138
|
+
expect(actual_annotations.to_s).to eq(source)
|
136
139
|
end
|
137
140
|
|
138
141
|
# Parsed representation of code annotated with the `^^^ Message` style
|
@@ -61,6 +61,18 @@ RSpec.shared_context 'config', :config do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
RSpec.shared_context 'mock console output' do
|
65
|
+
before do
|
66
|
+
$stdout = StringIO.new
|
67
|
+
$stderr = StringIO.new
|
68
|
+
end
|
69
|
+
|
70
|
+
after do
|
71
|
+
$stdout = STDOUT
|
72
|
+
$stderr = STDERR
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
64
76
|
RSpec.shared_context 'ruby 2.3', :ruby23 do
|
65
77
|
let(:ruby_version) { 2.3 }
|
66
78
|
end
|
data/lib/rubocop/runner.rb
CHANGED
@@ -104,25 +104,20 @@ module RuboCop
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def process_file(file)
|
107
|
-
puts "Scanning #{file}" if @options[:debug]
|
108
107
|
file_started(file)
|
109
|
-
|
110
108
|
offenses = file_offenses(file)
|
111
|
-
if @options[:display_only_fail_level_offenses]
|
112
|
-
offenses = offenses.select { |o| considered_failure?(o) }
|
113
|
-
end
|
114
|
-
formatter_set.file_finished(file, offenses)
|
115
|
-
offenses
|
116
109
|
rescue InfiniteCorrectionLoop => e
|
117
|
-
|
110
|
+
offenses = e.offenses.compact.sort.freeze
|
118
111
|
raise
|
112
|
+
ensure
|
113
|
+
file_finished(file, offenses || [])
|
119
114
|
end
|
120
115
|
|
121
116
|
def file_offenses(file)
|
122
117
|
file_offense_cache(file) do
|
123
118
|
source = get_processed_source(file)
|
124
119
|
source, offenses = do_inspection_loop(file, source)
|
125
|
-
|
120
|
+
add_redundant_disables(file, offenses.compact.sort, source)
|
126
121
|
end
|
127
122
|
end
|
128
123
|
|
@@ -146,48 +141,66 @@ module RuboCop
|
|
146
141
|
offenses
|
147
142
|
end
|
148
143
|
|
149
|
-
def
|
150
|
-
if
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
cop.check(offenses, source.disabled_line_ranges, source.comments)
|
157
|
-
offenses += cop.offenses
|
158
|
-
autocorrect_unneeded_disables(source, cop)
|
159
|
-
end
|
144
|
+
def add_redundant_disables(file, offenses, source)
|
145
|
+
if check_for_redundant_disables?(source)
|
146
|
+
redundant_cop_disable_directive(file) do |cop|
|
147
|
+
cop.check(offenses, source.disabled_line_ranges, source.comments)
|
148
|
+
offenses += cop.offenses
|
149
|
+
offenses += autocorrect_redundant_disables(file, source, cop,
|
150
|
+
offenses)
|
160
151
|
end
|
161
|
-
offenses
|
162
152
|
end
|
163
153
|
|
164
154
|
offenses.sort.reject(&:disabled?).freeze
|
165
155
|
end
|
166
156
|
|
167
|
-
def
|
157
|
+
def check_for_redundant_disables?(source)
|
168
158
|
!source.disabled_line_ranges.empty? && !filtered_run?
|
169
159
|
end
|
170
160
|
|
161
|
+
def redundant_cop_disable_directive(file)
|
162
|
+
config = @config_store.for(file)
|
163
|
+
if config.for_cop(Cop::Lint::RedundantCopDisableDirective)
|
164
|
+
.fetch('Enabled')
|
165
|
+
cop = Cop::Lint::RedundantCopDisableDirective.new(config, @options)
|
166
|
+
yield cop if cop.relevant_file?(file)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
171
170
|
def filtered_run?
|
172
171
|
@options[:except] || @options[:only]
|
173
172
|
end
|
174
173
|
|
175
|
-
def
|
174
|
+
def autocorrect_redundant_disables(file, source, cop, offenses)
|
176
175
|
cop.processed_source = source
|
177
176
|
|
178
|
-
Cop::Team.new(
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
177
|
+
team = Cop::Team.new(RuboCop::Cop::Registry.new, nil, @options)
|
178
|
+
team.autocorrect(source.buffer, [cop])
|
179
|
+
|
180
|
+
return [] unless team.updated_source_file?
|
181
|
+
|
182
|
+
# Do one extra inspection loop if any redundant disables were
|
183
|
+
# removed. This is done in order to find rubocop:enable directives that
|
184
|
+
# have now become useless.
|
185
|
+
_source, new_offenses = do_inspection_loop(file,
|
186
|
+
get_processed_source(file))
|
187
|
+
new_offenses - offenses
|
183
188
|
end
|
184
189
|
|
185
190
|
def file_started(file)
|
191
|
+
puts "Scanning #{file}" if @options[:debug]
|
186
192
|
formatter_set.file_started(file,
|
187
193
|
cli_options: @options,
|
188
194
|
config_store: @config_store)
|
189
195
|
end
|
190
196
|
|
197
|
+
def file_finished(file, offenses)
|
198
|
+
if @options[:display_only_fail_level_offenses]
|
199
|
+
offenses = offenses.select { |o| considered_failure?(o) }
|
200
|
+
end
|
201
|
+
formatter_set.file_finished(file, offenses)
|
202
|
+
end
|
203
|
+
|
191
204
|
def cached_run?
|
192
205
|
@cached_run ||=
|
193
206
|
(@options[:cache] == 'true' ||
|
@@ -285,9 +298,7 @@ module RuboCop
|
|
285
298
|
@mobilized_cop_classes[config.object_id] ||= begin
|
286
299
|
cop_classes = Cop::Cop.all
|
287
300
|
|
288
|
-
|
289
|
-
OptionsValidator.validate_cop_list(@options[opt])
|
290
|
-
end
|
301
|
+
OptionsValidator.new(@options).validate_cop_options
|
291
302
|
|
292
303
|
if @options[:only]
|
293
304
|
cop_classes.select! { |c| c.match?(@options[:only]) }
|
@@ -65,10 +65,7 @@ module RuboCop
|
|
65
65
|
to_inspect?(file, hidden_files, base_dir_config)
|
66
66
|
end
|
67
67
|
|
68
|
-
|
69
|
-
target_files.sort_by! { |path| -Integer(File.mtime(path)) } if fail_fast?
|
70
|
-
|
71
|
-
target_files
|
68
|
+
target_files.sort_by!(&order)
|
72
69
|
end
|
73
70
|
|
74
71
|
def to_inspect?(file, hidden_files, base_dir_config)
|
@@ -184,5 +181,16 @@ module RuboCop
|
|
184
181
|
config.file_to_exclude?(file)
|
185
182
|
end
|
186
183
|
end
|
184
|
+
|
185
|
+
private
|
186
|
+
|
187
|
+
def order
|
188
|
+
if fail_fast?
|
189
|
+
# Most recently modified file first.
|
190
|
+
->(path) { -Integer(File.mtime(path)) }
|
191
|
+
else
|
192
|
+
:itself
|
193
|
+
end
|
194
|
+
end
|
187
195
|
end
|
188
196
|
end
|
data/lib/rubocop/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.76.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-10-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jaro_winkler
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- lib/rubocop/ast/node/regexp_node.rb
|
186
186
|
- lib/rubocop/ast/node/resbody_node.rb
|
187
187
|
- lib/rubocop/ast/node/retry_node.rb
|
188
|
+
- lib/rubocop/ast/node/return_node.rb
|
188
189
|
- lib/rubocop/ast/node/self_class_node.rb
|
189
190
|
- lib/rubocop/ast/node/send_node.rb
|
190
191
|
- lib/rubocop/ast/node/str_node.rb
|
@@ -202,7 +203,9 @@ files:
|
|
202
203
|
- lib/rubocop/config.rb
|
203
204
|
- lib/rubocop/config_loader.rb
|
204
205
|
- lib/rubocop/config_loader_resolver.rb
|
206
|
+
- lib/rubocop/config_obsoletion.rb
|
205
207
|
- lib/rubocop/config_store.rb
|
208
|
+
- lib/rubocop/config_validator.rb
|
206
209
|
- lib/rubocop/cop/autocorrect_logic.rb
|
207
210
|
- lib/rubocop/cop/badge.rb
|
208
211
|
- lib/rubocop/cop/bundler/duplicated_gem.rb
|
@@ -376,6 +379,10 @@ files:
|
|
376
379
|
- lib/rubocop/cop/lint/percent_string_array.rb
|
377
380
|
- lib/rubocop/cop/lint/percent_symbol_array.rb
|
378
381
|
- lib/rubocop/cop/lint/rand_one.rb
|
382
|
+
- lib/rubocop/cop/lint/redundant_cop_disable_directive.rb
|
383
|
+
- lib/rubocop/cop/lint/redundant_cop_enable_directive.rb
|
384
|
+
- lib/rubocop/cop/lint/redundant_require_statement.rb
|
385
|
+
- lib/rubocop/cop/lint/redundant_splat_expansion.rb
|
379
386
|
- lib/rubocop/cop/lint/redundant_with_index.rb
|
380
387
|
- lib/rubocop/cop/lint/redundant_with_object.rb
|
381
388
|
- lib/rubocop/cop/lint/regexp_as_condition.rb
|
@@ -387,6 +394,7 @@ files:
|
|
387
394
|
- lib/rubocop/cop/lint/safe_navigation_consistency.rb
|
388
395
|
- lib/rubocop/cop/lint/safe_navigation_with_empty.rb
|
389
396
|
- lib/rubocop/cop/lint/script_permission.rb
|
397
|
+
- lib/rubocop/cop/lint/send_with_mixin_argument.rb
|
390
398
|
- lib/rubocop/cop/lint/shadowed_argument.rb
|
391
399
|
- lib/rubocop/cop/lint/shadowed_exception.rb
|
392
400
|
- lib/rubocop/cop/lint/shadowing_outer_local_variable.rb
|
@@ -395,10 +403,6 @@ files:
|
|
395
403
|
- lib/rubocop/cop/lint/to_json.rb
|
396
404
|
- lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb
|
397
405
|
- lib/rubocop/cop/lint/unified_integer.rb
|
398
|
-
- lib/rubocop/cop/lint/unneeded_cop_disable_directive.rb
|
399
|
-
- lib/rubocop/cop/lint/unneeded_cop_enable_directive.rb
|
400
|
-
- lib/rubocop/cop/lint/unneeded_require_statement.rb
|
401
|
-
- lib/rubocop/cop/lint/unneeded_splat_expansion.rb
|
402
406
|
- lib/rubocop/cop/lint/unreachable_code.rb
|
403
407
|
- lib/rubocop/cop/lint/unused_block_argument.rb
|
404
408
|
- lib/rubocop/cop/lint/unused_method_argument.rb
|
@@ -422,6 +426,7 @@ files:
|
|
422
426
|
- lib/rubocop/cop/metrics/parameter_lists.rb
|
423
427
|
- lib/rubocop/cop/metrics/perceived_complexity.rb
|
424
428
|
- lib/rubocop/cop/metrics/utils/abc_size_calculator.rb
|
429
|
+
- lib/rubocop/cop/migration/department_name.rb
|
425
430
|
- lib/rubocop/cop/mixin/alignment.rb
|
426
431
|
- lib/rubocop/cop/mixin/annotation_comment.rb
|
427
432
|
- lib/rubocop/cop/mixin/array_min_size.rb
|
@@ -446,10 +451,10 @@ files:
|
|
446
451
|
- lib/rubocop/cop/mixin/frozen_string_literal.rb
|
447
452
|
- lib/rubocop/cop/mixin/hash_alignment.rb
|
448
453
|
- lib/rubocop/cop/mixin/heredoc.rb
|
449
|
-
- lib/rubocop/cop/mixin/ignored_method_patterns.rb
|
450
454
|
- lib/rubocop/cop/mixin/ignored_methods.rb
|
451
455
|
- lib/rubocop/cop/mixin/ignored_pattern.rb
|
452
456
|
- lib/rubocop/cop/mixin/integer_node.rb
|
457
|
+
- lib/rubocop/cop/mixin/interpolation.rb
|
453
458
|
- lib/rubocop/cop/mixin/match_range.rb
|
454
459
|
- lib/rubocop/cop/mixin/method_complexity.rb
|
455
460
|
- lib/rubocop/cop/mixin/method_preference.rb
|
@@ -540,6 +545,7 @@ files:
|
|
540
545
|
- lib/rubocop/cop/style/dir.rb
|
541
546
|
- lib/rubocop/cop/style/documentation.rb
|
542
547
|
- lib/rubocop/cop/style/documentation_method.rb
|
548
|
+
- lib/rubocop/cop/style/double_cop_disable_directive.rb
|
543
549
|
- lib/rubocop/cop/style/double_negation.rb
|
544
550
|
- lib/rubocop/cop/style/each_for_simple_loop.rb
|
545
551
|
- lib/rubocop/cop/style/each_with_object.rb
|
@@ -592,6 +598,7 @@ files:
|
|
592
598
|
- lib/rubocop/cop/style/multiline_memoization.rb
|
593
599
|
- lib/rubocop/cop/style/multiline_method_signature.rb
|
594
600
|
- lib/rubocop/cop/style/multiline_ternary_operator.rb
|
601
|
+
- lib/rubocop/cop/style/multiline_when_then.rb
|
595
602
|
- lib/rubocop/cop/style/multiple_comparison.rb
|
596
603
|
- lib/rubocop/cop/style/mutable_constant.rb
|
597
604
|
- lib/rubocop/cop/style/negated_if.rb
|
@@ -621,12 +628,17 @@ files:
|
|
621
628
|
- lib/rubocop/cop/style/raise_args.rb
|
622
629
|
- lib/rubocop/cop/style/random_with_offset.rb
|
623
630
|
- lib/rubocop/cop/style/redundant_begin.rb
|
631
|
+
- lib/rubocop/cop/style/redundant_capital_w.rb
|
632
|
+
- lib/rubocop/cop/style/redundant_condition.rb
|
624
633
|
- lib/rubocop/cop/style/redundant_conditional.rb
|
625
634
|
- lib/rubocop/cop/style/redundant_exception.rb
|
626
635
|
- lib/rubocop/cop/style/redundant_freeze.rb
|
636
|
+
- lib/rubocop/cop/style/redundant_interpolation.rb
|
627
637
|
- lib/rubocop/cop/style/redundant_parentheses.rb
|
638
|
+
- lib/rubocop/cop/style/redundant_percent_q.rb
|
628
639
|
- lib/rubocop/cop/style/redundant_return.rb
|
629
640
|
- lib/rubocop/cop/style/redundant_self.rb
|
641
|
+
- lib/rubocop/cop/style/redundant_sort.rb
|
630
642
|
- lib/rubocop/cop/style/redundant_sort_by.rb
|
631
643
|
- lib/rubocop/cop/style/regexp_literal.rb
|
632
644
|
- lib/rubocop/cop/style/rescue_modifier.rb
|
@@ -663,11 +675,6 @@ files:
|
|
663
675
|
- lib/rubocop/cop/style/trailing_underscore_variable.rb
|
664
676
|
- lib/rubocop/cop/style/trivial_accessors.rb
|
665
677
|
- lib/rubocop/cop/style/unless_else.rb
|
666
|
-
- lib/rubocop/cop/style/unneeded_capital_w.rb
|
667
|
-
- lib/rubocop/cop/style/unneeded_condition.rb
|
668
|
-
- lib/rubocop/cop/style/unneeded_interpolation.rb
|
669
|
-
- lib/rubocop/cop/style/unneeded_percent_q.rb
|
670
|
-
- lib/rubocop/cop/style/unneeded_sort.rb
|
671
678
|
- lib/rubocop/cop/style/unpack_first.rb
|
672
679
|
- lib/rubocop/cop/style/variable_interpolation.rb
|
673
680
|
- lib/rubocop/cop/style/when_then.rb
|
@@ -678,6 +685,7 @@ files:
|
|
678
685
|
- lib/rubocop/cop/style/zero_length_predicate.rb
|
679
686
|
- lib/rubocop/cop/team.rb
|
680
687
|
- lib/rubocop/cop/util.rb
|
688
|
+
- lib/rubocop/cop/utils/format_string.rb
|
681
689
|
- lib/rubocop/cop/variable_force.rb
|
682
690
|
- lib/rubocop/cop/variable_force/assignment.rb
|
683
691
|
- lib/rubocop/cop/variable_force/branch.rb
|
@@ -702,6 +710,7 @@ files:
|
|
702
710
|
- lib/rubocop/formatter/html_formatter.rb
|
703
711
|
- lib/rubocop/formatter/json_formatter.rb
|
704
712
|
- lib/rubocop/formatter/offense_count_formatter.rb
|
713
|
+
- lib/rubocop/formatter/pacman_formatter.rb
|
705
714
|
- lib/rubocop/formatter/progress_formatter.rb
|
706
715
|
- lib/rubocop/formatter/quiet_formatter.rb
|
707
716
|
- lib/rubocop/formatter/simple_text_formatter.rb
|