rubocop 1.72.1 → 1.73.1
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 +3 -3
- data/config/default.yml +26 -11
- data/config/internal_affairs.yml +16 -0
- data/lib/rubocop/config_loader_resolver.rb +2 -2
- data/lib/rubocop/config_validator.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/example_description.rb +4 -2
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +4 -4
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +26 -1
- data/lib/rubocop/cop/layout/line_length.rb +3 -3
- data/lib/rubocop/cop/lint/duplicate_methods.rb +0 -14
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +10 -5
- data/lib/rubocop/cop/lint/float_comparison.rb +1 -6
- data/lib/rubocop/cop/lint/literal_as_condition.rb +99 -9
- data/lib/rubocop/cop/lint/mixed_case_range.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +0 -21
- data/lib/rubocop/cop/lint/redundant_type_conversion.rb +23 -2
- data/lib/rubocop/cop/lint/useless_constant_scoping.rb +7 -1
- data/lib/rubocop/cop/lint/void.rb +6 -0
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +4 -4
- data/lib/rubocop/cop/mixin/hash_subset.rb +19 -4
- data/lib/rubocop/cop/mixin/trailing_comma.rb +12 -0
- data/lib/rubocop/cop/naming/block_forwarding.rb +3 -3
- data/lib/rubocop/cop/naming/variable_name.rb +64 -6
- data/lib/rubocop/cop/style/accessor_grouping.rb +19 -5
- data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -3
- data/lib/rubocop/cop/style/commented_keyword.rb +1 -1
- data/lib/rubocop/cop/style/endless_method.rb +163 -18
- data/lib/rubocop/cop/style/line_end_concatenation.rb +10 -4
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +46 -0
- data/lib/rubocop/cop/style/redundant_format.rb +39 -11
- data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +3 -3
- data/lib/rubocop/cop/style/string_concatenation.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +47 -6
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +48 -6
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cops_documentation_generator.rb +12 -1
- data/lib/rubocop/plugin/configuration_integrator.rb +2 -0
- data/lib/rubocop/plugin/load_error.rb +1 -1
- data/lib/rubocop/plugin.rb +9 -2
- data/lib/rubocop/rspec/cop_helper.rb +2 -0
- data/lib/rubocop/rspec/shared_contexts.rb +15 -0
- data/lib/rubocop/rspec/support.rb +1 -0
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +0 -1
- metadata +4 -5
- data/lib/rubocop/cop/utils/regexp_ranges.rb +0 -113
@@ -36,7 +36,7 @@ module RuboCop
|
|
36
36
|
include RangeHelp
|
37
37
|
extend AutoCorrector
|
38
38
|
|
39
|
-
MSG = 'Use `\\` instead of
|
39
|
+
MSG = 'Use `\\` instead of `%<operator>s` to concatenate multiline strings.'
|
40
40
|
CONCAT_TOKEN_TYPES = %i[tPLUS tLSHFT].freeze
|
41
41
|
SIMPLE_STRING_TOKEN_TYPE = :tSTRING
|
42
42
|
COMPLEX_STRING_BEGIN_TOKEN = :tSTRING_BEG
|
@@ -61,14 +61,20 @@ module RuboCop
|
|
61
61
|
successor = tokens[index + 2]
|
62
62
|
|
63
63
|
return unless eligible_token_set?(predecessor, operator, successor)
|
64
|
-
|
65
64
|
return if same_line?(operator, successor)
|
66
65
|
|
67
66
|
next_successor = token_after_last_string(successor, index)
|
68
|
-
|
69
67
|
return unless eligible_next_successor?(next_successor)
|
70
68
|
|
71
|
-
|
69
|
+
register_offense(operator)
|
70
|
+
end
|
71
|
+
|
72
|
+
def register_offense(operator)
|
73
|
+
message = format(MSG, operator: operator.text)
|
74
|
+
|
75
|
+
add_offense(operator.pos, message: message) do |corrector|
|
76
|
+
autocorrect(corrector, operator.pos)
|
77
|
+
end
|
72
78
|
end
|
73
79
|
|
74
80
|
def autocorrect(corrector, operator_range)
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
return if ignored_node?(node)
|
42
42
|
|
43
43
|
return unless (receiver = node.receiver)
|
44
|
-
return unless receiver.any_block_type? && receiver.
|
44
|
+
return unless receiver.any_block_type? && receiver.keywords?
|
45
45
|
|
46
46
|
range = range_between(receiver.loc.end.begin_pos, node.source_range.end_pos)
|
47
47
|
|
@@ -42,7 +42,28 @@ module RuboCop
|
|
42
42
|
# c
|
43
43
|
# end
|
44
44
|
#
|
45
|
+
# # bad
|
46
|
+
# a.nil? ? true : a
|
47
|
+
#
|
48
|
+
# # good
|
49
|
+
# a.nil? || a
|
50
|
+
#
|
51
|
+
# # bad
|
52
|
+
# if a.nil?
|
53
|
+
# true
|
54
|
+
# else
|
55
|
+
# a
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# # good
|
59
|
+
# a.nil? || a
|
60
|
+
#
|
61
|
+
# @example AllowedMethods: ['nonzero?'] (default)
|
62
|
+
# # good
|
63
|
+
# num.nonzero? ? true : false
|
64
|
+
#
|
45
65
|
class RedundantCondition < Base
|
66
|
+
include AllowedMethods
|
46
67
|
include CommentsHelp
|
47
68
|
include RangeHelp
|
48
69
|
extend AutoCorrector
|
@@ -128,6 +149,16 @@ module RuboCop
|
|
128
149
|
# end
|
129
150
|
return true if condition == if_branch
|
130
151
|
|
152
|
+
# e.g.
|
153
|
+
# a.nil? ? true : a
|
154
|
+
# or
|
155
|
+
# if a.nil?
|
156
|
+
# true
|
157
|
+
# else
|
158
|
+
# a
|
159
|
+
# end
|
160
|
+
return true if if_branch_is_true_type_and_else_is_not?(node)
|
161
|
+
|
131
162
|
# e.g.
|
132
163
|
# if foo
|
133
164
|
# @value = foo
|
@@ -146,6 +177,19 @@ module RuboCop
|
|
146
177
|
!use_hash_key_access?(if_branch)
|
147
178
|
end
|
148
179
|
|
180
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
181
|
+
def if_branch_is_true_type_and_else_is_not?(node)
|
182
|
+
return false unless node.ternary? || node.if?
|
183
|
+
|
184
|
+
cond = node.condition
|
185
|
+
if cond.call_type? && (!cond.predicate_method? || allowed_method?(cond.method_name))
|
186
|
+
return false
|
187
|
+
end
|
188
|
+
|
189
|
+
node.if_branch&.true_type? && node.else_branch && !node.else_branch.true_type?
|
190
|
+
end
|
191
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
192
|
+
|
149
193
|
def branches_have_assignment?(node)
|
150
194
|
_condition, if_branch, else_branch = *node # rubocop:disable InternalAffairs/NodeDestructuring
|
151
195
|
|
@@ -194,6 +238,8 @@ module RuboCop
|
|
194
238
|
argument_source = if_branch.first_argument.source
|
195
239
|
|
196
240
|
"#{if_branch.receiver.source} #{if_branch.method_name} (#{argument_source}"
|
241
|
+
elsif if_branch.true_type?
|
242
|
+
if_branch.parent.condition.source
|
197
243
|
else
|
198
244
|
if_branch.source
|
199
245
|
end
|
@@ -12,6 +12,22 @@ module RuboCop
|
|
12
12
|
# inlined into a string easily. This applies to the `%s`, `%d`, `%i`, `%u`, and
|
13
13
|
# `%f` format specifiers.
|
14
14
|
#
|
15
|
+
# @safety
|
16
|
+
# This cop's autocorrection is unsafe because string object returned by
|
17
|
+
# `format` and `sprintf` are never frozen. If `format('string')` is autocorrected to
|
18
|
+
# `'string'`, `FrozenError` may occur when calling a destructive method like `String#<<`.
|
19
|
+
# Consider using `'string'.dup` instead of `format('string')`.
|
20
|
+
# Additionally, since the necessity of `dup` cannot be determined automatically,
|
21
|
+
# this autocorrection is inherently unsafe.
|
22
|
+
#
|
23
|
+
# [source,ruby]
|
24
|
+
# ----
|
25
|
+
# # frozen_string_literal: true
|
26
|
+
#
|
27
|
+
# format('template').frozen? # => false
|
28
|
+
# 'template'.frozen? # => true
|
29
|
+
# ----
|
30
|
+
#
|
15
31
|
# @example
|
16
32
|
#
|
17
33
|
# # bad
|
@@ -31,7 +47,7 @@ module RuboCop
|
|
31
47
|
class RedundantFormat < Base
|
32
48
|
extend AutoCorrector
|
33
49
|
|
34
|
-
MSG = '
|
50
|
+
MSG = 'Use `%<prefer>s` directly instead of `%<method_name>s`.'
|
35
51
|
|
36
52
|
RESTRICT_ON_SEND = %i[format sprintf].to_set.freeze
|
37
53
|
ACCEPTABLE_LITERAL_TYPES = %i[str dstr sym dsym numeric boolean nil].freeze
|
@@ -56,10 +72,20 @@ module RuboCop
|
|
56
72
|
(pair (sym %1) $_)
|
57
73
|
PATTERN
|
58
74
|
|
75
|
+
# @!method splatted_arguments?(node)
|
76
|
+
def_node_matcher :splatted_arguments?, <<~PATTERN
|
77
|
+
(send _ %RESTRICT_ON_SEND <{
|
78
|
+
splat
|
79
|
+
(hash <kwsplat ...>)
|
80
|
+
} ...>)
|
81
|
+
PATTERN
|
82
|
+
|
59
83
|
def on_send(node)
|
60
84
|
format_without_additional_args?(node) do |value|
|
61
|
-
|
62
|
-
|
85
|
+
replacement = value.source
|
86
|
+
|
87
|
+
add_offense(node, message: message(node, replacement)) do |corrector|
|
88
|
+
corrector.replace(node, replacement)
|
63
89
|
end
|
64
90
|
return
|
65
91
|
end
|
@@ -69,8 +95,8 @@ module RuboCop
|
|
69
95
|
|
70
96
|
private
|
71
97
|
|
72
|
-
def message(node)
|
73
|
-
format(MSG, method_name: node.method_name)
|
98
|
+
def message(node, prefer)
|
99
|
+
format(MSG, prefer: prefer, method_name: node.method_name)
|
74
100
|
end
|
75
101
|
|
76
102
|
def detect_unnecessary_fields(node)
|
@@ -80,7 +106,7 @@ module RuboCop
|
|
80
106
|
arguments = node.arguments[1..]
|
81
107
|
|
82
108
|
return unless string && arguments.any?
|
83
|
-
return if
|
109
|
+
return if splatted_arguments?(node)
|
84
110
|
|
85
111
|
register_all_fields_literal(node, string, arguments)
|
86
112
|
end
|
@@ -88,9 +114,11 @@ module RuboCop
|
|
88
114
|
def register_all_fields_literal(node, string, arguments)
|
89
115
|
return unless all_fields_literal?(string, arguments.dup)
|
90
116
|
|
91
|
-
|
92
|
-
|
93
|
-
|
117
|
+
formatted_string = format(string, *argument_values(arguments))
|
118
|
+
replacement = quote(formatted_string, node)
|
119
|
+
|
120
|
+
add_offense(node, message: message(node, replacement)) do |corrector|
|
121
|
+
corrector.replace(node, replacement)
|
94
122
|
end
|
95
123
|
end
|
96
124
|
|
@@ -103,7 +131,7 @@ module RuboCop
|
|
103
131
|
next if sequence.percent?
|
104
132
|
|
105
133
|
hash = arguments.detect(&:hash_type?)
|
106
|
-
argument = find_argument(sequence, arguments, hash)
|
134
|
+
next unless (argument = find_argument(sequence, arguments, hash))
|
107
135
|
next unless matching_argument?(sequence, argument)
|
108
136
|
|
109
137
|
count += 1
|
@@ -113,7 +141,7 @@ module RuboCop
|
|
113
141
|
end
|
114
142
|
|
115
143
|
def find_argument(sequence, arguments, hash)
|
116
|
-
if sequence.annotated? || sequence.template?
|
144
|
+
if hash && (sequence.annotated? || sequence.template?)
|
117
145
|
find_hash_value_node(hash, sequence.name.to_sym).first
|
118
146
|
elsif sequence.arg_number
|
119
147
|
arguments[sequence.arg_number.to_i - 1]
|
@@ -13,8 +13,7 @@ module RuboCop
|
|
13
13
|
# # good
|
14
14
|
# x if y.z.nil?
|
15
15
|
#
|
16
|
-
# rubocop:disable Metrics/ClassLength
|
17
|
-
class RedundantParentheses < Base
|
16
|
+
class RedundantParentheses < Base # rubocop:disable Metrics/ClassLength
|
18
17
|
include Parentheses
|
19
18
|
extend AutoCorrector
|
20
19
|
|
@@ -299,7 +298,6 @@ module RuboCop
|
|
299
298
|
block.keywords? && begin_node.each_ancestor(:call).any?
|
300
299
|
end
|
301
300
|
end
|
302
|
-
# rubocop:enable Metrics/ClassLength
|
303
301
|
end
|
304
302
|
end
|
305
303
|
end
|
@@ -58,7 +58,7 @@ module RuboCop
|
|
58
58
|
# rubocop:disable Metrics/AbcSize
|
59
59
|
def on_lvasgn(node)
|
60
60
|
return unless (rhs = node.rhs)
|
61
|
-
return unless rhs.
|
61
|
+
return unless rhs.type?(:any_block, :call) && method_returning_self?(rhs.method_name)
|
62
62
|
return unless (receiver = rhs.receiver)
|
63
63
|
|
64
64
|
receiver_type = ASSIGNMENT_TYPE_TO_RECEIVER_TYPE[node.type]
|
@@ -8,9 +8,9 @@ module RuboCop
|
|
8
8
|
#
|
9
9
|
# Endless methods added in Ruby 3.0 are also accepted by this cop.
|
10
10
|
#
|
11
|
-
# If `Style/EndlessMethod` is enabled with `EnforcedStyle: allow_single_line`
|
12
|
-
# `
|
13
|
-
# methods if there is only one statement in the body.
|
11
|
+
# If `Style/EndlessMethod` is enabled with `EnforcedStyle: allow_single_line`, `allow_always`,
|
12
|
+
# `require_single_line`, or `require_always`, single-line methods will be autocorrected
|
13
|
+
# to endless methods if there is only one statement in the body.
|
14
14
|
#
|
15
15
|
# @example
|
16
16
|
# # bad
|
@@ -6,12 +6,13 @@ module RuboCop
|
|
6
6
|
# Checks for trailing comma in array literals.
|
7
7
|
# The configuration options are:
|
8
8
|
#
|
9
|
-
# * `consistent_comma`: Requires a comma after the
|
10
|
-
#
|
11
|
-
# * `comma`: Requires a comma after last item in an array,
|
12
|
-
#
|
13
|
-
# * `
|
14
|
-
#
|
9
|
+
# * `consistent_comma`: Requires a comma after the last item of all non-empty, multiline array
|
10
|
+
# literals.
|
11
|
+
# * `comma`: Requires a comma after the last item in an array, but only when each item is on
|
12
|
+
# its own line.
|
13
|
+
# * `diff_comma`: Requires a comma after the last item in an array, but only when that item is
|
14
|
+
# followed by an immediate newline.
|
15
|
+
# * `no_comma`: Does not require a comma after the last item in an array
|
15
16
|
#
|
16
17
|
# @example EnforcedStyleForMultiline: consistent_comma
|
17
18
|
# # bad
|
@@ -37,6 +38,14 @@ module RuboCop
|
|
37
38
|
# 2,
|
38
39
|
# ]
|
39
40
|
#
|
41
|
+
# # bad
|
42
|
+
# a = [1, 2,
|
43
|
+
# 3, 4]
|
44
|
+
#
|
45
|
+
# # good
|
46
|
+
# a = [1, 2,
|
47
|
+
# 3, 4,]
|
48
|
+
#
|
40
49
|
# @example EnforcedStyleForMultiline: comma
|
41
50
|
# # bad
|
42
51
|
# a = [1, 2,]
|
@@ -72,6 +81,38 @@ module RuboCop
|
|
72
81
|
# 2,
|
73
82
|
# ]
|
74
83
|
#
|
84
|
+
# @example EnforcedStyleForMultiline: diff_comma
|
85
|
+
# # bad
|
86
|
+
# a = [1, 2,]
|
87
|
+
#
|
88
|
+
# # good
|
89
|
+
# a = [1, 2]
|
90
|
+
#
|
91
|
+
# # good
|
92
|
+
# a = [
|
93
|
+
# 1, 2,
|
94
|
+
# 3,
|
95
|
+
# ]
|
96
|
+
#
|
97
|
+
# # good
|
98
|
+
# a = [
|
99
|
+
# 1, 2, 3,
|
100
|
+
# ]
|
101
|
+
#
|
102
|
+
# # good
|
103
|
+
# a = [
|
104
|
+
# 1,
|
105
|
+
# 2,
|
106
|
+
# ]
|
107
|
+
#
|
108
|
+
# # bad
|
109
|
+
# a = [1, 2,
|
110
|
+
# 3, 4,]
|
111
|
+
#
|
112
|
+
# # good
|
113
|
+
# a = [1, 2,
|
114
|
+
# 3, 4]
|
115
|
+
#
|
75
116
|
# @example EnforcedStyleForMultiline: no_comma (default)
|
76
117
|
# # bad
|
77
118
|
# a = [1, 2,]
|
@@ -6,12 +6,13 @@ module RuboCop
|
|
6
6
|
# Checks for trailing comma in hash literals.
|
7
7
|
# The configuration options are:
|
8
8
|
#
|
9
|
-
# * `consistent_comma`: Requires a comma after the
|
10
|
-
#
|
11
|
-
# * `comma`: Requires a comma after the last item in a hash,
|
12
|
-
#
|
13
|
-
# * `
|
14
|
-
#
|
9
|
+
# * `consistent_comma`: Requires a comma after the last item of all non-empty, multiline hash
|
10
|
+
# literals.
|
11
|
+
# * `comma`: Requires a comma after the last item in a hash, but only when each item is on its
|
12
|
+
# own line.
|
13
|
+
# * `diff_comma`: Requires a comma after the last item in a hash, but only when that item is
|
14
|
+
# followed by an immediate newline.
|
15
|
+
# * `no_comma`: Does not require a comma after the last item in a hash
|
15
16
|
#
|
16
17
|
# @example EnforcedStyleForMultiline: consistent_comma
|
17
18
|
#
|
@@ -38,6 +39,14 @@ module RuboCop
|
|
38
39
|
# bar: 2,
|
39
40
|
# }
|
40
41
|
#
|
42
|
+
# # bad
|
43
|
+
# a = { foo: 1, bar: 2,
|
44
|
+
# baz: 3, qux: 4 }
|
45
|
+
#
|
46
|
+
# # good
|
47
|
+
# a = { foo: 1, bar: 2,
|
48
|
+
# baz: 3, qux: 4, }
|
49
|
+
#
|
41
50
|
# @example EnforcedStyleForMultiline: comma
|
42
51
|
#
|
43
52
|
# # bad
|
@@ -74,6 +83,39 @@ module RuboCop
|
|
74
83
|
# bar: 2,
|
75
84
|
# }
|
76
85
|
#
|
86
|
+
# @example EnforcedStyleForMultiline: diff_comma
|
87
|
+
#
|
88
|
+
# # bad
|
89
|
+
# a = { foo: 1, bar: 2, }
|
90
|
+
#
|
91
|
+
# # good
|
92
|
+
# a = { foo: 1, bar: 2 }
|
93
|
+
#
|
94
|
+
# # good
|
95
|
+
# a = {
|
96
|
+
# foo: 1, bar: 2,
|
97
|
+
# qux: 3,
|
98
|
+
# }
|
99
|
+
#
|
100
|
+
# # good
|
101
|
+
# a = {
|
102
|
+
# foo: 1, bar: 2, qux: 3,
|
103
|
+
# }
|
104
|
+
#
|
105
|
+
# # good
|
106
|
+
# a = {
|
107
|
+
# foo: 1,
|
108
|
+
# bar: 2,
|
109
|
+
# }
|
110
|
+
#
|
111
|
+
# # bad
|
112
|
+
# a = { foo: 1, bar: 2,
|
113
|
+
# baz: 3, qux: 4, }
|
114
|
+
#
|
115
|
+
# # good
|
116
|
+
# a = { foo: 1, bar: 2,
|
117
|
+
# baz: 3, qux: 4 }
|
118
|
+
#
|
77
119
|
# @example EnforcedStyleForMultiline: no_comma (default)
|
78
120
|
#
|
79
121
|
# # bad
|
@@ -113,7 +113,7 @@ module RuboCop
|
|
113
113
|
private
|
114
114
|
|
115
115
|
def in_module_or_instance_eval?(node)
|
116
|
-
node.each_ancestor(:
|
116
|
+
node.each_ancestor(:any_block, :class, :sclass, :module).each do |pnode|
|
117
117
|
case pnode.type
|
118
118
|
when :class, :sclass
|
119
119
|
return false
|
@@ -28,6 +28,12 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
28
28
|
#
|
29
29
|
# CopsDocumentationGenerator.new(departments: ['Lint']).call
|
30
30
|
#
|
31
|
+
# For plugin extensions, specify `:plugin_name` keyword as follows:
|
32
|
+
#
|
33
|
+
# CopsDocumentationGenerator.new(
|
34
|
+
# departments: ['Performance'], plugin_name: 'rubocop-performance'
|
35
|
+
# ).call
|
36
|
+
#
|
31
37
|
# You can append additional information:
|
32
38
|
#
|
33
39
|
# callback = ->(data) { required_rails_version(data.cop) }
|
@@ -36,11 +42,16 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
36
42
|
# This will insert the string returned from the lambda _after_ the section from RuboCop itself.
|
37
43
|
# See `CopsDocumentationGenerator::STRUCTURE` for available sections.
|
38
44
|
#
|
39
|
-
def initialize(departments: [], extra_info: {}, base_dir: Dir.pwd)
|
45
|
+
def initialize(departments: [], extra_info: {}, base_dir: Dir.pwd, plugin_name: nil)
|
40
46
|
@departments = departments.map(&:to_sym).sort!
|
41
47
|
@extra_info = extra_info
|
42
48
|
@cops = RuboCop::Cop::Registry.global
|
43
49
|
@config = RuboCop::ConfigLoader.default_configuration
|
50
|
+
# NOTE: For example, this prevents excessive plugin loading before another task executes,
|
51
|
+
# in cases where plugins are already loaded by `internal_investigation`.
|
52
|
+
if plugin_name && @config.loaded_plugins.none? { |plugin| plugin.about.name == plugin_name }
|
53
|
+
RuboCop::Plugin.integrate_plugins(RuboCop::Config.new, [plugin_name])
|
54
|
+
end
|
44
55
|
@base_dir = base_dir
|
45
56
|
@docs_path = "#{base_dir}/docs/modules/ROOT"
|
46
57
|
FileUtils.mkdir_p("#{@docs_path}/pages")
|
@@ -15,7 +15,7 @@ module RuboCop
|
|
15
15
|
<<~MESSAGE
|
16
16
|
Failed to load plugin `#{@plugin_name}` because the corresponding plugin class could not be determined for instantiation.
|
17
17
|
Try upgrading it first (e.g., `bundle update #{@plugin_name}`).
|
18
|
-
If `#{@plugin_name}` is not yet a plugin, use `require: #{@plugin_name}` instead of `plugins:
|
18
|
+
If `#{@plugin_name}` is not yet a plugin, use `require: #{@plugin_name}` instead of `plugins: #{@plugin_name}` in your configuration.
|
19
19
|
|
20
20
|
For further assistance, check with the developer regarding the following points:
|
21
21
|
https://docs.rubocop.org/rubocop/plugin_migration_guide.html
|
data/lib/rubocop/plugin.rb
CHANGED
@@ -22,9 +22,16 @@ module RuboCop
|
|
22
22
|
def plugin_capable?(feature_name)
|
23
23
|
return true if BUILTIN_INTERNAL_PLUGINS.key?(feature_name)
|
24
24
|
return true if feature_name == OBSOLETE_INTERNAL_AFFAIRS_PLUGIN_NAME
|
25
|
-
return false unless (gem = Gem.loaded_specs[feature_name])
|
26
25
|
|
27
|
-
|
26
|
+
begin
|
27
|
+
# When not using Bundler. Makes the spec available but does not require it.
|
28
|
+
gem feature_name
|
29
|
+
rescue Gem::LoadError
|
30
|
+
# The user requested a gem that they do not have installed
|
31
|
+
end
|
32
|
+
return false unless (spec = Gem.loaded_specs[feature_name])
|
33
|
+
|
34
|
+
!!spec.metadata['default_lint_roller_plugin']
|
28
35
|
end
|
29
36
|
|
30
37
|
def integrate_plugins(rubocop_config, plugins)
|
@@ -14,6 +14,8 @@ module CopHelper
|
|
14
14
|
let(:rails_version) { false }
|
15
15
|
|
16
16
|
before(:all) do
|
17
|
+
next if ENV['RUBOCOP_CORE_DEVELOPMENT']
|
18
|
+
|
17
19
|
plugins = Gem.loaded_specs.filter_map do |feature_name, feature_specification|
|
18
20
|
feature_name if feature_specification.metadata['default_lint_roller_plugin']
|
19
21
|
end
|
@@ -80,6 +80,21 @@ RSpec.shared_context 'maintain registry' do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
RSpec.shared_context 'maintain default configuration' do
|
84
|
+
around(:each) do |example|
|
85
|
+
# Make a copy of the current configuration that will not change when source hash changes
|
86
|
+
default_configuration = RuboCop::ConfigLoader.default_configuration
|
87
|
+
config = RuboCop::Config.create(
|
88
|
+
default_configuration.to_h.clone,
|
89
|
+
default_configuration.loaded_path
|
90
|
+
)
|
91
|
+
|
92
|
+
example.run
|
93
|
+
|
94
|
+
RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
83
98
|
# This context assumes nothing and defines `cop`, among others.
|
84
99
|
RSpec.shared_context 'config' do # rubocop:disable Metrics/BlockLength
|
85
100
|
### Meant to be overridden at will
|
@@ -15,6 +15,7 @@ RSpec.configure do |config|
|
|
15
15
|
config.include_context 'isolated bundler', :isolated_bundler
|
16
16
|
config.include_context 'lsp', :lsp
|
17
17
|
config.include_context 'maintain registry', :restore_registry
|
18
|
+
config.include_context 'maintain default configuration', :restore_configuration
|
18
19
|
config.include_context 'ruby 2.0', :ruby20
|
19
20
|
config.include_context 'ruby 2.1', :ruby21
|
20
21
|
config.include_context 'ruby 2.2', :ruby22
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
@@ -148,7 +148,6 @@ require_relative 'rubocop/cop/mixin/comments_help' # relies on visibility_help
|
|
148
148
|
require_relative 'rubocop/cop/mixin/def_node' # relies on visibility_help
|
149
149
|
|
150
150
|
require_relative 'rubocop/cop/utils/format_string'
|
151
|
-
require_relative 'rubocop/cop/utils/regexp_ranges'
|
152
151
|
|
153
152
|
require_relative 'rubocop/cop/migration/department_name'
|
154
153
|
|
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: 1.
|
4
|
+
version: 1.73.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
- Yuji Nakayama
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-02-
|
12
|
+
date: 2025-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -971,7 +971,6 @@ files:
|
|
971
971
|
- lib/rubocop/cop/team.rb
|
972
972
|
- lib/rubocop/cop/util.rb
|
973
973
|
- lib/rubocop/cop/utils/format_string.rb
|
974
|
-
- lib/rubocop/cop/utils/regexp_ranges.rb
|
975
974
|
- lib/rubocop/cop/variable_force.rb
|
976
975
|
- lib/rubocop/cop/variable_force/assignment.rb
|
977
976
|
- lib/rubocop/cop/variable_force/branch.rb
|
@@ -1075,9 +1074,9 @@ licenses:
|
|
1075
1074
|
- MIT
|
1076
1075
|
metadata:
|
1077
1076
|
homepage_uri: https://rubocop.org/
|
1078
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.
|
1077
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.73.1
|
1079
1078
|
source_code_uri: https://github.com/rubocop/rubocop/
|
1080
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
1079
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.73/
|
1081
1080
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|
1082
1081
|
rubygems_mfa_required: 'true'
|
1083
1082
|
rdoc_options: []
|