rubocop 0.81.0 → 0.82.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 -2
- data/config/default.yml +59 -13
- data/lib/rubocop.rb +4 -2
- data/lib/rubocop/ast/node.rb +1 -1
- data/lib/rubocop/ast/node/array_node.rb +13 -0
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +8 -0
- data/lib/rubocop/cli.rb +10 -4
- data/lib/rubocop/config.rb +9 -1
- data/lib/rubocop/config_loader.rb +24 -15
- data/lib/rubocop/config_loader_resolver.rb +1 -1
- data/lib/rubocop/config_obsoletion.rb +1 -0
- data/lib/rubocop/config_validator.rb +16 -0
- data/lib/rubocop/cop/badge.rb +5 -5
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
- data/lib/rubocop/cop/corrector.rb +48 -24
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -2
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/string_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +16 -10
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/{tab.rb → indentation_style.rb} +48 -6
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +2 -2
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -3
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +133 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_range_literal.rb +2 -2
- data/lib/rubocop/cop/lint/boolean_symbol.rb +2 -2
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
- data/lib/rubocop/cop/lint/interpolation_check.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
- data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -2
- data/lib/rubocop/cop/lint/raise_exception.rb +42 -6
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
- data/lib/rubocop/cop/lint/unified_integer.rb +0 -2
- data/lib/rubocop/cop/lint/uri_regexp.rb +4 -4
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +4 -3
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +2 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
- data/lib/rubocop/cop/registry.rb +11 -4
- data/lib/rubocop/cop/style/alias.rb +4 -4
- data/lib/rubocop/cop/style/and_or.rb +5 -6
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/case_equality.rb +24 -1
- data/lib/rubocop/cop/style/character_literal.rb +2 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +8 -8
- data/lib/rubocop/cop/style/copyright.rb +1 -1
- data/lib/rubocop/cop/style/dir.rb +1 -1
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +49 -0
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +1 -1
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
- data/lib/rubocop/cop/style/each_with_object.rb +3 -3
- data/lib/rubocop/cop/style/empty_method.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +1 -1
- data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -3
- data/lib/rubocop/cop/style/exponential_notation.rb +119 -0
- data/lib/rubocop/cop/style/format_string.rb +2 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +3 -3
- data/lib/rubocop/cop/style/hash_syntax.rb +3 -5
- data/lib/rubocop/cop/style/hash_transform_values.rb +0 -3
- data/lib/rubocop/cop/style/if_unless_modifier.rb +23 -3
- data/lib/rubocop/cop/style/lambda.rb +2 -2
- data/lib/rubocop/cop/style/lambda_call.rb +2 -2
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/module_function.rb +2 -2
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +2 -4
- data/lib/rubocop/cop/style/next.rb +2 -2
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
- data/lib/rubocop/cop/style/non_nil_check.rb +4 -4
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
- data/lib/rubocop/cop/style/one_line_conditional.rb +1 -1
- data/lib/rubocop/cop/style/or_assignment.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
- data/lib/rubocop/cop/style/redundant_condition.rb +3 -4
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +3 -3
- data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
- data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
- data/lib/rubocop/cop/style/redundant_return.rb +5 -7
- data/lib/rubocop/cop/style/redundant_self.rb +1 -1
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- 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/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -4
- data/lib/rubocop/cop/style/string_hash_keys.rb +1 -1
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/symbol_literal.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -2
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +2 -1
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +3 -0
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +0 -4
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +0 -1
- data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
- data/lib/rubocop/options.rb +7 -1
- data/lib/rubocop/processed_source.rb +0 -3
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +1 -1
- data/lib/rubocop/rspec/shared_contexts.rb +0 -4
- data/lib/rubocop/runner.rb +1 -1
- data/lib/rubocop/target_ruby.rb +2 -2
- data/lib/rubocop/version.rb +1 -1
- metadata +7 -5
- data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
def_node_matcher :uri_regexp_with_argument?, <<~PATTERN
|
22
22
|
(send
|
23
23
|
(const ${nil? cbase} :URI) :regexp
|
24
|
-
(str
|
24
|
+
${(str _) (array ...)})
|
25
25
|
PATTERN
|
26
26
|
|
27
27
|
def_node_matcher :uri_regexp_without_argument?, <<~PATTERN
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
32
32
|
def on_send(node)
|
33
33
|
uri_regexp_with_argument?(node) do |double_colon, arg|
|
34
34
|
register_offense(
|
35
|
-
node, top_level: double_colon ? '::' : '', arg: "(
|
35
|
+
node, top_level: double_colon ? '::' : '', arg: "(#{arg.source})"
|
36
36
|
)
|
37
37
|
end
|
38
38
|
|
@@ -51,10 +51,10 @@ module RuboCop
|
|
51
51
|
double_colon, arg = captured_values
|
52
52
|
|
53
53
|
top_level = double_colon ? '::' : ''
|
54
|
-
argument = arg ? "(
|
54
|
+
argument = arg ? "(#{arg.source})" : ''
|
55
55
|
|
56
56
|
corrector.replace(
|
57
|
-
node
|
57
|
+
node,
|
58
58
|
"#{top_level}URI::DEFAULT_PARSER.make_regexp#{argument}"
|
59
59
|
)
|
60
60
|
end
|
@@ -58,12 +58,13 @@ module RuboCop
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def indentation_multiplier
|
61
|
-
return 1 if config.for_cop('Layout/
|
61
|
+
return 1 if config.for_cop('Layout/IndentationStyle')['Enabled']
|
62
62
|
|
63
63
|
default_configuration = RuboCop::ConfigLoader.default_configuration
|
64
|
-
config.for_cop('Layout/
|
64
|
+
config.for_cop('Layout/IndentationStyle')['IndentationWidth'] ||
|
65
65
|
config.for_cop('Layout/IndentationWidth')['Width'] ||
|
66
|
-
default_configuration
|
66
|
+
default_configuration
|
67
|
+
.for_cop('Layout/IndentationStyle')['IndentationWidth'] ||
|
67
68
|
default_configuration.for_cop('Layout/IndentationWidth')['Width']
|
68
69
|
end
|
69
70
|
end
|
@@ -135,7 +135,7 @@ module RuboCop
|
|
135
135
|
|
136
136
|
def avoid_comma(kind, comma_begin_pos, extra_info)
|
137
137
|
range = range_between(comma_begin_pos, comma_begin_pos + 1)
|
138
|
-
article =
|
138
|
+
article = /array/.match?(kind) ? 'an' : 'a'
|
139
139
|
msg = format(
|
140
140
|
MSG,
|
141
141
|
command: 'Avoid',
|
@@ -45,8 +45,9 @@ module RuboCop
|
|
45
45
|
# SomeClass = Class.new(...)
|
46
46
|
# SomeClass = Struct.new(...)
|
47
47
|
return if allowed_assignment?(value)
|
48
|
+
return if SNAKE_CASE.match?(const_name)
|
48
49
|
|
49
|
-
add_offense(node, location: :name)
|
50
|
+
add_offense(node, location: :name)
|
50
51
|
end
|
51
52
|
|
52
53
|
private
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
def meaningful_delimiters?(node)
|
40
40
|
delimiters = delimiter_string(node)
|
41
41
|
|
42
|
-
return false unless
|
42
|
+
return false unless /\w/.match?(delimiters)
|
43
43
|
|
44
44
|
forbidden_delimiters.none? do |forbidden_delimiter|
|
45
45
|
delimiters =~ Regexp.new(forbidden_delimiter)
|
data/lib/rubocop/cop/registry.rb
CHANGED
@@ -22,12 +22,13 @@ module RuboCop
|
|
22
22
|
|
23
23
|
# Registry that tracks all cops by their badge and department.
|
24
24
|
class Registry
|
25
|
-
def initialize(cops = [])
|
25
|
+
def initialize(cops = [], options = {})
|
26
26
|
@registry = {}
|
27
27
|
@departments = {}
|
28
28
|
@cops_by_cop_name = Hash.new { |hash, key| hash[key] = [] }
|
29
29
|
|
30
30
|
cops.each { |cop| enlist(cop) }
|
31
|
+
@options = options
|
31
32
|
end
|
32
33
|
|
33
34
|
def enlist(cop)
|
@@ -147,9 +148,8 @@ module RuboCop
|
|
147
148
|
def enabled?(cop, config, only_safe)
|
148
149
|
cfg = config.for_cop(cop)
|
149
150
|
|
150
|
-
|
151
|
-
|
152
|
-
cop_enabled = cfg.fetch('Enabled') == true
|
151
|
+
cop_enabled = cfg.fetch('Enabled') == true ||
|
152
|
+
enabled_pending_cop?(cfg, config)
|
153
153
|
|
154
154
|
if only_safe
|
155
155
|
cop_enabled && cfg.fetch('Safe', true)
|
@@ -158,6 +158,13 @@ module RuboCop
|
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
|
+
def enabled_pending_cop?(cop_cfg, config)
|
162
|
+
return false if @options[:disable_pending_cops]
|
163
|
+
|
164
|
+
cop_cfg.fetch('Enabled') == 'pending' &&
|
165
|
+
(@options[:enable_pending_cops] || config.enabled_new_cops?)
|
166
|
+
end
|
167
|
+
|
161
168
|
def names
|
162
169
|
cops.map(&:cop_name)
|
163
170
|
end
|
@@ -115,7 +115,7 @@ module RuboCop
|
|
115
115
|
lambda do |corrector|
|
116
116
|
new, old = *send_node.arguments
|
117
117
|
replacement = "alias #{identifier(new)} #{identifier(old)}"
|
118
|
-
corrector.replace(send_node
|
118
|
+
corrector.replace(send_node, replacement)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -125,15 +125,15 @@ module RuboCop
|
|
125
125
|
'alias_method ' \
|
126
126
|
":#{identifier(node.new_identifier)}, " \
|
127
127
|
":#{identifier(node.old_identifier)}"
|
128
|
-
corrector.replace(node
|
128
|
+
corrector.replace(node, replacement)
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
132
|
def correct_alias_with_symbol_args(node)
|
133
133
|
lambda do |corrector|
|
134
|
-
corrector.replace(node.new_identifier
|
134
|
+
corrector.replace(node.new_identifier,
|
135
135
|
node.new_identifier.source[1..-1])
|
136
|
-
corrector.replace(node.old_identifier
|
136
|
+
corrector.replace(node.old_identifier,
|
137
137
|
node.old_identifier.source[1..-1])
|
138
138
|
end
|
139
139
|
end
|
@@ -97,12 +97,12 @@ module RuboCop
|
|
97
97
|
return unless correctable_send?(node)
|
98
98
|
|
99
99
|
corrector.replace(whitespace_before_arg(node), '(')
|
100
|
-
corrector.insert_after(node.last_argument
|
100
|
+
corrector.insert_after(node.last_argument, ')')
|
101
101
|
end
|
102
102
|
|
103
103
|
def correct_setter(node, corrector)
|
104
|
-
corrector.insert_before(node.receiver
|
105
|
-
corrector.insert_after(node.last_argument
|
104
|
+
corrector.insert_before(node.receiver, '(')
|
105
|
+
corrector.insert_after(node.last_argument, ')')
|
106
106
|
end
|
107
107
|
|
108
108
|
# ! is a special case:
|
@@ -124,8 +124,7 @@ module RuboCop
|
|
124
124
|
def correct_other(node, corrector)
|
125
125
|
return if node.source_range.begin.is?('(')
|
126
126
|
|
127
|
-
corrector.
|
128
|
-
corrector.insert_after(node.source_range, ')')
|
127
|
+
corrector.wrap(node, '(', ')')
|
129
128
|
end
|
130
129
|
|
131
130
|
def correctable_send?(node)
|
@@ -137,7 +136,7 @@ module RuboCop
|
|
137
136
|
end_paren = begin_paren
|
138
137
|
# Increment position of parenthesis, unless message is a predicate
|
139
138
|
# method followed by a non-whitespace char (e.g. is_a?String).
|
140
|
-
end_paren += 1 unless node.source
|
139
|
+
end_paren += 1 unless /\?\S/.match?(node.source)
|
141
140
|
range_between(begin_paren, end_paren)
|
142
141
|
end
|
143
142
|
end
|
@@ -16,14 +16,37 @@ module RuboCop
|
|
16
16
|
# (1..100).include?(7)
|
17
17
|
# some_string =~ /something/
|
18
18
|
#
|
19
|
+
# @example AllowOnConstant
|
20
|
+
# # Style/CaseEquality:
|
21
|
+
# # AllowOnConstant: true
|
22
|
+
#
|
23
|
+
# # bad
|
24
|
+
# (1..100) === 7
|
25
|
+
# /something/ === some_string
|
26
|
+
#
|
27
|
+
# # good
|
28
|
+
# Array === something
|
29
|
+
# (1..100).include?(7)
|
30
|
+
# some_string =~ /something/
|
31
|
+
#
|
19
32
|
class CaseEquality < Cop
|
20
33
|
MSG = 'Avoid the use of the case equality operator `===`.'
|
21
34
|
|
22
|
-
def_node_matcher :case_equality?, '(send
|
35
|
+
def_node_matcher :case_equality?, '(send #const? :=== _)'
|
23
36
|
|
24
37
|
def on_send(node)
|
25
38
|
case_equality?(node) { add_offense(node, location: :selector) }
|
26
39
|
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def const?(node)
|
44
|
+
if cop_config.fetch('AllowOnConstant', false)
|
45
|
+
!node.const_type?
|
46
|
+
else
|
47
|
+
true
|
48
|
+
end
|
49
|
+
end
|
27
50
|
end
|
28
51
|
end
|
29
52
|
end
|
@@ -33,9 +33,9 @@ module RuboCop
|
|
33
33
|
# special character like \n
|
34
34
|
# or ' which needs to use "" or be escaped.
|
35
35
|
if string.length == 2 || string == "'"
|
36
|
-
corrector.replace(node
|
36
|
+
corrector.replace(node, %("#{string}"))
|
37
37
|
elsif string.length == 1 # normal character
|
38
|
-
corrector.replace(node
|
38
|
+
corrector.replace(node, "'#{string}'")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -458,7 +458,7 @@ module RuboCop
|
|
458
458
|
def correct_if_branches(corrector, cop, node)
|
459
459
|
if_branch, elsif_branches, else_branch = extract_tail_branches(node)
|
460
460
|
|
461
|
-
corrector.insert_before(node
|
461
|
+
corrector.insert_before(node, lhs(if_branch))
|
462
462
|
replace_branch_assignment(corrector, if_branch)
|
463
463
|
correct_branches(corrector, elsif_branches)
|
464
464
|
replace_branch_assignment(corrector, else_branch)
|
@@ -475,13 +475,13 @@ module RuboCop
|
|
475
475
|
source
|
476
476
|
end
|
477
477
|
|
478
|
-
corrector.replace(branch
|
478
|
+
corrector.replace(branch, replacement)
|
479
479
|
end
|
480
480
|
|
481
481
|
def correct_branches(corrector, branches)
|
482
482
|
branches.each do |branch|
|
483
483
|
*_, assignment = *branch
|
484
|
-
corrector.replace(branch
|
484
|
+
corrector.replace(branch, assignment.source)
|
485
485
|
end
|
486
486
|
end
|
487
487
|
end
|
@@ -494,7 +494,7 @@ module RuboCop
|
|
494
494
|
|
495
495
|
def correct(node)
|
496
496
|
lambda do |corrector|
|
497
|
-
corrector.replace(node
|
497
|
+
corrector.replace(node, correction(node))
|
498
498
|
end
|
499
499
|
end
|
500
500
|
|
@@ -547,7 +547,7 @@ module RuboCop
|
|
547
547
|
end
|
548
548
|
|
549
549
|
def move_branch_inside_condition(corrector, branch, assignment)
|
550
|
-
corrector.insert_before(branch
|
550
|
+
corrector.insert_before(branch, assignment.source)
|
551
551
|
end
|
552
552
|
end
|
553
553
|
end
|
@@ -589,7 +589,7 @@ module RuboCop
|
|
589
589
|
def move_branch_inside_condition(corrector, branch, condition,
|
590
590
|
assignment, column)
|
591
591
|
branch_assignment = tail(branch)
|
592
|
-
corrector.insert_before(branch_assignment
|
592
|
+
corrector.insert_before(branch_assignment,
|
593
593
|
assignment.source)
|
594
594
|
|
595
595
|
remove_whitespace_in_branches(corrector, branch, condition, column)
|
@@ -611,7 +611,7 @@ module RuboCop
|
|
611
611
|
when_branches, else_branch = extract_tail_branches(node)
|
612
612
|
|
613
613
|
lambda do |corrector|
|
614
|
-
corrector.insert_before(node
|
614
|
+
corrector.insert_before(node, lhs(else_branch))
|
615
615
|
correct_branches(corrector, when_branches)
|
616
616
|
replace_branch_assignment(corrector, else_branch)
|
617
617
|
|
@@ -652,7 +652,7 @@ module RuboCop
|
|
652
652
|
def move_branch_inside_condition(corrector, branch, condition,
|
653
653
|
assignment, column)
|
654
654
|
branch_assignment = tail(branch)
|
655
|
-
corrector.insert_before(branch_assignment
|
655
|
+
corrector.insert_before(branch_assignment,
|
656
656
|
assignment.source)
|
657
657
|
|
658
658
|
remove_whitespace_in_branches(corrector, branch, condition, column)
|
@@ -55,7 +55,7 @@ module RuboCop
|
|
55
55
|
raise Warning, AUTOCORRECT_EMPTY_WARNING if autocorrect_notice.empty?
|
56
56
|
|
57
57
|
regex = Regexp.new(notice)
|
58
|
-
return if autocorrect_notice
|
58
|
+
return if autocorrect_notice&.match?(regex)
|
59
59
|
|
60
60
|
raise Warning, "AutocorrectNotice '#{autocorrect_notice}' must " \
|
61
61
|
"match Notice /#{notice}/"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Lint/RedundantCopDisableDirective
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module Style
|
8
|
+
# Detects comments to enable/disable RuboCop.
|
9
|
+
# This is useful if want to make sure that every RuboCop error gets fixed
|
10
|
+
# and not quickly disabled with a comment.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# # bad
|
14
|
+
# # rubocop:disable Metrics/AbcSize
|
15
|
+
# def f
|
16
|
+
# end
|
17
|
+
# # rubocop:enable Metrics/AbcSize
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
# def fixed_method_name_and_no_rubocop_comments
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
class DisableCopsWithinSourceCodeDirective < Cop
|
24
|
+
# rubocop:enable Lint/RedundantCopDisableDirective
|
25
|
+
MSG = 'Comment to disable/enable RuboCop.'
|
26
|
+
|
27
|
+
def investigate(processed_source)
|
28
|
+
processed_source.comments.each do |comment|
|
29
|
+
next unless rubocop_directive_comment?(comment)
|
30
|
+
|
31
|
+
add_offense(comment)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def autocorrect(comment)
|
36
|
+
lambda do |corrector|
|
37
|
+
corrector.replace(comment, '')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def rubocop_directive_comment?(comment)
|
44
|
+
comment.text =~ CommentConfig::COMMENT_DIRECTIVE_REGEXP
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -48,15 +48,15 @@ module RuboCop
|
|
48
48
|
|
49
49
|
first_arg, second_arg = *node.arguments
|
50
50
|
|
51
|
-
corrector.replace(first_arg
|
52
|
-
corrector.replace(second_arg
|
51
|
+
corrector.replace(first_arg, second_arg.source)
|
52
|
+
corrector.replace(second_arg, first_arg.source)
|
53
53
|
|
54
54
|
return_value = return_value(node.body)
|
55
55
|
|
56
56
|
if return_value_occupies_whole_line?(return_value)
|
57
57
|
corrector.remove(whole_line_expression(return_value))
|
58
58
|
else
|
59
|
-
corrector.remove(return_value
|
59
|
+
corrector.remove(return_value)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|