rubocop-rspec 3.3.0 → 3.6.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/CHANGELOG.md +26 -2
- data/README.md +7 -4
- data/config/default.yml +7 -12
- data/config/obsoletion.yml +5 -0
- data/lib/rubocop/cop/rspec/be_eq.rb +1 -1
- data/lib/rubocop/cop/rspec/be_eql.rb +1 -1
- data/lib/rubocop/cop/rspec/be_nil.rb +4 -0
- data/lib/rubocop/cop/rspec/change_by_zero.rb +3 -4
- data/lib/rubocop/cop/rspec/contain_exactly.rb +1 -0
- data/lib/rubocop/cop/rspec/context_wording.rb +6 -1
- data/lib/rubocop/cop/rspec/described_class.rb +4 -2
- data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_example_group.rb +6 -4
- data/lib/rubocop/cop/rspec/example_wording.rb +1 -3
- data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +1 -1
- data/lib/rubocop/cop/rspec/expect_actual.rb +1 -1
- data/lib/rubocop/cop/rspec/expect_change.rb +21 -2
- data/lib/rubocop/cop/rspec/focus.rb +15 -17
- data/lib/rubocop/cop/rspec/hook_argument.rb +2 -2
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +1 -1
- data/lib/rubocop/cop/rspec/implicit_expect.rb +3 -3
- data/lib/rubocop/cop/rspec/implicit_subject.rb +8 -0
- data/lib/rubocop/cop/rspec/include_examples.rb +39 -0
- data/lib/rubocop/cop/rspec/indexed_let.rb +2 -0
- data/lib/rubocop/cop/rspec/match_array.rb +1 -0
- data/lib/rubocop/cop/rspec/message_spies.rb +4 -0
- data/lib/rubocop/cop/rspec/mixin/metadata.rb +5 -8
- data/lib/rubocop/cop/rspec/nested_groups.rb +2 -2
- data/lib/rubocop/cop/rspec/no_expectation_example.rb +1 -1
- data/lib/rubocop/cop/rspec/pending.rb +1 -1
- data/lib/rubocop/cop/rspec/pending_without_reason.rb +2 -8
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +18 -8
- data/lib/rubocop/cop/rspec/receive_messages.rb +1 -2
- data/lib/rubocop/cop/rspec/redundant_around.rb +1 -1
- data/lib/rubocop/cop/rspec/return_from_stub.rb +5 -4
- data/lib/rubocop/cop/rspec/scattered_setup.rb +10 -2
- data/lib/rubocop/cop/rspec/sort_metadata.rb +22 -8
- data/lib/rubocop/cop/rspec/variable_definition.rb +1 -1
- data/lib/rubocop/cop/rspec/variable_name.rb +1 -1
- data/lib/rubocop/cop/rspec/verified_double_reference.rb +14 -53
- data/lib/rubocop/cop/rspec_cops.rb +1 -1
- data/lib/rubocop/rspec/config_formatter.rb +4 -9
- data/lib/rubocop/rspec/description_extractor.rb +2 -2
- data/lib/rubocop/rspec/hook.rb +3 -1
- data/lib/rubocop/rspec/language.rb +3 -6
- data/lib/rubocop/rspec/plugin.rb +37 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- data/lib/rubocop/rspec/wording.rb +0 -2
- data/lib/rubocop/rspec.rb +0 -7
- data/lib/rubocop-rspec.rb +1 -3
- metadata +28 -10
- data/lib/rubocop/cop/rspec/string_as_instance_double_constant.rb +0 -45
- data/lib/rubocop/rspec/inject.rb +0 -18
@@ -63,8 +63,7 @@ module RuboCop
|
|
63
63
|
def_node_matcher :skipped_in_example?, <<~PATTERN
|
64
64
|
{
|
65
65
|
(send nil? ${#Examples.skipped #Examples.pending})
|
66
|
-
(
|
67
|
-
(numblock (send nil? ${#Examples.skipped}) ...)
|
66
|
+
(any_block (send nil? ${#Examples.skipped}) ...)
|
68
67
|
}
|
69
68
|
PATTERN
|
70
69
|
|
@@ -75,7 +74,7 @@ module RuboCop
|
|
75
74
|
|
76
75
|
# @!method skipped_by_example_method_with_block?(node)
|
77
76
|
def_node_matcher :skipped_by_example_method_with_block?, <<~PATTERN
|
78
|
-
(
|
77
|
+
(any_block (send nil? ${#Examples.skipped #Examples.pending} ...) ...)
|
79
78
|
PATTERN
|
80
79
|
|
81
80
|
# @!method metadata_without_reason?(node)
|
@@ -94,11 +93,6 @@ module RuboCop
|
|
94
93
|
(send #rspec? ${#ExampleGroups.skipped} ...)
|
95
94
|
PATTERN
|
96
95
|
|
97
|
-
# @!method pending_step_without_reason?(node)
|
98
|
-
def_node_matcher :pending_step_without_reason?, <<~PATTERN
|
99
|
-
(send nil? {:skip :pending})
|
100
|
-
PATTERN
|
101
|
-
|
102
96
|
def on_send(node)
|
103
97
|
on_pending_by_metadata(node)
|
104
98
|
return unless (parent = parent_node(node))
|
@@ -15,6 +15,8 @@ module RuboCop
|
|
15
15
|
|
16
16
|
def check_inflected(node)
|
17
17
|
predicate_in_actual?(node) do |predicate, to, matcher|
|
18
|
+
next if cannot_replace_predicate?(predicate)
|
19
|
+
|
18
20
|
msg = message_inflected(predicate)
|
19
21
|
add_offense(node, message: msg) do |corrector|
|
20
22
|
remove_predicate(corrector, predicate)
|
@@ -35,9 +37,13 @@ module RuboCop
|
|
35
37
|
$#boolean_matcher? ...)
|
36
38
|
PATTERN
|
37
39
|
|
40
|
+
def cannot_replace_predicate?(send_node)
|
41
|
+
send_node.method?(:respond_to?) && send_node.arguments.length > 1
|
42
|
+
end
|
43
|
+
|
38
44
|
# @!method be_bool?(node)
|
39
45
|
def_node_matcher :be_bool?, <<~PATTERN
|
40
|
-
(send nil? {:be :eq :eql :equal}
|
46
|
+
(send nil? {:be :eq :eql :equal} boolean)
|
41
47
|
PATTERN
|
42
48
|
|
43
49
|
# @!method be_boolthy?(node)
|
@@ -63,7 +69,6 @@ module RuboCop
|
|
63
69
|
matcher_name: to_predicate_matcher(predicate.method_name))
|
64
70
|
end
|
65
71
|
|
66
|
-
# rubocop:disable Metrics/MethodLength
|
67
72
|
def to_predicate_matcher(name)
|
68
73
|
case name = name.to_s
|
69
74
|
when 'is_a?'
|
@@ -80,7 +85,6 @@ module RuboCop
|
|
80
85
|
"be_#{name[0..-2]}"
|
81
86
|
end
|
82
87
|
end
|
83
|
-
# rubocop:enable Metrics/MethodLength
|
84
88
|
|
85
89
|
def remove_predicate(corrector, predicate)
|
86
90
|
range = predicate.loc.dot.with(
|
@@ -106,12 +110,16 @@ module RuboCop
|
|
106
110
|
|
107
111
|
def true?(to_symbol, matcher)
|
108
112
|
result = case matcher.method_name
|
109
|
-
when :be, :eq
|
113
|
+
when :be, :eq, :eql, :equal
|
110
114
|
matcher.first_argument.true_type?
|
111
115
|
when :be_truthy, :a_truthy_value
|
112
116
|
true
|
113
117
|
when :be_falsey, :be_falsy, :a_falsey_value, :a_falsy_value
|
114
118
|
false
|
119
|
+
else
|
120
|
+
# :nocov:
|
121
|
+
:noop
|
122
|
+
# :nocov:
|
115
123
|
end
|
116
124
|
to_symbol == :to ? result : !result
|
117
125
|
end
|
@@ -174,7 +182,7 @@ module RuboCop
|
|
174
182
|
|
175
183
|
def heredoc_argument?(matcher)
|
176
184
|
matcher.arguments.select do |arg|
|
177
|
-
arg.
|
185
|
+
arg.type?(:str, :dstr, :xstr)
|
178
186
|
end.any?(&:heredoc?)
|
179
187
|
end
|
180
188
|
|
@@ -233,7 +241,6 @@ module RuboCop
|
|
233
241
|
corrector.insert_after(actual, ".#{predicate}" + args + block)
|
234
242
|
end
|
235
243
|
|
236
|
-
# rubocop:disable Metrics/MethodLength
|
237
244
|
def to_predicate_method(matcher)
|
238
245
|
case matcher = matcher.to_s
|
239
246
|
when 'be_a', 'be_an', 'be_a_kind_of', 'a_kind_of', 'be_kind_of'
|
@@ -250,7 +257,6 @@ module RuboCop
|
|
250
257
|
"#{matcher[/\Abe_(.+)/, 1]}?"
|
251
258
|
end
|
252
259
|
end
|
253
|
-
# rubocop:enable Metrics/MethodLength
|
254
260
|
|
255
261
|
def replacement_matcher(node)
|
256
262
|
case [cop_config['Strict'], node.method?(:to)]
|
@@ -260,7 +266,7 @@ module RuboCop
|
|
260
266
|
'be(false)'
|
261
267
|
when [false, true]
|
262
268
|
'be_truthy'
|
263
|
-
|
269
|
+
else
|
264
270
|
'be_falsey'
|
265
271
|
end
|
266
272
|
end
|
@@ -329,6 +335,10 @@ module RuboCop
|
|
329
335
|
check_inflected(node)
|
330
336
|
when :explicit
|
331
337
|
check_explicit(node)
|
338
|
+
else
|
339
|
+
# :nocov:
|
340
|
+
:noop
|
341
|
+
# :nocov:
|
332
342
|
end
|
333
343
|
end
|
334
344
|
|
@@ -148,8 +148,7 @@ module RuboCop
|
|
148
148
|
end
|
149
149
|
|
150
150
|
def heredoc_or_splat?(node)
|
151
|
-
(
|
152
|
-
node.splat_type?
|
151
|
+
(node.type?(:str, :dstr) && node.heredoc?) || node.splat_type?
|
153
152
|
end
|
154
153
|
|
155
154
|
def requires_quotes?(value)
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
|
42
42
|
# @!method match_redundant_around_hook_block?(node)
|
43
43
|
def_node_matcher :match_redundant_around_hook_block?, <<~PATTERN
|
44
|
-
(
|
44
|
+
(any_block (send _ :around ...) ... (send _ :run))
|
45
45
|
PATTERN
|
46
46
|
|
47
47
|
# @!method match_redundant_around_hook_send?(node)
|
@@ -80,10 +80,10 @@ module RuboCop
|
|
80
80
|
|
81
81
|
def check_block_body(block)
|
82
82
|
body = block.body
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
return if dynamic?(body)
|
84
|
+
|
85
|
+
add_offense(block.loc.begin, message: MSG_AND_RETURN) do |corrector|
|
86
|
+
BlockBodyCorrector.new(block).call(corrector)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -162,6 +162,7 @@ module RuboCop
|
|
162
162
|
end
|
163
163
|
|
164
164
|
NULL_BLOCK_BODY = Struct.new(:loc, :source).new(nil, 'nil')
|
165
|
+
private_constant :NULL_BLOCK_BODY
|
165
166
|
end
|
166
167
|
end
|
167
168
|
end
|
@@ -5,7 +5,9 @@ module RuboCop
|
|
5
5
|
module RSpec
|
6
6
|
# Checks for setup scattered across multiple hooks in an example group.
|
7
7
|
#
|
8
|
-
# Unify `before
|
8
|
+
# Unify `before` and `after` hooks when possible.
|
9
|
+
# However, `around` hooks are allowed to be defined multiple times,
|
10
|
+
# as unifying them would typically make the code harder to read.
|
9
11
|
#
|
10
12
|
# @example
|
11
13
|
# # bad
|
@@ -22,6 +24,12 @@ module RuboCop
|
|
22
24
|
# end
|
23
25
|
# end
|
24
26
|
#
|
27
|
+
# # good
|
28
|
+
# describe Foo do
|
29
|
+
# around { |example| before1; example.call; after1 }
|
30
|
+
# around { |example| before2; example.call; after2 }
|
31
|
+
# end
|
32
|
+
#
|
25
33
|
class ScatteredSetup < Base
|
26
34
|
include FinalEndLocation
|
27
35
|
include RangeHelp
|
@@ -48,7 +56,7 @@ module RuboCop
|
|
48
56
|
def repeated_hooks(node)
|
49
57
|
hooks = RuboCop::RSpec::ExampleGroup.new(node)
|
50
58
|
.hooks
|
51
|
-
.select
|
59
|
+
.select { |hook| hook.knowable_scope? && hook.name != :around }
|
52
60
|
.group_by { |hook| [hook.name, hook.scope, hook.metadata] }
|
53
61
|
.values
|
54
62
|
.reject(&:one?)
|
@@ -5,6 +5,8 @@ module RuboCop
|
|
5
5
|
module RSpec
|
6
6
|
# Sort RSpec metadata alphabetically.
|
7
7
|
#
|
8
|
+
# Only the trailing metadata is sorted.
|
9
|
+
#
|
8
10
|
# @example
|
9
11
|
# # bad
|
10
12
|
# describe 'Something', :b, :a
|
@@ -16,6 +18,9 @@ module RuboCop
|
|
16
18
|
# context 'Something', baz: true, foo: 'bar'
|
17
19
|
# it 'works', :a, :b, baz: true, foo: 'bar'
|
18
20
|
#
|
21
|
+
# # good, trailing metadata is sorted
|
22
|
+
# describe 'Something', 'description', :a, :b, :z
|
23
|
+
# context 'Something', :z, variable, :a, :b
|
19
24
|
class SortMetadata < Base
|
20
25
|
extend AutoCorrector
|
21
26
|
include Metadata
|
@@ -23,8 +28,14 @@ module RuboCop
|
|
23
28
|
|
24
29
|
MSG = 'Sort metadata alphabetically.'
|
25
30
|
|
26
|
-
|
31
|
+
# @!method match_ambiguous_trailing_metadata?(node)
|
32
|
+
def_node_matcher :match_ambiguous_trailing_metadata?, <<~PATTERN
|
33
|
+
(send _ _ _ ... !{hash sym str dstr xstr})
|
34
|
+
PATTERN
|
35
|
+
|
36
|
+
def on_metadata(args, hash)
|
27
37
|
pairs = hash&.pairs || []
|
38
|
+
symbols = trailing_symbols(args)
|
28
39
|
return if sorted?(symbols, pairs)
|
29
40
|
|
30
41
|
crime_scene = crime_scene(symbols, pairs)
|
@@ -35,6 +46,15 @@ module RuboCop
|
|
35
46
|
|
36
47
|
private
|
37
48
|
|
49
|
+
def trailing_symbols(args)
|
50
|
+
args = args[...-1] if last_arg_could_be_a_hash?(args)
|
51
|
+
args.reverse.take_while(&:sym_type?).reverse
|
52
|
+
end
|
53
|
+
|
54
|
+
def last_arg_could_be_a_hash?(args)
|
55
|
+
args.last && match_ambiguous_trailing_metadata?(args.last.parent)
|
56
|
+
end
|
57
|
+
|
38
58
|
def crime_scene(symbols, pairs)
|
39
59
|
metadata = symbols + pairs
|
40
60
|
|
@@ -57,13 +77,7 @@ module RuboCop
|
|
57
77
|
end
|
58
78
|
|
59
79
|
def sort_symbols(symbols)
|
60
|
-
symbols.sort_by
|
61
|
-
if symbol.str_type? || symbol.sym_type?
|
62
|
-
symbol.value.to_s.downcase
|
63
|
-
else
|
64
|
-
symbol.source.downcase
|
65
|
-
end
|
66
|
-
end
|
80
|
+
symbols.sort_by { |symbol| symbol.value.to_s.downcase }
|
67
81
|
end
|
68
82
|
end
|
69
83
|
end
|
@@ -50,7 +50,7 @@ module RuboCop
|
|
50
50
|
return unless inside_example_group?(node)
|
51
51
|
|
52
52
|
variable_definition?(node) do |variable|
|
53
|
-
return if variable.
|
53
|
+
return if variable.type?(:dstr, :dsym)
|
54
54
|
return if matches_allowed_pattern?(variable.value)
|
55
55
|
|
56
56
|
check_name(node, variable.value, variable.source_range)
|
@@ -5,14 +5,14 @@ module RuboCop
|
|
5
5
|
module RSpec
|
6
6
|
# Checks for consistent verified double reference style.
|
7
7
|
#
|
8
|
-
# Only investigates references that are one of the supported styles.
|
9
|
-
#
|
10
8
|
# @see https://rspec.info/features/3-12/rspec-mocks/verifying-doubles
|
11
9
|
#
|
12
|
-
#
|
13
|
-
#
|
10
|
+
# @safety
|
11
|
+
# This cop is unsafe because the correction requires loading the class.
|
12
|
+
# Loading before stubbing causes RSpec to only allow instance methods
|
13
|
+
# to be stubbed.
|
14
14
|
#
|
15
|
-
# @example
|
15
|
+
# @example
|
16
16
|
# # bad
|
17
17
|
# let(:foo) do
|
18
18
|
# instance_double('ClassName', method_name: 'returned_value')
|
@@ -23,18 +23,7 @@ module RuboCop
|
|
23
23
|
# instance_double(ClassName, method_name: 'returned_value')
|
24
24
|
# end
|
25
25
|
#
|
26
|
-
# @example
|
27
|
-
# # bad
|
28
|
-
# let(:foo) do
|
29
|
-
# instance_double(ClassName, method_name: 'returned_value')
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# # good
|
33
|
-
# let(:foo) do
|
34
|
-
# instance_double('ClassName', method_name: 'returned_value')
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
# @example Reference is not in the supported style list. No enforcement
|
26
|
+
# @example Reference is any dynamic variable. No enforcement
|
38
27
|
#
|
39
28
|
# # good
|
40
29
|
# let(:foo) do
|
@@ -42,9 +31,9 @@ module RuboCop
|
|
42
31
|
# end
|
43
32
|
class VerifiedDoubleReference < Base
|
44
33
|
extend AutoCorrector
|
45
|
-
include ConfigurableEnforcedStyle
|
46
34
|
|
47
|
-
MSG = 'Use a
|
35
|
+
MSG = 'Use a constant class reference for verified doubles. ' \
|
36
|
+
'String references are not verifying unless the class is loaded.'
|
48
37
|
|
49
38
|
RESTRICT_ON_SEND = Set[
|
50
39
|
:class_double,
|
@@ -57,53 +46,25 @@ module RuboCop
|
|
57
46
|
:stub_model
|
58
47
|
].freeze
|
59
48
|
|
60
|
-
REFERENCE_TYPE_STYLES = {
|
61
|
-
str: :string,
|
62
|
-
const: :constant
|
63
|
-
}.freeze
|
64
|
-
|
65
49
|
# @!method verified_double(node)
|
66
50
|
def_node_matcher :verified_double, <<~PATTERN
|
67
51
|
(send
|
68
52
|
nil?
|
69
53
|
RESTRICT_ON_SEND
|
70
|
-
$
|
54
|
+
$str
|
71
55
|
...)
|
72
56
|
PATTERN
|
73
57
|
|
74
58
|
def on_send(node)
|
75
|
-
verified_double(node) do |
|
76
|
-
|
77
|
-
|
78
|
-
message = format(MSG, style: style)
|
79
|
-
expression = class_reference.source_range
|
80
|
-
|
81
|
-
add_offense(expression, message: message) do |corrector|
|
82
|
-
offense = class_reference.source
|
83
|
-
corrector.replace(expression, correct_style(offense))
|
84
|
-
|
85
|
-
opposite_style_detected
|
59
|
+
verified_double(node) do |string_argument_node|
|
60
|
+
add_offense(string_argument_node) do |corrector|
|
61
|
+
autocorrect(corrector, string_argument_node)
|
86
62
|
end
|
87
63
|
end
|
88
64
|
end
|
89
65
|
|
90
|
-
|
91
|
-
|
92
|
-
def opposing_style?(class_reference)
|
93
|
-
class_reference_style = REFERENCE_TYPE_STYLES[class_reference.type]
|
94
|
-
|
95
|
-
# Only enforce supported styles
|
96
|
-
return false unless class_reference_style
|
97
|
-
|
98
|
-
class_reference_style != style
|
99
|
-
end
|
100
|
-
|
101
|
-
def correct_style(offense)
|
102
|
-
if style == :string
|
103
|
-
"'#{offense}'"
|
104
|
-
else
|
105
|
-
offense.gsub(/^['"]|['"]$/, '')
|
106
|
-
end
|
66
|
+
def autocorrect(corrector, node)
|
67
|
+
corrector.replace(node, node.value)
|
107
68
|
end
|
108
69
|
end
|
109
70
|
end
|
@@ -48,6 +48,7 @@ require_relative 'rspec/identical_equality_assertion'
|
|
48
48
|
require_relative 'rspec/implicit_block_expectation'
|
49
49
|
require_relative 'rspec/implicit_expect'
|
50
50
|
require_relative 'rspec/implicit_subject'
|
51
|
+
require_relative 'rspec/include_examples'
|
51
52
|
require_relative 'rspec/indexed_let'
|
52
53
|
require_relative 'rspec/instance_spy'
|
53
54
|
require_relative 'rspec/instance_variable'
|
@@ -99,7 +100,6 @@ require_relative 'rspec/skip_block_inside_example'
|
|
99
100
|
require_relative 'rspec/sort_metadata'
|
100
101
|
require_relative 'rspec/spec_file_path_format'
|
101
102
|
require_relative 'rspec/spec_file_path_suffix'
|
102
|
-
require_relative 'rspec/string_as_instance_double_constant'
|
103
103
|
require_relative 'rspec/stubbed_mock'
|
104
104
|
require_relative 'rspec/subject_declaration'
|
105
105
|
require_relative 'rspec/subject_stub'
|
@@ -6,9 +6,7 @@ module RuboCop
|
|
6
6
|
module RSpec
|
7
7
|
# Builds a YAML config file from two config hashes
|
8
8
|
class ConfigFormatter
|
9
|
-
EXTENSION_ROOT_DEPARTMENT = %r{^
|
10
|
-
SUBDEPARTMENTS = [].freeze
|
11
|
-
AMENDMENTS = %(Metrics/BlockLength)
|
9
|
+
EXTENSION_ROOT_DEPARTMENT = %r{^RSpec/}.freeze
|
12
10
|
COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/'
|
13
11
|
|
14
12
|
def initialize(config, descriptions)
|
@@ -18,18 +16,15 @@ module RuboCop
|
|
18
16
|
|
19
17
|
def dump
|
20
18
|
YAML.dump(unified_config)
|
21
|
-
.gsub(
|
22
|
-
.gsub(
|
23
|
-
.gsub(
|
24
|
-
.gsub('"~"', '~')
|
19
|
+
.gsub(%r{^\w+/}, "\n\\0") # Add an extra newline before each cop.
|
20
|
+
.gsub(/^(\s+)- /, '\1 - ') # Add 2 spaces before each array element.
|
21
|
+
.gsub('"~"', '~') # Don't quote tilde, YAML's null value.
|
25
22
|
end
|
26
23
|
|
27
24
|
private
|
28
25
|
|
29
26
|
def unified_config
|
30
27
|
cops.each_with_object(config.dup) do |cop, unified|
|
31
|
-
next if SUBDEPARTMENTS.include?(cop) || AMENDMENTS.include?(cop)
|
32
|
-
|
33
28
|
replace_nil(unified[cop])
|
34
29
|
unified[cop].merge!(descriptions.fetch(cop))
|
35
30
|
unified[cop]['Reference'] = reference(cop)
|
@@ -62,8 +62,8 @@ module RuboCop
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def cop_subclass?
|
65
|
-
|
66
|
-
|
65
|
+
[RSPEC_COP_CLASS_NAME,
|
66
|
+
RUBOCOP_COP_CLASS_NAME].include?(yardoc.superclass.path)
|
67
67
|
end
|
68
68
|
|
69
69
|
def abstract?
|
data/lib/rubocop/rspec/hook.rb
CHANGED
@@ -26,7 +26,7 @@ module RuboCop
|
|
26
26
|
|
27
27
|
# @!method example_group?(node)
|
28
28
|
def_node_matcher :example_group?, <<~PATTERN
|
29
|
-
(
|
29
|
+
(any_block (send #rspec? #ExampleGroups.all ...) ...)
|
30
30
|
PATTERN
|
31
31
|
|
32
32
|
# @!method shared_group?(node)
|
@@ -35,7 +35,7 @@ module RuboCop
|
|
35
35
|
|
36
36
|
# @!method spec_group?(node)
|
37
37
|
def_node_matcher :spec_group?, <<~PATTERN
|
38
|
-
(
|
38
|
+
(any_block (send #rspec?
|
39
39
|
{#SharedGroups.all #ExampleGroups.all}
|
40
40
|
...) ...)
|
41
41
|
PATTERN
|
@@ -50,10 +50,7 @@ module RuboCop
|
|
50
50
|
|
51
51
|
# @!method hook?(node)
|
52
52
|
def_node_matcher :hook?, <<~PATTERN
|
53
|
-
|
54
|
-
(numblock (send nil? #Hooks.all ...) ...)
|
55
|
-
(block (send nil? #Hooks.all ...) ...)
|
56
|
-
}
|
53
|
+
(any_block (send nil? #Hooks.all ...) ...)
|
57
54
|
PATTERN
|
58
55
|
|
59
56
|
# @!method let?(node)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'lint_roller'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module RSpec
|
7
|
+
# A plugin that integrates RuboCop RSpec with RuboCop's plugin system.
|
8
|
+
class Plugin < LintRoller::Plugin
|
9
|
+
# :nocov:
|
10
|
+
def about
|
11
|
+
LintRoller::About.new(
|
12
|
+
name: 'rubocop-rspec',
|
13
|
+
version: Version::STRING,
|
14
|
+
homepage: 'https://github.com/rubocop/rubocop-rspec',
|
15
|
+
description: 'Code style checking for RSpec files.'
|
16
|
+
)
|
17
|
+
end
|
18
|
+
# :nocov:
|
19
|
+
|
20
|
+
def supported?(context)
|
21
|
+
context.engine == :rubocop
|
22
|
+
end
|
23
|
+
|
24
|
+
def rules(_context)
|
25
|
+
project_root = Pathname.new(__dir__).join('../../..')
|
26
|
+
|
27
|
+
ConfigObsoletion.files << project_root.join('config', 'obsoletion.yml')
|
28
|
+
|
29
|
+
LintRoller::Rules.new(
|
30
|
+
type: :path,
|
31
|
+
config_format: :rubocop,
|
32
|
+
value: project_root.join('config/default.yml')
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -17,7 +17,6 @@ module RuboCop
|
|
17
17
|
@replacements = replace
|
18
18
|
end
|
19
19
|
|
20
|
-
# rubocop:disable Metrics/MethodLength
|
21
20
|
def rewrite
|
22
21
|
case text
|
23
22
|
when SHOULDNT_BE_PREFIX
|
@@ -32,7 +31,6 @@ module RuboCop
|
|
32
31
|
remove_should_and_pluralize
|
33
32
|
end
|
34
33
|
end
|
35
|
-
# rubocop:enable Metrics/MethodLength
|
36
34
|
|
37
35
|
private
|
38
36
|
|
data/lib/rubocop/rspec.rb
CHANGED
@@ -3,12 +3,5 @@
|
|
3
3
|
module RuboCop
|
4
4
|
# RuboCop RSpec project namespace
|
5
5
|
module RSpec
|
6
|
-
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
7
|
-
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
8
|
-
|
9
|
-
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
10
|
-
|
11
|
-
::RuboCop::ConfigObsoletion.files << PROJECT_ROOT.join('config',
|
12
|
-
'obsoletion.yml')
|
13
6
|
end
|
14
7
|
end
|
data/lib/rubocop-rspec.rb
CHANGED
@@ -6,9 +6,9 @@ require 'yaml'
|
|
6
6
|
require 'rubocop'
|
7
7
|
|
8
8
|
require_relative 'rubocop/rspec'
|
9
|
-
require_relative 'rubocop/rspec/inject'
|
10
9
|
require_relative 'rubocop/rspec/language'
|
11
10
|
require_relative 'rubocop/rspec/node'
|
11
|
+
require_relative 'rubocop/rspec/plugin'
|
12
12
|
require_relative 'rubocop/rspec/version'
|
13
13
|
require_relative 'rubocop/rspec/wording'
|
14
14
|
|
@@ -34,8 +34,6 @@ require_relative 'rubocop/rspec/example'
|
|
34
34
|
require_relative 'rubocop/rspec/example_group'
|
35
35
|
require_relative 'rubocop/rspec/hook'
|
36
36
|
|
37
|
-
RuboCop::RSpec::Inject.defaults!
|
38
|
-
|
39
37
|
require_relative 'rubocop/cop/rspec_cops'
|
40
38
|
|
41
39
|
# We have to register our autocorrect incompatibilities in RuboCop's cops
|