rubocop 0.72.0 → 0.73.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 +1 -1
- data/config/default.yml +13 -0
- data/lib/rubocop.rb +2 -0
- data/lib/rubocop/ast/node.rb +8 -8
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +16 -5
- data/lib/rubocop/ast/traversal.rb +3 -3
- 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 +3 -9
- data/lib/rubocop/cop/cop.rb +36 -6
- data/lib/rubocop/cop/corrector.rb +2 -3
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +2 -2
- 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 +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/block_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +1 -1
- data/lib/rubocop/cop/layout/indent_first_argument.rb +1 -1
- data/lib/rubocop/cop/layout/indent_heredoc.rb +3 -2
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +28 -0
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +18 -4
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +14 -2
- data/lib/rubocop/cop/layout/tab.rb +10 -22
- data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +3 -3
- 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/erb_new_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
- 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/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 +2 -2
- data/lib/rubocop/cop/lint/rand_one.rb +1 -1
- 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 +5 -5
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -1
- data/lib/rubocop/cop/lint/unified_integer.rb +1 -1
- data/lib/rubocop/cop/lint/unneeded_require_statement.rb +1 -1
- data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- 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/metrics/class_length.rb +1 -1
- data/lib/rubocop/cop/metrics/module_length.rb +1 -1
- data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- 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/method_complexity.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +3 -3
- 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/predicate_name.rb +1 -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/alias.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
- data/lib/rubocop/cop/style/constant_visibility.rb +1 -1
- 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 +1 -1
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +49 -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/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 +3 -3
- data/lib/rubocop/cop/style/float_division.rb +4 -4
- data/lib/rubocop/cop/style/format_string.rb +7 -7
- data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
- data/lib/rubocop/cop/style/inverse_methods.rb +2 -2
- data/lib/rubocop/cop/style/min_max.rb +1 -1
- data/lib/rubocop/cop/style/mixin_usage.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/numeric_predicate.rb +3 -3
- data/lib/rubocop/cop/style/option_hash.rb +1 -1
- data/lib/rubocop/cop/style/or_assignment.rb +2 -2
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +6 -6
- 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/redundant_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -1
- 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 +1 -1
- data/lib/rubocop/cop/style/sample.rb +1 -1
- 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 +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unneeded_sort.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +1 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -5
- data/lib/rubocop/cop/team.rb +15 -14
- data/lib/rubocop/error.rb +23 -0
- data/lib/rubocop/node_pattern.rb +2 -2
- data/lib/rubocop/options.rb +17 -0
- data/lib/rubocop/rspec/shared_contexts.rb +12 -0
- data/lib/rubocop/target_finder.rb +6 -4
- data/lib/rubocop/version.rb +1 -1
- metadata +4 -2
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
MSG = 'Prefer ranges when generating random numbers instead of ' \
|
28
28
|
'integers with offsets.'
|
29
29
|
|
30
|
-
def_node_matcher :integer_op_rand?,
|
30
|
+
def_node_matcher :integer_op_rand?, <<~PATTERN
|
31
31
|
(send
|
32
32
|
int {:+ :-}
|
33
33
|
(send
|
@@ -36,7 +36,7 @@ module RuboCop
|
|
36
36
|
{int irange erange}))
|
37
37
|
PATTERN
|
38
38
|
|
39
|
-
def_node_matcher :rand_op_integer?,
|
39
|
+
def_node_matcher :rand_op_integer?, <<~PATTERN
|
40
40
|
(send
|
41
41
|
(send
|
42
42
|
{nil? (const nil? :Random) (const nil? :Kernel)}
|
@@ -46,7 +46,7 @@ module RuboCop
|
|
46
46
|
int)
|
47
47
|
PATTERN
|
48
48
|
|
49
|
-
def_node_matcher :rand_modified?,
|
49
|
+
def_node_matcher :rand_modified?, <<~PATTERN
|
50
50
|
(send
|
51
51
|
(send
|
52
52
|
{nil? (const nil? :Random) (const nil? :Kernel)}
|
@@ -80,7 +80,7 @@ module RuboCop
|
|
80
80
|
|
81
81
|
private
|
82
82
|
|
83
|
-
def_node_matcher :random_call,
|
83
|
+
def_node_matcher :random_call, <<~PATTERN
|
84
84
|
{(send (send $_ _ $_) ...)
|
85
85
|
(send _ _ (send $_ _ $_))}
|
86
86
|
PATTERN
|
@@ -128,7 +128,7 @@ module RuboCop
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
def_node_matcher :namespace,
|
131
|
+
def_node_matcher :namespace, <<~PATTERN
|
132
132
|
{$nil? (const nil? $_)}
|
133
133
|
PATTERN
|
134
134
|
|
@@ -149,7 +149,7 @@ module RuboCop
|
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
-
def_node_matcher :to_int,
|
152
|
+
def_node_matcher :to_int, <<~PATTERN
|
153
153
|
(int $_)
|
154
154
|
PATTERN
|
155
155
|
end
|
@@ -53,11 +53,11 @@ module RuboCop
|
|
53
53
|
format(MSG, msg: msg)
|
54
54
|
end
|
55
55
|
|
56
|
-
def_node_matcher :redundant_condition?,
|
56
|
+
def_node_matcher :redundant_condition?, <<~RUBY
|
57
57
|
(if (send _ {:#{COMPARISON_OPERATORS.join(' :')}} _) true false)
|
58
58
|
RUBY
|
59
59
|
|
60
|
-
def_node_matcher :redundant_condition_inverted?,
|
60
|
+
def_node_matcher :redundant_condition_inverted?, <<~RUBY
|
61
61
|
(if (send _ {:#{COMPARISON_OPERATORS.join(' :')}} _) false true)
|
62
62
|
RUBY
|
63
63
|
|
@@ -47,11 +47,11 @@ module RuboCop
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def_node_matcher :exploded?,
|
50
|
+
def_node_matcher :exploded?, <<~PATTERN
|
51
51
|
(send nil? ${:raise :fail} (const nil? :RuntimeError) $_)
|
52
52
|
PATTERN
|
53
53
|
|
54
|
-
def_node_matcher :compact?,
|
54
|
+
def_node_matcher :compact?, <<~PATTERN
|
55
55
|
(send nil? {:raise :fail} $(send (const nil? :RuntimeError) :new $_))
|
56
56
|
PATTERN
|
57
57
|
end
|
@@ -51,7 +51,7 @@ module RuboCop
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def_node_matcher :operation_produces_immutable_object?,
|
54
|
+
def_node_matcher :operation_produces_immutable_object?, <<~PATTERN
|
55
55
|
{
|
56
56
|
(begin (send {float int} {:+ :- :* :** :/ :% :<<} _))
|
57
57
|
(begin (send !(str _) {:+ :- :* :** :/ :%} {float int}))
|
@@ -203,11 +203,11 @@ module RuboCop
|
|
203
203
|
first_send_argument?(node) || first_super_argument?(node)
|
204
204
|
end
|
205
205
|
|
206
|
-
def_node_matcher :first_send_argument?,
|
206
|
+
def_node_matcher :first_send_argument?, <<~PATTERN
|
207
207
|
^(send _ _ equal?(%0) ...)
|
208
208
|
PATTERN
|
209
209
|
|
210
|
-
def_node_matcher :first_super_argument?,
|
210
|
+
def_node_matcher :first_super_argument?, <<~PATTERN
|
211
211
|
^(super equal?(%0) ...)
|
212
212
|
PATTERN
|
213
213
|
|
@@ -80,11 +80,11 @@ module RuboCop
|
|
80
80
|
MSG_EXPLICIT = 'Avoid rescuing without specifying ' \
|
81
81
|
'an error class.'
|
82
82
|
|
83
|
-
def_node_matcher :rescue_without_error_class?,
|
83
|
+
def_node_matcher :rescue_without_error_class?, <<~PATTERN
|
84
84
|
(resbody nil? _ _)
|
85
85
|
PATTERN
|
86
86
|
|
87
|
-
def_node_matcher :rescue_standard_error?,
|
87
|
+
def_node_matcher :rescue_standard_error?, <<~PATTERN
|
88
88
|
(resbody $(array (const nil? :StandardError)) _ _)
|
89
89
|
PATTERN
|
90
90
|
|
@@ -69,7 +69,7 @@ module RuboCop
|
|
69
69
|
|
70
70
|
# if format: (if checked_variable body nil)
|
71
71
|
# unless format: (if checked_variable nil body)
|
72
|
-
def_node_matcher :modifier_if_safe_navigation_candidate,
|
72
|
+
def_node_matcher :modifier_if_safe_navigation_candidate, <<~PATTERN
|
73
73
|
{
|
74
74
|
(if {
|
75
75
|
(send $_ {:nil? :!})
|
@@ -30,7 +30,7 @@ module RuboCop
|
|
30
30
|
class Sample < Cop
|
31
31
|
MSG = 'Use `%<correct>s` instead of `%<incorrect>s`.'
|
32
32
|
|
33
|
-
def_node_matcher :sample_candidate?,
|
33
|
+
def_node_matcher :sample_candidate?, <<~PATTERN
|
34
34
|
(send $(send _ :shuffle $...) ${:first :last :[] :at :slice} $...)
|
35
35
|
PATTERN
|
36
36
|
|
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
MSG =
|
21
21
|
'Use `warn` instead of `%<bad>s` to allow such output to be disabled.'
|
22
22
|
|
23
|
-
def_node_matcher :stderr_puts?,
|
23
|
+
def_node_matcher :stderr_puts?, <<~PATTERN
|
24
24
|
(send
|
25
25
|
{(gvar #stderr_gvar?) (const nil? :STDERR)}
|
26
26
|
:puts $_
|
@@ -15,11 +15,11 @@ module RuboCop
|
|
15
15
|
class StringHashKeys < Cop
|
16
16
|
MSG = 'Prefer symbols instead of strings as hash keys.'
|
17
17
|
|
18
|
-
def_node_matcher :string_hash_key?,
|
18
|
+
def_node_matcher :string_hash_key?, <<~PATTERN
|
19
19
|
(pair (str _) _)
|
20
20
|
PATTERN
|
21
21
|
|
22
|
-
def_node_matcher :receive_environments_method?,
|
22
|
+
def_node_matcher :receive_environments_method?, <<~PATTERN
|
23
23
|
{
|
24
24
|
^^(send (const {nil? cbase} :IO) :popen ...)
|
25
25
|
^^(send (const {nil? cbase} :Open3)
|
@@ -29,9 +29,9 @@ module RuboCop
|
|
29
29
|
add_offense(node, location: node.parent_class.source_range)
|
30
30
|
end
|
31
31
|
|
32
|
-
def_node_matcher :struct_constructor?,
|
33
|
-
|
34
|
-
|
32
|
+
def_node_matcher :struct_constructor?, <<~PATTERN
|
33
|
+
{(send (const nil? :Struct) :new ...)
|
34
|
+
(block (send (const nil? :Struct) :new ...) ...)}
|
35
35
|
PATTERN
|
36
36
|
end
|
37
37
|
end
|
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
SUPER_TYPES = %i[super zsuper].freeze
|
21
21
|
|
22
22
|
def_node_matcher :proc_node?, '(send (const nil? :Proc) :new)'
|
23
|
-
def_node_matcher :symbol_proc?,
|
23
|
+
def_node_matcher :symbol_proc?, <<~PATTERN
|
24
24
|
(block
|
25
25
|
${(send ...) (super ...) zsuper}
|
26
26
|
$(args (arg _var))
|
@@ -118,7 +118,7 @@ module RuboCop
|
|
118
118
|
!allowed_method?(node) && !allowed_writer?(node.method_name)
|
119
119
|
end
|
120
120
|
|
121
|
-
def_node_matcher :looks_like_trivial_writer?,
|
121
|
+
def_node_matcher :looks_like_trivial_writer?, <<~PATTERN
|
122
122
|
{(def _ (args (arg ...)) (ivasgn _ (lvar _)))
|
123
123
|
(defs _ _ (args (arg ...)) (ivasgn _ (lvar _)))}
|
124
124
|
PATTERN
|
@@ -55,7 +55,7 @@ module RuboCop
|
|
55
55
|
MSG = 'Use `%<suggestion>s` instead of '\
|
56
56
|
'`%<sorter>s...%<accessor_source>s`.'
|
57
57
|
|
58
|
-
def_node_matcher :unneeded_sort?,
|
58
|
+
def_node_matcher :unneeded_sort?, <<~MATCHER
|
59
59
|
{
|
60
60
|
(send $(send _ $:sort ...) ${:last :first})
|
61
61
|
(send $(send _ $:sort ...) ${:[] :at :slice} {(int 0) (int -1)})
|
@@ -25,7 +25,7 @@ module RuboCop
|
|
25
25
|
MSG = 'Use `%<receiver>s.unpack1(%<format>s)` instead of '\
|
26
26
|
'`%<receiver>s.unpack(%<format>s)%<method>s`.'
|
27
27
|
|
28
|
-
def_node_matcher :unpack_and_first_element?,
|
28
|
+
def_node_matcher :unpack_and_first_element?, <<~PATTERN
|
29
29
|
{
|
30
30
|
(send $(send (...) :unpack $(...)) :first)
|
31
31
|
(send $(send (...) :unpack $(...)) {:[] :slice :at} (int 0))
|
@@ -73,14 +73,14 @@ module RuboCop
|
|
73
73
|
)
|
74
74
|
end
|
75
75
|
|
76
|
-
def_node_matcher :zero_length_predicate,
|
76
|
+
def_node_matcher :zero_length_predicate, <<~PATTERN
|
77
77
|
{(send (send (...) ${:length :size}) $:== (int $0))
|
78
78
|
(send (int $0) $:== (send (...) ${:length :size}))
|
79
79
|
(send (send (...) ${:length :size}) $:< (int $1))
|
80
80
|
(send (int $1) $:> (send (...) ${:length :size}))}
|
81
81
|
PATTERN
|
82
82
|
|
83
|
-
def_node_matcher :nonzero_length_predicate,
|
83
|
+
def_node_matcher :nonzero_length_predicate, <<~PATTERN
|
84
84
|
{(send (send (...) ${:length :size}) ${:> :!=} (int $0))
|
85
85
|
(send (int $0) ${:< :!=} (send (...) ${:length :size}))}
|
86
86
|
PATTERN
|
@@ -92,14 +92,14 @@ module RuboCop
|
|
92
92
|
"!#{other_receiver(node).source}.empty?"
|
93
93
|
end
|
94
94
|
|
95
|
-
def_node_matcher :zero_length_receiver,
|
95
|
+
def_node_matcher :zero_length_receiver, <<~PATTERN
|
96
96
|
{(send (send $_ _) :== (int 0))
|
97
97
|
(send (int 0) :== (send $_ _))
|
98
98
|
(send (send $_ _) :< (int 1))
|
99
99
|
(send (int 1) :> (send $_ _))}
|
100
100
|
PATTERN
|
101
101
|
|
102
|
-
def_node_matcher :other_receiver,
|
102
|
+
def_node_matcher :other_receiver, <<~PATTERN
|
103
103
|
{(send (send $_ _) _ _)
|
104
104
|
(send _ _ (send $_ _))}
|
105
105
|
PATTERN
|
@@ -107,7 +107,7 @@ module RuboCop
|
|
107
107
|
# Some collection like objects in the Ruby standard library
|
108
108
|
# implement `#size`, but not `#empty`. We ignore those to
|
109
109
|
# reduce false positives.
|
110
|
-
def_node_matcher :non_polymorphic_collection?,
|
110
|
+
def_node_matcher :non_polymorphic_collection?, <<~PATTERN
|
111
111
|
{(send (send (send (const nil? :File) :stat _) ...) ...)
|
112
112
|
(send (send (send (const nil? {:Tempfile :StringIO}) {:new :open} ...) ...) ...)}
|
113
113
|
PATTERN
|
data/lib/rubocop/cop/team.rb
CHANGED
@@ -81,6 +81,9 @@ module RuboCop
|
|
81
81
|
File.open(filename, 'w') { |f| f.write(new_source) }
|
82
82
|
end
|
83
83
|
@updated_source_file = true
|
84
|
+
rescue RuboCop::ErrorWithAnalyzedFileLocation => e
|
85
|
+
process_errors(buffer.name, [e])
|
86
|
+
raise e.cause
|
84
87
|
end
|
85
88
|
|
86
89
|
private
|
@@ -103,8 +106,8 @@ module RuboCop
|
|
103
106
|
|
104
107
|
other = investigate(other_cops, processed_source)
|
105
108
|
|
106
|
-
errors = autocorrect.errors
|
107
|
-
|
109
|
+
errors = [*autocorrect.errors, *other.errors]
|
110
|
+
process_errors(processed_source.path, errors)
|
108
111
|
|
109
112
|
autocorrect.offenses.concat(other.offenses)
|
110
113
|
end
|
@@ -149,19 +152,17 @@ module RuboCop
|
|
149
152
|
end
|
150
153
|
end
|
151
154
|
|
152
|
-
def
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
location = "#{file}#{line}#{column}"
|
155
|
+
def process_errors(file, errors)
|
156
|
+
errors.each do |error|
|
157
|
+
line = ":#{error.line}" if error.line
|
158
|
+
column = ":#{error.column}" if error.column
|
159
|
+
location = "#{file}#{line}#{column}"
|
160
|
+
cause = error.cause
|
159
161
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
end
|
162
|
+
if cause.is_a?(Warning)
|
163
|
+
handle_warning(cause, location)
|
164
|
+
else
|
165
|
+
handle_error(cause, location, error.cop)
|
165
166
|
end
|
166
167
|
end
|
167
168
|
end
|
data/lib/rubocop/error.rb
CHANGED
@@ -8,4 +8,27 @@ module RuboCop
|
|
8
8
|
class Error < StandardError; end
|
9
9
|
|
10
10
|
class ValidationError < Error; end
|
11
|
+
|
12
|
+
# A wrapper to display errored location of analyzed file.
|
13
|
+
class ErrorWithAnalyzedFileLocation < Error
|
14
|
+
def initialize(cause:, node:, cop:)
|
15
|
+
@cause = cause
|
16
|
+
@cop = cop
|
17
|
+
@location = node.is_a?(RuboCop::AST::Node) ? node.loc : node
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :cause, :cop
|
21
|
+
|
22
|
+
def line
|
23
|
+
@location&.line
|
24
|
+
end
|
25
|
+
|
26
|
+
def column
|
27
|
+
@location&.column
|
28
|
+
end
|
29
|
+
|
30
|
+
def message
|
31
|
+
"cause: #{cause.inspect}"
|
32
|
+
end
|
33
|
+
end
|
11
34
|
end
|
data/lib/rubocop/node_pattern.rb
CHANGED
@@ -612,7 +612,7 @@ module RuboCop
|
|
612
612
|
end
|
613
613
|
|
614
614
|
def emit_method_code
|
615
|
-
|
615
|
+
<<~RUBY
|
616
616
|
return unless #{@match_code}
|
617
617
|
block_given? ? #{emit_yield_capture} : (return #{emit_retval})
|
618
618
|
RUBY
|
@@ -746,7 +746,7 @@ module RuboCop
|
|
746
746
|
|
747
747
|
def node_search_body(method_name, trailing_params, prelude, match_code,
|
748
748
|
on_match)
|
749
|
-
|
749
|
+
<<~RUBY
|
750
750
|
def #{method_name}(node0#{trailing_params})
|
751
751
|
#{prelude}
|
752
752
|
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,6 +255,7 @@ module RuboCop
|
|
253
255
|
@options = options
|
254
256
|
end
|
255
257
|
|
258
|
+
# rubocop:disable Metrics/AbcSize
|
256
259
|
def validate_compatibility # rubocop:disable Metrics/MethodLength
|
257
260
|
if only_includes_unneeded_disable?
|
258
261
|
raise OptionArgumentError, 'Lint/UnneededCopDisableDirective can not ' \
|
@@ -270,6 +273,7 @@ module RuboCop
|
|
270
273
|
'--display-only-fail-level-offenses'
|
271
274
|
end
|
272
275
|
validate_auto_gen_config
|
276
|
+
validate_auto_correct
|
273
277
|
validate_parallel
|
274
278
|
|
275
279
|
return if incompatible_options.size <= 1
|
@@ -277,6 +281,7 @@ module RuboCop
|
|
277
281
|
raise OptionArgumentError, 'Incompatible cli options: ' \
|
278
282
|
"#{incompatible_options.inspect}"
|
279
283
|
end
|
284
|
+
# rubocop:enable Metrics/AbcSize
|
280
285
|
|
281
286
|
def validate_auto_gen_config
|
282
287
|
return if @options.key?(:auto_gen_config)
|
@@ -292,6 +297,15 @@ module RuboCop
|
|
292
297
|
end
|
293
298
|
end
|
294
299
|
|
300
|
+
def validate_auto_correct
|
301
|
+
return if @options.key?(:auto_correct)
|
302
|
+
return unless @options.key?(:disable_uncorrectable)
|
303
|
+
|
304
|
+
raise OptionArgumentError,
|
305
|
+
format('--%<flag>s can only be used together with --auto-correct.',
|
306
|
+
flag: '--disable-uncorrectable')
|
307
|
+
end
|
308
|
+
|
295
309
|
def validate_parallel
|
296
310
|
return unless @options.key?(:parallel)
|
297
311
|
|
@@ -378,6 +392,9 @@ module RuboCop
|
|
378
392
|
exclude_limit: ['Used together with --auto-gen-config to',
|
379
393
|
'set the limit for how many Exclude',
|
380
394
|
"properties to generate. Default is #{MAX_EXCL}."],
|
395
|
+
disable_uncorrectable: ['Used with --auto-correct to annotate any',
|
396
|
+
'offenses that do not support autocorrect',
|
397
|
+
'with `rubocop:disable` comments.'],
|
381
398
|
force_exclusion: ['Force excluding files specified in the',
|
382
399
|
'configuration `Exclude` even if they are',
|
383
400
|
'explicitly passed as arguments.'],
|