rubocop 0.91.0 → 1.0.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 +1 -1
- data/config/default.yml +100 -54
- data/lib/rubocop.rb +10 -6
- data/lib/rubocop/cached_data.rb +2 -1
- data/lib/rubocop/cli/command/version.rb +1 -1
- data/lib/rubocop/comment_config.rb +9 -5
- data/lib/rubocop/config.rb +4 -0
- data/lib/rubocop/config_loader.rb +19 -2
- data/lib/rubocop/config_loader_resolver.rb +7 -5
- data/lib/rubocop/config_regeneration.rb +33 -0
- data/lib/rubocop/config_validator.rb +7 -6
- data/lib/rubocop/cop/badge.rb +9 -24
- data/lib/rubocop/cop/base.rb +16 -1
- data/lib/rubocop/cop/commissioner.rb +34 -20
- 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/gemspec/required_ruby_version.rb +10 -10
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/case_indentation.rb +4 -7
- data/lib/rubocop/cop/layout/class_structure.rb +8 -1
- data/lib/rubocop/cop/layout/dot_position.rb +6 -9
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +2 -2
- data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +4 -13
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +13 -8
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +2 -2
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -2
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +10 -1
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +4 -13
- data/lib/rubocop/cop/layout/space_around_operators.rb +4 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -7
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +0 -4
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +4 -18
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +2 -2
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +37 -13
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +2 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +18 -1
- data/lib/rubocop/cop/lint/boolean_symbol.rb +3 -0
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +23 -3
- data/lib/rubocop/cop/lint/duplicate_rescue_exception.rb +2 -4
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +37 -0
- data/lib/rubocop/cop/lint/identity_comparison.rb +5 -3
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +2 -5
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -0
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +22 -12
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +14 -4
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +78 -0
- data/lib/rubocop/cop/lint/rescue_type.rb +0 -1
- data/lib/rubocop/cop/lint/shadowed_exception.rb +6 -6
- data/lib/rubocop/cop/lint/to_json.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -5
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +3 -9
- data/lib/rubocop/cop/lint/useless_times.rb +11 -2
- data/lib/rubocop/cop/metrics/block_length.rb +3 -1
- data/lib/rubocop/cop/metrics/class_length.rb +14 -6
- data/lib/rubocop/cop/metrics/parameter_lists.rb +4 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +25 -16
- data/lib/rubocop/cop/mixin/configurable_numbering.rb +3 -3
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -1
- data/lib/rubocop/cop/mixin/rescue_node.rb +1 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -3
- data/lib/rubocop/cop/mixin/visibility_help.rb +4 -16
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/offense.rb +15 -2
- data/lib/rubocop/cop/security/open.rb +12 -10
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +6 -2
- data/lib/rubocop/cop/style/accessor_grouping.rb +3 -0
- data/lib/rubocop/cop/style/array_coercion.rb +4 -0
- data/lib/rubocop/cop/style/case_like_if.rb +20 -4
- data/lib/rubocop/cop/style/class_equality_comparison.rb +64 -0
- data/lib/rubocop/cop/style/combinable_loops.rb +13 -11
- data/lib/rubocop/cop/style/comment_annotation.rb +6 -0
- data/lib/rubocop/cop/style/commented_keyword.rb +7 -8
- data/lib/rubocop/cop/style/date_time.rb +12 -1
- data/lib/rubocop/cop/style/explicit_block_argument.rb +6 -2
- data/lib/rubocop/cop/style/for.rb +0 -4
- data/lib/rubocop/cop/style/format_string_token.rb +48 -3
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +15 -6
- data/lib/rubocop/cop/style/if_unless_modifier.rb +0 -4
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -6
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +10 -13
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +6 -11
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +7 -11
- data/lib/rubocop/cop/style/method_def_parentheses.rb +0 -4
- data/lib/rubocop/cop/style/mixin_usage.rb +7 -27
- data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -2
- data/lib/rubocop/cop/style/multiline_when_then.rb +1 -0
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +2 -0
- data/lib/rubocop/cop/style/one_line_conditional.rb +3 -1
- data/lib/rubocop/cop/style/optional_boolean_parameter.rb +12 -1
- data/lib/rubocop/cop/style/raise_args.rb +0 -3
- data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
- data/lib/rubocop/cop/style/redundant_assignment.rb +1 -9
- data/lib/rubocop/cop/style/redundant_begin.rb +36 -8
- data/lib/rubocop/cop/style/redundant_condition.rb +5 -1
- data/lib/rubocop/cop/style/redundant_conditional.rb +4 -5
- data/lib/rubocop/cop/style/redundant_interpolation.rb +6 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +6 -3
- data/lib/rubocop/cop/style/redundant_percent_q.rb +9 -11
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +39 -24
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -15
- data/lib/rubocop/cop/style/redundant_return.rb +17 -17
- data/lib/rubocop/cop/style/redundant_self.rb +10 -9
- data/lib/rubocop/cop/style/redundant_sort.rb +13 -24
- data/lib/rubocop/cop/style/redundant_sort_by.rb +5 -9
- data/lib/rubocop/cop/style/rescue_standard_error.rb +20 -16
- data/lib/rubocop/cop/style/safe_navigation.rb +16 -4
- data/lib/rubocop/cop/style/string_concatenation.rb +14 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -3
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +4 -3
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +3 -1
- data/lib/rubocop/cop/util.rb +0 -1
- data/lib/rubocop/cop/variable_force/branch.rb +0 -4
- data/lib/rubocop/directive_comment.rb +32 -0
- data/lib/rubocop/ext/regexp_node.rb +20 -4
- data/lib/rubocop/formatter/disabled_config_formatter.rb +12 -5
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -1
- data/lib/rubocop/options.rb +22 -17
- data/lib/rubocop/result_cache.rb +8 -2
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +5 -5
- data/lib/rubocop/runner.rb +9 -5
- data/lib/rubocop/target_finder.rb +27 -26
- data/lib/rubocop/target_ruby.rb +1 -1
- data/lib/rubocop/version.rb +61 -6
- metadata +14 -17
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +0 -43
- data/lib/rubocop/cop/tokens_util.rb +0 -84
@@ -142,10 +142,22 @@ module RuboCop
|
|
142
142
|
end
|
143
143
|
|
144
144
|
def comments(node)
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
145
|
+
relevant_comment_ranges(node).each.with_object([]) do |range, comments|
|
146
|
+
comments.concat(processed_source.each_comment_in_lines(range).to_a)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def relevant_comment_ranges(node)
|
151
|
+
# Get source lines ranges inside the if node that aren't inside an inner node
|
152
|
+
# Comments inside an inner node should remain attached to that node, and not
|
153
|
+
# moved.
|
154
|
+
begin_pos = node.loc.first_line
|
155
|
+
end_pos = node.loc.last_line
|
156
|
+
|
157
|
+
node.child_nodes.each.with_object([]) do |child, ranges|
|
158
|
+
ranges << (begin_pos...child.loc.first_line)
|
159
|
+
begin_pos = child.loc.last_line
|
160
|
+
end << (begin_pos...end_pos)
|
149
161
|
end
|
150
162
|
|
151
163
|
def allowed_if_condition?(node)
|
@@ -33,6 +33,10 @@ module RuboCop
|
|
33
33
|
}
|
34
34
|
PATTERN
|
35
35
|
|
36
|
+
def on_new_investigation
|
37
|
+
@corrected_nodes = nil
|
38
|
+
end
|
39
|
+
|
36
40
|
def on_send(node)
|
37
41
|
return unless string_concatenation?(node)
|
38
42
|
|
@@ -42,8 +46,12 @@ module RuboCop
|
|
42
46
|
collect_parts(topmost_plus_node, parts)
|
43
47
|
|
44
48
|
add_offense(topmost_plus_node) do |corrector|
|
45
|
-
|
49
|
+
correctable_parts = parts.none? { |part| uncorrectable?(part) }
|
50
|
+
if correctable_parts && !corrected_ancestor?(topmost_plus_node)
|
46
51
|
corrector.replace(topmost_plus_node, replacement(parts))
|
52
|
+
|
53
|
+
@corrected_nodes ||= Set.new.compare_by_identity
|
54
|
+
@corrected_nodes.add(topmost_plus_node)
|
47
55
|
end
|
48
56
|
end
|
49
57
|
end
|
@@ -80,6 +88,10 @@ module RuboCop
|
|
80
88
|
part.each_descendant(:block).any?
|
81
89
|
end
|
82
90
|
|
91
|
+
def corrected_ancestor?(node)
|
92
|
+
node.each_ancestor(:send).any? { |ancestor| @corrected_nodes&.include?(ancestor) }
|
93
|
+
end
|
94
|
+
|
83
95
|
def replacement(parts)
|
84
96
|
interpolated_parts =
|
85
97
|
parts.map do |part|
|
@@ -87,7 +99,7 @@ module RuboCop
|
|
87
99
|
if single_quoted?(part)
|
88
100
|
part.value.gsub('\\') { '\\\\' }
|
89
101
|
else
|
90
|
-
|
102
|
+
part.value.inspect[1..-2]
|
91
103
|
end
|
92
104
|
else
|
93
105
|
"\#{#{part.source}}"
|
@@ -192,7 +192,7 @@ module RuboCop
|
|
192
192
|
end
|
193
193
|
|
194
194
|
def_node_matcher :method_name, <<~PATTERN
|
195
|
-
{($:defined?
|
195
|
+
{($:defined? _ ...)
|
196
196
|
(send {_ nil?} $_ _ ...)}
|
197
197
|
PATTERN
|
198
198
|
|
@@ -211,8 +211,7 @@ module RuboCop
|
|
211
211
|
end
|
212
212
|
|
213
213
|
def whitespace_after?(node)
|
214
|
-
|
215
|
-
last_token = processed_source.tokens[index]
|
214
|
+
last_token = processed_source.last_token_of(node)
|
216
215
|
last_token.space_after?
|
217
216
|
end
|
218
217
|
end
|
@@ -76,12 +76,13 @@ module RuboCop
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def argument_tokens(node)
|
79
|
-
|
79
|
+
tokens = processed_source.tokens_within(node)
|
80
|
+
pipes = tokens.select { |token| token.type == :tPIPE }
|
80
81
|
begin_pos, end_pos = pipes.map do |pipe|
|
81
|
-
tokens
|
82
|
+
tokens.index(pipe)
|
82
83
|
end
|
83
84
|
|
84
|
-
tokens
|
85
|
+
tokens[begin_pos + 1..end_pos - 1]
|
85
86
|
end
|
86
87
|
end
|
87
88
|
end
|
@@ -36,6 +36,8 @@ module RuboCop
|
|
36
36
|
MSG = 'Do not use trailing `_`s in parallel assignment. ' \
|
37
37
|
'Prefer `%<code>s`.'
|
38
38
|
UNDERSCORE = '_'
|
39
|
+
DISALLOW = %i[lvasgn splat].freeze
|
40
|
+
private_constant :DISALLOW
|
39
41
|
|
40
42
|
def on_masgn(node)
|
41
43
|
ranges = unneeded_ranges(node)
|
@@ -64,7 +66,7 @@ module RuboCop
|
|
64
66
|
|
65
67
|
def find_first_possible_offense(variables)
|
66
68
|
variables.reduce(nil) do |offense, variable|
|
67
|
-
break offense unless
|
69
|
+
break offense unless DISALLOW.include?(variable.type)
|
68
70
|
|
69
71
|
var, = *variable
|
70
72
|
var, = *var
|
data/lib/rubocop/cop/util.rb
CHANGED
@@ -5,7 +5,6 @@ module RuboCop
|
|
5
5
|
# This module contains a collection of useful utility methods.
|
6
6
|
module Util
|
7
7
|
include PathUtil
|
8
|
-
include TokensUtil
|
9
8
|
|
10
9
|
# Match literal regex characters, not including anchors, character
|
11
10
|
# classes, alternatives, groups, repetitions, references, etc
|
@@ -20,8 +20,6 @@ module RuboCop
|
|
20
20
|
nil
|
21
21
|
end
|
22
22
|
|
23
|
-
# rubocop:disable Metrics/BlockLength
|
24
|
-
|
25
23
|
# Abstract base class for branch classes.
|
26
24
|
# A branch represents a conditional branch in a scope.
|
27
25
|
#
|
@@ -42,8 +40,6 @@ module RuboCop
|
|
42
40
|
# do_something # no branch
|
43
41
|
# end
|
44
42
|
Base = Struct.new(:child_node, :scope) do
|
45
|
-
# rubocop:enable Metrics/BlockLength
|
46
|
-
|
47
43
|
def self.classes
|
48
44
|
@classes ||= []
|
49
45
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
# This class wraps the `Parser::Source::Comment` object that represents a
|
5
|
+
# special `rubocop:disable` and `rubocop:enable` comment and exposes what
|
6
|
+
# cops it contains.
|
7
|
+
class DirectiveComment
|
8
|
+
attr_reader :comment
|
9
|
+
|
10
|
+
def initialize(comment)
|
11
|
+
@comment = comment
|
12
|
+
end
|
13
|
+
|
14
|
+
# Return all the cops specified in the directive
|
15
|
+
def cops
|
16
|
+
match = comment.text.match(CommentConfig::COMMENT_DIRECTIVE_REGEXP)
|
17
|
+
return unless match
|
18
|
+
|
19
|
+
cops_string = match.captures[1]
|
20
|
+
cops_string.split(/,\s*/).uniq.sort
|
21
|
+
end
|
22
|
+
|
23
|
+
# Checks if this directive contains all the given cop names
|
24
|
+
def match?(cop_names)
|
25
|
+
cops == cop_names.uniq.sort
|
26
|
+
end
|
27
|
+
|
28
|
+
def range
|
29
|
+
comment.location.expression
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -17,11 +17,9 @@ module RuboCop
|
|
17
17
|
|
18
18
|
# @return [Regexp::Expression::Root, nil]
|
19
19
|
def parsed_tree
|
20
|
-
|
21
|
-
|
22
|
-
str = content
|
20
|
+
str = with_interpolations_blanked
|
23
21
|
Ext::RegexpNode.parsed_cache[str] ||= begin
|
24
|
-
Regexp::Parser.parse(str)
|
22
|
+
Regexp::Parser.parse(str, options: options)
|
25
23
|
rescue StandardError
|
26
24
|
nil
|
27
25
|
end
|
@@ -40,6 +38,24 @@ module RuboCop
|
|
40
38
|
self
|
41
39
|
end
|
42
40
|
|
41
|
+
private
|
42
|
+
|
43
|
+
def with_interpolations_blanked
|
44
|
+
# Ignore the trailing regopt node
|
45
|
+
children[0...-1].map do |child|
|
46
|
+
source = child.source
|
47
|
+
|
48
|
+
# We don't want to consider the contents of interpolations as part of the pattern source,
|
49
|
+
# but need to preserve their width, to allow offsets to correctly line up with the
|
50
|
+
# original source: spaces have no effect, and preserve width.
|
51
|
+
if child.begin_type?
|
52
|
+
' ' * source.length
|
53
|
+
else
|
54
|
+
source
|
55
|
+
end
|
56
|
+
end.join
|
57
|
+
end
|
58
|
+
|
43
59
|
AST::RegexpNode.include self
|
44
60
|
end
|
45
61
|
end
|
@@ -32,7 +32,6 @@ module RuboCop
|
|
32
32
|
@exclude_limit_option = @options[:exclude_limit]
|
33
33
|
@exclude_limit = Integer(@exclude_limit_option ||
|
34
34
|
RuboCop::Options::DEFAULT_MAXIMUM_EXCLUSION_ITEMS)
|
35
|
-
@show_offense_counts = !@options[:no_offense_counts]
|
36
35
|
end
|
37
36
|
|
38
37
|
def file_finished(file, offenses)
|
@@ -56,6 +55,14 @@ module RuboCop
|
|
56
55
|
|
57
56
|
private
|
58
57
|
|
58
|
+
def show_timestamp?
|
59
|
+
@options.fetch(:auto_gen_timestamp, true)
|
60
|
+
end
|
61
|
+
|
62
|
+
def show_offense_counts?
|
63
|
+
@options.fetch(:offense_counts, true)
|
64
|
+
end
|
65
|
+
|
59
66
|
def command
|
60
67
|
command = 'rubocop --auto-gen-config'
|
61
68
|
|
@@ -66,15 +73,15 @@ module RuboCop
|
|
66
73
|
format(' --exclude-limit %<limit>d',
|
67
74
|
limit: Integer(@exclude_limit_option))
|
68
75
|
end
|
69
|
-
command += ' --no-offense-counts'
|
76
|
+
command += ' --no-offense-counts' unless show_offense_counts?
|
70
77
|
|
71
|
-
command += ' --no-auto-gen-timestamp'
|
78
|
+
command += ' --no-auto-gen-timestamp' unless show_timestamp?
|
72
79
|
|
73
80
|
command
|
74
81
|
end
|
75
82
|
|
76
83
|
def timestamp
|
77
|
-
|
84
|
+
show_timestamp? ? "on #{Time.now.utc} " : ''
|
78
85
|
end
|
79
86
|
|
80
87
|
def output_offenses
|
@@ -112,7 +119,7 @@ module RuboCop
|
|
112
119
|
end
|
113
120
|
|
114
121
|
def output_cop_comments(output_buffer, cfg, cop_name, offense_count)
|
115
|
-
output_buffer.puts "# Offense count: #{offense_count}" if
|
122
|
+
output_buffer.puts "# Offense count: #{offense_count}" if show_offense_counts?
|
116
123
|
|
117
124
|
cop_class = Cop::Registry.global.find_by_cop_name(cop_name)
|
118
125
|
output_buffer.puts '# Cop supports --auto-correct.' if cop_class&.support_autocorrect?
|
data/lib/rubocop/options.rb
CHANGED
@@ -114,20 +114,19 @@ module RuboCop
|
|
114
114
|
def add_auto_gen_options(opts)
|
115
115
|
option(opts, '--auto-gen-config')
|
116
116
|
|
117
|
+
option(opts, '--regenerate-todo') do
|
118
|
+
@options.replace(ConfigRegeneration.new.options.merge(@options))
|
119
|
+
end
|
120
|
+
|
117
121
|
option(opts, '--exclude-limit COUNT') do
|
118
122
|
@validator.validate_exclude_limit_option
|
119
123
|
end
|
120
124
|
|
121
125
|
option(opts, '--disable-uncorrectable')
|
122
126
|
|
123
|
-
option(opts, '--no-offense-counts')
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
option(opts, '--auto-gen-only-exclude')
|
128
|
-
option(opts, '--no-auto-gen-timestamp') do
|
129
|
-
@options[:no_auto_gen_timestamp] = true
|
130
|
-
end
|
127
|
+
option(opts, '--[no-]offense-counts')
|
128
|
+
option(opts, '--[no-]auto-gen-only-exclude')
|
129
|
+
option(opts, '--[no-]auto-gen-timestamp')
|
131
130
|
|
132
131
|
option(opts, '--init')
|
133
132
|
end
|
@@ -243,6 +242,9 @@ module RuboCop
|
|
243
242
|
# @api private
|
244
243
|
class OptionsValidator
|
245
244
|
class << self
|
245
|
+
SYNTAX_DEPARTMENTS = %w[Syntax Lint/Syntax].freeze
|
246
|
+
private_constant :SYNTAX_DEPARTMENTS
|
247
|
+
|
246
248
|
# Cop name validation must be done later than option parsing, so it's not
|
247
249
|
# called from within Options.
|
248
250
|
def validate_cop_list(names)
|
@@ -254,7 +256,7 @@ module RuboCop
|
|
254
256
|
names.each do |name|
|
255
257
|
next if cop_names.include?(name)
|
256
258
|
next if departments.include?(name)
|
257
|
-
next if
|
259
|
+
next if SYNTAX_DEPARTMENTS.include?(name)
|
258
260
|
|
259
261
|
raise IncorrectCopNameError, format_message_from(name, cop_names)
|
260
262
|
end
|
@@ -318,7 +320,7 @@ module RuboCop
|
|
318
320
|
|
319
321
|
message = '--%<flag>s can only be used together with --auto-gen-config.'
|
320
322
|
|
321
|
-
%i[exclude_limit
|
323
|
+
%i[exclude_limit offense_counts auto_gen_timestamp
|
322
324
|
auto_gen_only_exclude].each do |option|
|
323
325
|
if @options.key?(option)
|
324
326
|
raise OptionArgumentError,
|
@@ -423,17 +425,20 @@ module RuboCop
|
|
423
425
|
config: 'Specify configuration file.',
|
424
426
|
auto_gen_config: ['Generate a configuration file acting as a',
|
425
427
|
'TODO list.'],
|
426
|
-
|
427
|
-
'
|
428
|
-
|
429
|
-
|
430
|
-
'
|
431
|
-
'
|
428
|
+
regenerate_todo: ['Regenerate the TODO configuration file using',
|
429
|
+
'the last configuration. If there is no existing',
|
430
|
+
'TODO file, acts like --auto-gen-config.'],
|
431
|
+
offense_counts: ['Include offense counts in configuration',
|
432
|
+
'file generated by --auto-gen-config.',
|
433
|
+
'Default is true.'],
|
434
|
+
auto_gen_timestamp:
|
435
|
+
['Include the date and time when the --auto-gen-config',
|
436
|
+
'was run in the file it generates. Default is true.'],
|
432
437
|
auto_gen_only_exclude:
|
433
438
|
['Generate only Exclude parameters and not Max',
|
434
439
|
'when running --auto-gen-config, except if the',
|
435
440
|
'number of files with offenses is bigger than',
|
436
|
-
'exclude-limit.'],
|
441
|
+
'exclude-limit. Default is false.'],
|
437
442
|
exclude_limit: ['Used together with --auto-gen-config to',
|
438
443
|
'set the limit for how many Exclude',
|
439
444
|
"properties to generate. Default is #{MAX_EXCL}."],
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -95,6 +95,11 @@ module RuboCop
|
|
95
95
|
context_checksum(team, options),
|
96
96
|
file_checksum(file, config_store))
|
97
97
|
@cached_data = CachedData.new(file)
|
98
|
+
@debug = options[:debug]
|
99
|
+
end
|
100
|
+
|
101
|
+
def debug?
|
102
|
+
@debug
|
98
103
|
end
|
99
104
|
|
100
105
|
def valid?
|
@@ -102,6 +107,7 @@ module RuboCop
|
|
102
107
|
end
|
103
108
|
|
104
109
|
def load
|
110
|
+
puts "Loading cache from #{@path}" if debug?
|
105
111
|
@cached_data.from_json(IO.read(@path, encoding: Encoding::UTF_8))
|
106
112
|
end
|
107
113
|
|
@@ -209,8 +215,8 @@ module RuboCop
|
|
209
215
|
# The external dependency checksums are cached per RuboCop team so that
|
210
216
|
# the checksums don't need to be recomputed for each file.
|
211
217
|
def team_checksum(team)
|
212
|
-
@checksum_by_team ||= {}
|
213
|
-
@checksum_by_team[team
|
218
|
+
@checksum_by_team ||= {}.compare_by_identity
|
219
|
+
@checksum_by_team[team] ||= team.external_dependency_checksum
|
214
220
|
end
|
215
221
|
|
216
222
|
# We combine team and options into a single "context" checksum to avoid
|
@@ -133,14 +133,14 @@ module RuboCop
|
|
133
133
|
"#{@processed_source.diagnostics.map(&:render).join("\n")}"
|
134
134
|
end
|
135
135
|
|
136
|
-
offenses = _investigate(cop, @processed_source)
|
136
|
+
@offenses = _investigate(cop, @processed_source)
|
137
137
|
actual_annotations =
|
138
|
-
expected_annotations.with_offense_annotations(offenses)
|
138
|
+
expected_annotations.with_offense_annotations(@offenses)
|
139
139
|
|
140
140
|
expect(actual_annotations).to eq(expected_annotations), ''
|
141
|
-
expect(offenses.map(&:severity).uniq).to eq([severity]) if severity
|
141
|
+
expect(@offenses.map(&:severity).uniq).to eq([severity]) if severity
|
142
142
|
|
143
|
-
offenses
|
143
|
+
@offenses
|
144
144
|
end
|
145
145
|
|
146
146
|
def expect_correction(correction, loop: true)
|
@@ -157,7 +157,7 @@ module RuboCop
|
|
157
157
|
break corrected_source if corrected_source == @processed_source.buffer.source
|
158
158
|
|
159
159
|
if iteration > RuboCop::Runner::MAX_ITERATIONS
|
160
|
-
raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [])
|
160
|
+
raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [@offenses])
|
161
161
|
end
|
162
162
|
|
163
163
|
# Prepare for next loop
|