rubocop 0.75.1 → 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 +1 -1
- data/config/default.yml +52 -53
- data/lib/rubocop.rb +10 -9
- data/lib/rubocop/ast/builder.rb +1 -0
- data/lib/rubocop/ast/node.rb +4 -0
- data/lib/rubocop/ast/node/return_node.rb +24 -0
- data/lib/rubocop/cli.rb +7 -4
- data/lib/rubocop/comment_config.rb +2 -2
- data/lib/rubocop/config.rb +7 -0
- data/lib/rubocop/config_loader.rb +1 -1
- data/lib/rubocop/config_loader_resolver.rb +2 -1
- data/lib/rubocop/config_obsoletion.rb +9 -0
- data/lib/rubocop/config_validator.rb +24 -15
- data/lib/rubocop/cop/commissioner.rb +15 -7
- data/lib/rubocop/cop/cop.rb +10 -6
- data/lib/rubocop/cop/corrector.rb +8 -7
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/layout/align_hash.rb +6 -2
- 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/end_of_line.rb +8 -3
- data/lib/rubocop/cop/layout/indent_first_argument.rb +9 -7
- data/lib/rubocop/cop/layout/indent_first_hash_element.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -4
- data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
- data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +23 -23
- 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} +1 -1
- data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +5 -5
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
- data/lib/rubocop/cop/lint/void.rb +4 -4
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/line_length.rb +1 -4
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
- data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +5 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -6
- data/lib/rubocop/cop/naming/file_name.rb +12 -5
- data/lib/rubocop/cop/registry.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +2 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +6 -6
- data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
- data/lib/rubocop/cop/style/copyright.rb +11 -7
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +2 -2
- 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/format_string.rb +10 -7
- data/lib/rubocop/cop/style/format_string_token.rb +2 -0
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +10 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +9 -2
- data/lib/rubocop/cop/style/infinite_loop.rb +4 -3
- data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
- data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
- data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
- data/lib/rubocop/cop/style/multiline_when_then.rb +1 -1
- data/lib/rubocop/cop/style/nested_modifier.rb +4 -2
- data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
- 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/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
- data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +25 -21
- data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +4 -4
- data/lib/rubocop/cop/style/safe_navigation.rb +13 -10
- data/lib/rubocop/cop/style/semicolon.rb +2 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/utils/format_string.rb +10 -18
- data/lib/rubocop/cop/variable_force.rb +7 -5
- data/lib/rubocop/node_pattern.rb +3 -1
- data/lib/rubocop/options.rb +12 -6
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/runner.rb +32 -27
- data/lib/rubocop/target_finder.rb +12 -6
- data/lib/rubocop/version.rb +1 -1
- metadata +12 -11
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Lint/
|
3
|
+
# rubocop:disable Lint/RedundantCopDisableDirective
|
4
4
|
module RuboCop
|
5
5
|
module Cop
|
6
6
|
module Lint
|
@@ -81,4 +81,4 @@ module RuboCop
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
84
|
-
# rubocop:enable Lint/
|
84
|
+
# rubocop:enable Lint/RedundantCopDisableDirective, Layout/SpaceAroundOperators
|
data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb}
RENAMED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# The Lint/
|
4
|
-
# to be able to provide a (bad) example of
|
5
|
-
# rubocop:disable Lint/
|
3
|
+
# The Lint/RedundantCopDisableDirective cop needs to be disabled so as
|
4
|
+
# to be able to provide a (bad) example of a redundant disable.
|
5
|
+
# rubocop:disable Lint/RedundantCopDisableDirective
|
6
6
|
module RuboCop
|
7
7
|
module Cop
|
8
8
|
module Lint
|
@@ -25,21 +25,21 @@ module RuboCop
|
|
25
25
|
#
|
26
26
|
# # good
|
27
27
|
# x += 1
|
28
|
-
class
|
28
|
+
class RedundantCopDisableDirective < Cop
|
29
29
|
include NameSimilarity
|
30
30
|
include RangeHelp
|
31
31
|
|
32
|
-
COP_NAME = 'Lint/
|
32
|
+
COP_NAME = 'Lint/RedundantCopDisableDirective'
|
33
33
|
|
34
34
|
def check(offenses, cop_disabled_line_ranges, comments)
|
35
|
-
|
35
|
+
redundant_cops = Hash.new { |h, k| h[k] = Set.new }
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
each_redundant_disable(cop_disabled_line_ranges,
|
38
|
+
offenses, comments) do |comment, redundant_cop|
|
39
|
+
redundant_cops[comment].add(redundant_cop)
|
40
40
|
end
|
41
41
|
|
42
|
-
add_offenses(
|
42
|
+
add_offenses(redundant_cops)
|
43
43
|
end
|
44
44
|
|
45
45
|
def autocorrect(args)
|
@@ -89,8 +89,8 @@ module RuboCop
|
|
89
89
|
newlines: false)
|
90
90
|
end
|
91
91
|
|
92
|
-
def
|
93
|
-
|
92
|
+
def each_redundant_disable(cop_disabled_line_ranges, offenses, comments,
|
93
|
+
&block)
|
94
94
|
disabled_ranges = cop_disabled_line_ranges[COP_NAME] || [0..0]
|
95
95
|
|
96
96
|
cop_disabled_line_ranges.each do |cop, line_ranges|
|
@@ -110,9 +110,9 @@ module RuboCop
|
|
110
110
|
comment = comments.find { |c| c.loc.line == line_range.begin }
|
111
111
|
next if ignore_offense?(disabled_ranges, line_range)
|
112
112
|
|
113
|
-
|
114
|
-
|
115
|
-
yield comment,
|
113
|
+
redundant_cop = find_redundant(comment, offenses, cop, line_range,
|
114
|
+
line_ranges[ix + 1])
|
115
|
+
yield comment, redundant_cop if redundant_cop
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
@@ -123,24 +123,24 @@ module RuboCop
|
|
123
123
|
|
124
124
|
# If a cop is disabled in a range that begins on the same line as
|
125
125
|
# the end of the previous range, it means that the cop was
|
126
|
-
# already disabled by an earlier comment. So it's
|
126
|
+
# already disabled by an earlier comment. So it's redundant
|
127
127
|
# whether there are offenses or not.
|
128
|
-
|
128
|
+
redundant_comment = comments.find do |c|
|
129
129
|
c.loc.line == range.begin &&
|
130
130
|
# Comments disabling all cops don't count since it's reasonable
|
131
131
|
# to disable a few select cops first and then all cops further
|
132
132
|
# down in the code.
|
133
133
|
!all_disabled?(c)
|
134
134
|
end
|
135
|
-
yield
|
135
|
+
yield redundant_comment if redundant_comment
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
-
def
|
139
|
+
def find_redundant(comment, offenses, cop, line_range, next_line_range)
|
140
140
|
if all_disabled?(comment)
|
141
141
|
# If there's a disable all comment followed by a comment
|
142
142
|
# specifically disabling `cop`, we don't report the `all`
|
143
|
-
# comment. If the disable all comment is truly
|
143
|
+
# comment. If the disable all comment is truly redundant, we will
|
144
144
|
# detect that when examining the comments of another cop, and we
|
145
145
|
# get the full line range for the disable all.
|
146
146
|
if (next_line_range.nil? ||
|
@@ -170,8 +170,8 @@ module RuboCop
|
|
170
170
|
cops_string.split(/,\s*/).size
|
171
171
|
end
|
172
172
|
|
173
|
-
def add_offenses(
|
174
|
-
|
173
|
+
def add_offenses(redundant_cops)
|
174
|
+
redundant_cops.each do |comment, cops|
|
175
175
|
if all_disabled?(comment) ||
|
176
176
|
directive_count(comment) == cops.size
|
177
177
|
add_offense_for_entire_comment(comment, cops)
|
@@ -260,4 +260,4 @@ module RuboCop
|
|
260
260
|
end
|
261
261
|
end
|
262
262
|
end
|
263
|
-
# rubocop:enable Lint/
|
263
|
+
# rubocop:enable Lint/RedundantCopDisableDirective
|
data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb}
RENAMED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# The Lint/
|
3
|
+
# The Lint/RedundantCopEnableDirective cop needs to be disabled so as
|
4
4
|
# to be able to provide a (bad) example of an unneeded enable.
|
5
5
|
|
6
|
-
# rubocop:disable Lint/
|
6
|
+
# rubocop:disable Lint/RedundantCopEnableDirective
|
7
7
|
module RuboCop
|
8
8
|
module Cop
|
9
9
|
module Lint
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
32
32
|
# baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrr
|
33
33
|
# # rubocop:enable all
|
34
34
|
# baz
|
35
|
-
class
|
35
|
+
class RedundantCopEnableDirective < Cop
|
36
36
|
include RangeHelp
|
37
37
|
include SurroundingSpace
|
38
38
|
|
@@ -94,16 +94,14 @@ module RuboCop
|
|
94
94
|
|
95
95
|
def range_to_remove(begin_pos, end_pos, comma_pos, comment)
|
96
96
|
start = comment_start(comment)
|
97
|
-
buffer = processed_source.buffer
|
98
|
-
range_class = Parser::Source::Range
|
99
97
|
|
100
98
|
case comma_pos
|
101
99
|
when :before
|
102
|
-
|
100
|
+
range_between(start + begin_pos - 1, start + end_pos)
|
103
101
|
when :after
|
104
|
-
|
102
|
+
range_between(start + begin_pos, start + end_pos + 1)
|
105
103
|
else
|
106
|
-
|
104
|
+
range_between(start, comment.loc.expression.end_pos)
|
107
105
|
end
|
108
106
|
end
|
109
107
|
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
49
49
|
# else
|
50
50
|
# baz
|
51
51
|
# end
|
52
|
-
class
|
52
|
+
class RedundantSplatExpansion < Cop
|
53
53
|
MSG = 'Replace splat expansion with comma separated values.'
|
54
54
|
ARRAY_PARAM_MSG = 'Pass array contents as separate arguments.'
|
55
55
|
PERCENT_W = '%w'
|
@@ -70,7 +70,7 @@ module RuboCop
|
|
70
70
|
PATTERN
|
71
71
|
|
72
72
|
def on_splat(node)
|
73
|
-
|
73
|
+
redundant_splat_expansion(node) do
|
74
74
|
if array_splat?(node) &&
|
75
75
|
(method_argument?(node) || part_of_an_array?(node))
|
76
76
|
add_offense(node, message: ARRAY_PARAM_MSG)
|
@@ -90,7 +90,7 @@ module RuboCop
|
|
90
90
|
|
91
91
|
private
|
92
92
|
|
93
|
-
def
|
93
|
+
def redundant_splat_expansion(node)
|
94
94
|
literal_expansion(node) do |expanded_item|
|
95
95
|
if expanded_item.send_type?
|
96
96
|
return if array_new_inside_array_literal?(expanded_item)
|
@@ -119,7 +119,7 @@ module RuboCop
|
|
119
119
|
[node.parent.loc.expression, variable.source]
|
120
120
|
elsif !variable.array_type?
|
121
121
|
[loc.expression, "[#{variable.source}]"]
|
122
|
-
elsif
|
122
|
+
elsif redundant_brackets?(node)
|
123
123
|
[loc.expression, remove_brackets(variable)]
|
124
124
|
else
|
125
125
|
[loc.operator, '']
|
@@ -141,7 +141,7 @@ module RuboCop
|
|
141
141
|
parent.array_type? && parent.loc.begin && parent.loc.end
|
142
142
|
end
|
143
143
|
|
144
|
-
def
|
144
|
+
def redundant_brackets?(node)
|
145
145
|
parent = node.parent
|
146
146
|
grandparent = node.parent.parent
|
147
147
|
|
@@ -42,9 +42,9 @@ module RuboCop
|
|
42
42
|
|
43
43
|
method_chain = method_chain(node)
|
44
44
|
location =
|
45
|
-
Parser::Source::Range.new(node.
|
46
|
-
safe_nav.
|
47
|
-
method_chain.
|
45
|
+
Parser::Source::Range.new(node.source_range.source_buffer,
|
46
|
+
safe_nav.source_range.end_pos,
|
47
|
+
method_chain.source_range.end_pos)
|
48
48
|
add_offense(node, location: location)
|
49
49
|
end
|
50
50
|
end
|
@@ -54,9 +54,8 @@ module RuboCop
|
|
54
54
|
def method_chain(node)
|
55
55
|
chain = node
|
56
56
|
while chain.send_type?
|
57
|
-
chain = chain.parent if chain.parent
|
58
|
-
|
59
|
-
break
|
57
|
+
chain = chain.parent if chain.parent&.call_type?
|
58
|
+
break # FIXME: Unconditional break. Why while "loop" then?
|
60
59
|
end
|
61
60
|
chain
|
62
61
|
end
|
@@ -55,10 +55,10 @@ module RuboCop
|
|
55
55
|
VOID_CONTEXT_TYPES = %i[def for block].freeze
|
56
56
|
NONMUTATING_METHODS = %i[capitalize chomp chop collect compact
|
57
57
|
delete_prefix delete_suffix downcase
|
58
|
-
encode flatten gsub lstrip map next
|
59
|
-
reverse rotate rstrip scrub select
|
60
|
-
slice sort sort_by squeeze strip sub
|
61
|
-
swapcase tr tr_s transform_values
|
58
|
+
encode flatten gsub lstrip map merge next
|
59
|
+
reject reverse rotate rstrip scrub select
|
60
|
+
shuffle slice sort sort_by squeeze strip sub
|
61
|
+
succ swapcase tr tr_s transform_values
|
62
62
|
unicode_normalize uniq upcase].freeze
|
63
63
|
|
64
64
|
def on_block(node)
|
@@ -128,10 +128,7 @@ module RuboCop
|
|
128
128
|
return check_uri_line(line, line_index) if allow_uri?
|
129
129
|
|
130
130
|
register_offense(
|
131
|
-
|
132
|
-
processed_source.buffer, line_index,
|
133
|
-
highlight_start(line)...line_length(line)
|
134
|
-
),
|
131
|
+
excess_range(nil, line, line_index),
|
135
132
|
line,
|
136
133
|
line_index
|
137
134
|
)
|
@@ -36,15 +36,17 @@ module RuboCop
|
|
36
36
|
@node.each_node do |child|
|
37
37
|
if child.assignment?
|
38
38
|
@assignment += 1
|
39
|
-
elsif
|
39
|
+
elsif branch?(child)
|
40
40
|
evaluate_branch_nodes(child)
|
41
|
-
elsif
|
42
|
-
|
43
|
-
@condition += 1
|
41
|
+
elsif condition?(child)
|
42
|
+
evaluate_condition_node(child)
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
|
-
|
46
|
+
[
|
47
|
+
Math.sqrt(@assignment**2 + @branch**2 + @condition**2).round(2),
|
48
|
+
"<#{@assignment}, #{@branch}, #{@condition}>"
|
49
|
+
]
|
48
50
|
end
|
49
51
|
|
50
52
|
def evaluate_branch_nodes(node)
|
@@ -55,11 +57,26 @@ module RuboCop
|
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
58
|
-
def
|
60
|
+
def evaluate_condition_node(node)
|
61
|
+
@condition += 1 if else_branch?(node)
|
62
|
+
@condition += 1
|
63
|
+
end
|
64
|
+
|
65
|
+
def else_branch?(node)
|
59
66
|
%i[case if].include?(node.type) &&
|
60
67
|
node.else? &&
|
61
68
|
node.loc.else.is?('else')
|
62
69
|
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def branch?(node)
|
74
|
+
BRANCH_NODES.include?(node.type)
|
75
|
+
end
|
76
|
+
|
77
|
+
def condition?(node)
|
78
|
+
CONDITION_NODES.include?(node.type)
|
79
|
+
end
|
63
80
|
end
|
64
81
|
end
|
65
82
|
end
|
@@ -32,13 +32,14 @@ module RuboCop
|
|
32
32
|
return unless node.body
|
33
33
|
|
34
34
|
max = cop_config['Max']
|
35
|
-
complexity = complexity(node.body)
|
35
|
+
complexity, abc_vector = complexity(node.body)
|
36
36
|
|
37
37
|
return unless complexity > max
|
38
38
|
|
39
39
|
msg = format(self.class::MSG,
|
40
40
|
method: method_name,
|
41
41
|
complexity: complexity,
|
42
|
+
abc_vector: abc_vector,
|
42
43
|
max: max)
|
43
44
|
|
44
45
|
add_offense(node, message: msg) do
|
@@ -41,10 +41,13 @@ module RuboCop
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def length_in_modifier_form(node, cond, body_length)
|
44
|
-
|
45
|
-
|
44
|
+
keyword = node.loc.keyword
|
45
|
+
|
46
|
+
indentation = keyword.column * indentation_multiplier
|
47
|
+
kw_length = keyword.size
|
46
48
|
cond_length = cond.source_range.size
|
47
49
|
space = 1
|
50
|
+
|
48
51
|
indentation + body_length + space + kw_length + space + cond_length
|
49
52
|
end
|
50
53
|
|
@@ -18,12 +18,7 @@ module RuboCop
|
|
18
18
|
|
19
19
|
def check(node, items, kind, begin_pos, end_pos)
|
20
20
|
after_last_item = range_between(begin_pos, end_pos)
|
21
|
-
|
22
|
-
# If there is any heredoc in items, then match the comma succeeding
|
23
|
-
# any whitespace (except newlines), otherwise allow for newlines
|
24
|
-
comma_regex = any_heredoc?(items) ? /\A[^\S\n]*,/ : /\A\s*,/
|
25
|
-
comma_offset = after_last_item.source =~ comma_regex &&
|
26
|
-
after_last_item.source.index(',')
|
21
|
+
comma_offset = comma_offset(items, after_last_item)
|
27
22
|
|
28
23
|
if comma_offset && !inside_comment?(after_last_item, comma_offset)
|
29
24
|
check_comma(node, kind, after_last_item.begin_pos + comma_offset)
|
@@ -32,6 +27,13 @@ module RuboCop
|
|
32
27
|
end
|
33
28
|
end
|
34
29
|
|
30
|
+
def comma_offset(items, range)
|
31
|
+
# If there is any heredoc in items, then match the comma succeeding
|
32
|
+
# any whitespace (except newlines), otherwise allow for newlines
|
33
|
+
comma_regex = any_heredoc?(items) ? /\A[^\S\n]*,/ : /\A\s*,/
|
34
|
+
range.source =~ comma_regex && range.source.index(',')
|
35
|
+
end
|
36
|
+
|
35
37
|
def check_comma(node, kind, comma_pos)
|
36
38
|
return if should_have_comma?(style, node)
|
37
39
|
|
@@ -50,14 +50,11 @@ module RuboCop
|
|
50
50
|
def for_bad_filename(file_path)
|
51
51
|
basename = File.basename(file_path)
|
52
52
|
msg = if filename_good?(basename)
|
53
|
-
return
|
54
|
-
return if find_class_or_module(processed_source.ast,
|
55
|
-
to_namespace(file_path))
|
53
|
+
return if matching_definition?(file_path)
|
56
54
|
|
57
55
|
no_definition_message(basename, file_path)
|
58
56
|
else
|
59
|
-
return if
|
60
|
-
processed_source.start_with?('#!')
|
57
|
+
return if bad_filename_allowed?
|
61
58
|
|
62
59
|
other_message(basename)
|
63
60
|
end
|
@@ -65,6 +62,16 @@ module RuboCop
|
|
65
62
|
yield source_range(processed_source.buffer, 1, 0), msg
|
66
63
|
end
|
67
64
|
|
65
|
+
def matching_definition?(file_path)
|
66
|
+
return true unless expect_matching_definition?
|
67
|
+
|
68
|
+
find_class_or_module(processed_source.ast, to_namespace(file_path))
|
69
|
+
end
|
70
|
+
|
71
|
+
def bad_filename_allowed?
|
72
|
+
ignore_executable_scripts? && processed_source.start_with?('#!')
|
73
|
+
end
|
74
|
+
|
68
75
|
def no_definition_message(basename, file_path)
|
69
76
|
format(MSG_NO_DEFINITION,
|
70
77
|
basename: basename,
|
data/lib/rubocop/cop/registry.rb
CHANGED
@@ -122,7 +122,7 @@ module RuboCop
|
|
122
122
|
def unqualified_cop_names
|
123
123
|
@unqualified_cop_names ||=
|
124
124
|
Set.new(@cops_by_cop_name.keys.map { |qn| File.basename(qn) }) <<
|
125
|
-
'
|
125
|
+
'RedundantCopDisableDirective'
|
126
126
|
end
|
127
127
|
|
128
128
|
# @return [Hash{String => Array<Class>}]
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
node_expr = node.source_range
|
32
32
|
attr_expr = attr_name.source_range
|
33
33
|
|
34
|
-
if setter
|
34
|
+
if setter&.boolean_type?
|
35
35
|
remove = range_between(attr_expr.end_pos, node_expr.end_pos)
|
36
36
|
end
|
37
37
|
|
@@ -50,7 +50,7 @@ module RuboCop
|
|
50
50
|
def replacement_method(node)
|
51
51
|
setter = node.last_argument
|
52
52
|
|
53
|
-
if setter
|
53
|
+
if setter&.boolean_type?
|
54
54
|
setter.true_type? ? 'attr_accessor' : 'attr_reader'
|
55
55
|
else
|
56
56
|
'attr_reader'
|