rubocop-vicenzo 0.10.0 → 0.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f7a8f58f53c6f2e6b50f1645a55cb401cd33b1f2654c793eaecd52cbf879153
4
- data.tar.gz: f2eaba7a6bbb615190abf109a64681372988e3f8cea255c6055f6ae40698c7e2
3
+ metadata.gz: 9bcae934be9ffca6f86007a710cdd35a9c610a7d5610b5c83960b12905c1a25b
4
+ data.tar.gz: a2b2cb6db0f9d177099b845caf9de7b87d71381efbc37041ca2f01f7c1f62e8b
5
5
  SHA512:
6
- metadata.gz: '0258853f6e8d32fb88d7d4c53fb5520e2c828bd31d5968be91008ab34c13a729188c802e91539ef95eef937c56dc584cb59c7dbb9ddcc8c50e3cd6e991eb49a1'
7
- data.tar.gz: c8a4a8d41af0c5d5f294acfd9361f1226f002590b051508b97a6fbcb9f3f36dbe695a6ae6efbccb7c122395bc9dd76e83f7cffc9a026f3d822954e20236483df
6
+ metadata.gz: 3568dc18ce54dc425af8fad2e06f0d2fb23e52c190c886a8781d879f4f46f0120dd949eab9ead4f05510b280a97c2d7513a01f95264f8a8c9c9facf3fa03d09b
7
+ data.tar.gz: 93c229f5feb3bfc0b5ea551b57afe5910e48f94d3e44f9da82fc054297d7499936e22f1ff84a7e5f45a2c9b1464b8204f6d38af5f99cdb625d8cf2b51bf99c60
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "0.10.0"
2
+ ".": "0.11.0"
3
3
  }
data/CHANGELOG.md CHANGED
@@ -1,50 +1,64 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.11.0](https://github.com/bvicenzo/rubocop-vicenzo/compare/v0.10.0...v0.11.0) (2026-11-18)
4
+
5
+
6
+ ### Features
7
+
8
+ * add Vicenzo/RSpec/ScenarioDescribe cop ([#54](https://github.com/bvicenzo/rubocop-vicenzo/pull/54)) ([df050f7](https://github.com/bvicenzo/rubocop-vicenzo/commit/df050f7e013b029a009c7445b30de739132de4b4)), closes [#48](https://github.com/bvicenzo/rubocop-vicenzo/issues/48)
9
+ * allow whole short words in Vicenzo/Naming/ShortName via AllowedNames ([#51](https://github.com/bvicenzo/rubocop-vicenzo/pull/51)) ([972ff35](https://github.com/bvicenzo/rubocop-vicenzo/commit/972ff35e376b4364876b7638d2838d5593e69ea9)), closes [#47](https://github.com/bvicenzo/rubocop-vicenzo/issues/47)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * remove 'however' from the context prefix vocabulary ([#49](https://github.com/bvicenzo/rubocop-vicenzo/pull/49)) ([0c46397](https://github.com/bvicenzo/rubocop-vicenzo/commit/0c46397b7fd04c943ae0f974d26f48cb80de17f0)), closes [#46](https://github.com/bvicenzo/rubocop-vicenzo/issues/46)
15
+ * report nested contexts whose forbidden first word is followed by punctuation ([#52](https://github.com/bvicenzo/rubocop-vicenzo/pull/52)) ([e103531](https://github.com/bvicenzo/rubocop-vicenzo/commit/e1035314d769f9e3a68cb6ba3d5ce98eab588bf4)), closes [#50](https://github.com/bvicenzo/rubocop-vicenzo/issues/50)
16
+
3
17
  ## [0.10.0](https://github.com/bvicenzo/rubocop-vicenzo/compare/v0.9.0...v0.10.0) (2026-10-23)
4
18
 
5
19
 
6
20
  ### Features
7
21
 
8
- * add Vicenzo/RSpec/LetAliasingSubject cop ([#44](https://github.com/bvicenzo/rubocop-vicenzo/issues/44)) ([a8cebd3](https://github.com/bvicenzo/rubocop-vicenzo/commit/a8cebd3c0237e8805a58ff9efa7ca34f6beb34b0)), closes [#42](https://github.com/bvicenzo/rubocop-vicenzo/issues/42)
9
- * add Vicenzo/Style/PreferManyOverSizeComparison cop ([#38](https://github.com/bvicenzo/rubocop-vicenzo/issues/38)) ([910ea02](https://github.com/bvicenzo/rubocop-vicenzo/commit/910ea026f7e4c46f9de27db580e6330cf845bfe7))
22
+ * add Vicenzo/RSpec/LetAliasingSubject cop ([#44](https://github.com/bvicenzo/rubocop-vicenzo/pull/44)) ([a8cebd3](https://github.com/bvicenzo/rubocop-vicenzo/commit/a8cebd3c0237e8805a58ff9efa7ca34f6beb34b0)), closes [#42](https://github.com/bvicenzo/rubocop-vicenzo/issues/42)
23
+ * add Vicenzo/Style/PreferManyOverSizeComparison cop ([#38](https://github.com/bvicenzo/rubocop-vicenzo/pull/38)) ([910ea02](https://github.com/bvicenzo/rubocop-vicenzo/commit/910ea026f7e4c46f9de27db580e6330cf845bfe7))
10
24
 
11
25
 
12
26
  ### Bug Fixes
13
27
 
14
- * report subjects that derive from an allowed method in SubjectIsMethodResult ([#41](https://github.com/bvicenzo/rubocop-vicenzo/issues/41)) ([a5efd33](https://github.com/bvicenzo/rubocop-vicenzo/commit/a5efd3330b32dd24b4291121a64e378091297a57)), closes [#40](https://github.com/bvicenzo/rubocop-vicenzo/issues/40)
15
- * see subjects declared in shared groups in LetIsMethodResult and LetAliasingSubject ([#45](https://github.com/bvicenzo/rubocop-vicenzo/issues/45)) ([a98039e](https://github.com/bvicenzo/rubocop-vicenzo/commit/a98039e2cbea568267d8b7832b4717b763678d14)), closes [#43](https://github.com/bvicenzo/rubocop-vicenzo/issues/43)
28
+ * report subjects that derive from an allowed method in SubjectIsMethodResult ([#41](https://github.com/bvicenzo/rubocop-vicenzo/pull/41)) ([a5efd33](https://github.com/bvicenzo/rubocop-vicenzo/commit/a5efd3330b32dd24b4291121a64e378091297a57)), closes [#40](https://github.com/bvicenzo/rubocop-vicenzo/issues/40)
29
+ * see subjects declared in shared groups in LetIsMethodResult and LetAliasingSubject ([#45](https://github.com/bvicenzo/rubocop-vicenzo/pull/45)) ([a98039e](https://github.com/bvicenzo/rubocop-vicenzo/commit/a98039e2cbea568267d8b7832b4717b763678d14)), closes [#43](https://github.com/bvicenzo/rubocop-vicenzo/issues/43)
16
30
 
17
31
  ## [0.9.0](https://github.com/bvicenzo/rubocop-vicenzo/compare/v0.8.0...v0.9.0) (2026-09-23)
18
32
 
19
33
 
20
34
  ### Features
21
35
 
22
- * add Vicenzo/Naming/AnonymousUnusedName cop ([#33](https://github.com/bvicenzo/rubocop-vicenzo/issues/33)) ([fabbad6](https://github.com/bvicenzo/rubocop-vicenzo/commit/fabbad655dac0c362924dd0aaf245abd2c7023e1))
23
- * add Vicenzo/Naming/ShortName cop and an opinionated config/style.yml ([#35](https://github.com/bvicenzo/rubocop-vicenzo/issues/35)) ([1b67f46](https://github.com/bvicenzo/rubocop-vicenzo/commit/1b67f4643b4348f5768a8fbb3b88cea35046e5e2))
24
- * add Vicenzo/RSpec/DescribeInsideContext cop ([#37](https://github.com/bvicenzo/rubocop-vicenzo/issues/37)) ([3f3d6ae](https://github.com/bvicenzo/rubocop-vicenzo/commit/3f3d6aeb95d087e32594e8ded3d1ce0e3715dee7))
25
- * add Vicenzo/RSpec/UnnestedContextImproperStart cop ([#36](https://github.com/bvicenzo/rubocop-vicenzo/issues/36)) ([0a8fb0f](https://github.com/bvicenzo/rubocop-vicenzo/commit/0a8fb0fec62370ac331b9a3275b95a0b22998b1d))
36
+ * add Vicenzo/Naming/AnonymousUnusedName cop ([#33](https://github.com/bvicenzo/rubocop-vicenzo/pull/33)) ([fabbad6](https://github.com/bvicenzo/rubocop-vicenzo/commit/fabbad655dac0c362924dd0aaf245abd2c7023e1))
37
+ * add Vicenzo/Naming/ShortName cop and an opinionated config/style.yml ([#35](https://github.com/bvicenzo/rubocop-vicenzo/pull/35)) ([1b67f46](https://github.com/bvicenzo/rubocop-vicenzo/commit/1b67f4643b4348f5768a8fbb3b88cea35046e5e2))
38
+ * add Vicenzo/RSpec/DescribeInsideContext cop ([#37](https://github.com/bvicenzo/rubocop-vicenzo/pull/37)) ([3f3d6ae](https://github.com/bvicenzo/rubocop-vicenzo/commit/3f3d6aeb95d087e32594e8ded3d1ce0e3715dee7))
39
+ * add Vicenzo/RSpec/UnnestedContextImproperStart cop ([#36](https://github.com/bvicenzo/rubocop-vicenzo/pull/36)) ([0a8fb0f](https://github.com/bvicenzo/rubocop-vicenzo/commit/0a8fb0fec62370ac331b9a3275b95a0b22998b1d))
26
40
 
27
41
  ## [0.8.0](https://github.com/bvicenzo/rubocop-vicenzo/compare/v0.7.0...v0.8.0) (2026-09-09)
28
42
 
29
43
 
30
44
  ### Features
31
45
 
32
- * add RSpec cops against top-level declarations ([#31](https://github.com/bvicenzo/rubocop-vicenzo/issues/31)) ([ef5e207](https://github.com/bvicenzo/rubocop-vicenzo/commit/ef5e20728c0c4bc94dbb5eec54a48ff5197d1b25))
46
+ * add RSpec cops against top-level declarations ([#31](https://github.com/bvicenzo/rubocop-vicenzo/pull/31)) ([ef5e207](https://github.com/bvicenzo/rubocop-vicenzo/commit/ef5e20728c0c4bc94dbb5eec54a48ff5197d1b25))
33
47
 
34
48
  ## [0.7.0](https://github.com/bvicenzo/rubocop-vicenzo/compare/v0.6.0...v0.7.0) (2026-08-31)
35
49
 
36
50
 
37
51
  ### Features
38
52
 
39
- * add RSpec cops against subjects hidden in lets ([#30](https://github.com/bvicenzo/rubocop-vicenzo/issues/30)) ([9daf259](https://github.com/bvicenzo/rubocop-vicenzo/commit/9daf25972252fdfdb92a51bba9cfe70e63446d17))
40
- * add Vicenzo/RSpec/SubjectIsMethodResult cop ([#28](https://github.com/bvicenzo/rubocop-vicenzo/issues/28)) ([b69245a](https://github.com/bvicenzo/rubocop-vicenzo/commit/b69245af973f3341bbe62bca628333c5acb909d7))
53
+ * add RSpec cops against subjects hidden in lets ([#30](https://github.com/bvicenzo/rubocop-vicenzo/pull/30)) ([9daf259](https://github.com/bvicenzo/rubocop-vicenzo/commit/9daf25972252fdfdb92a51bba9cfe70e63446d17))
54
+ * add Vicenzo/RSpec/SubjectIsMethodResult cop ([#28](https://github.com/bvicenzo/rubocop-vicenzo/pull/28)) ([b69245a](https://github.com/bvicenzo/rubocop-vicenzo/commit/b69245af973f3341bbe62bca628333c5acb909d7))
41
55
 
42
56
  ## [0.6.0](https://github.com/bvicenzo/rubocop-vicenzo/compare/v0.5.0...v0.6.0) (2026-08-19)
43
57
 
44
58
 
45
59
  ### Features
46
60
 
47
- * add RSpec cops against mutated and derived premises ([#26](https://github.com/bvicenzo/rubocop-vicenzo/issues/26)) ([b138dd0](https://github.com/bvicenzo/rubocop-vicenzo/commit/b138dd00a76e1bcd62e95c1f2c51dca5b4232319))
61
+ * add RSpec cops against mutated and derived premises ([#26](https://github.com/bvicenzo/rubocop-vicenzo/pull/26)) ([b138dd0](https://github.com/bvicenzo/rubocop-vicenzo/commit/b138dd00a76e1bcd62e95c1f2c51dca5b4232319))
48
62
 
49
63
  ## [0.5.0] - 2026-06-29
50
64
 
data/README.md CHANGED
@@ -11,7 +11,7 @@ Add it to the `development`/`test` group of your `Gemfile`:
11
11
  <!-- x-release-please-start-version -->
12
12
  ```ruby
13
13
  group :development, :test do
14
- gem 'rubocop-vicenzo', '~> 0.10.0', require: false
14
+ gem 'rubocop-vicenzo', '~> 0.11.0', require: false
15
15
  end
16
16
  ```
17
17
  <!-- x-release-please-end-version -->
data/config/default.yml CHANGED
@@ -16,6 +16,7 @@ Vicenzo/Naming/ShortName:
16
16
  Enabled: true
17
17
  Severity: convention
18
18
  MinNameLength: 3
19
+ AllowedNames: []
19
20
  VersionAdded: '0.9.0'
20
21
 
21
22
  Vicenzo/Rails/EnumInclusionOfValidation:
@@ -150,6 +151,17 @@ Vicenzo/RSpec/LetIsMethodResult:
150
151
  - '**/spec/factories/**/*'
151
152
  VersionAdded: '0.7.0'
152
153
 
154
+ Vicenzo/RSpec/ScenarioDescribe:
155
+ Description: 'A describe exercising an entry point a sibling describe already names is a scenario of it, and belongs in a context inside that describe.'
156
+ Enabled: true
157
+ Severity: warning
158
+ Include:
159
+ - '**/spec/**/*_spec.rb'
160
+ Exclude:
161
+ - '**/spec/support/**/*'
162
+ - '**/spec/factories/**/*'
163
+ VersionAdded: '0.11.0'
164
+
153
165
  Vicenzo/RSpec/SubjectDefinedAsLet:
154
166
  Description: 'A let the expectations assert on, in a group declaring no subject, must be declared as the subject.'
155
167
  Enabled: true
@@ -236,7 +248,6 @@ Vicenzo/RSpec/UnnestedContextImproperStart:
236
248
  ForbiddenPrefixes:
237
249
  - and
238
250
  - but
239
- - however
240
251
  Include:
241
252
  - '**/spec/**/*_spec.rb'
242
253
  Exclude:
data/config/style.yml CHANGED
@@ -130,11 +130,29 @@ Naming/RescuedExceptionsVariableName:
130
130
  Enabled: true
131
131
  PreferredName: error
132
132
 
133
+ # Short names that are whole English words, such as `to` as the upper bound of a
134
+ # range. Only whole words belong here: the abbreviations in the core
135
+ # Naming/MethodParameterName default (`db`, `io`, `ip`, `os`, `pp`, `cc`) are left
136
+ # out on purpose, since they are exactly what the rule is meant to catch.
137
+ Vicenzo/Naming/ShortName:
138
+ AllowedNames:
139
+ - to
140
+ - at
141
+ - by
142
+ - of
143
+ - on
144
+
133
145
  # Vicenzo/Naming/ShortName covers local variables. Block parameters are the core
134
146
  # cop's job, but it ships with MinNameLength: 1 and therefore never fires — raise
135
- # it so both halves of the rule agree.
147
+ # it, and allow the same whole words, so both halves of the rule agree.
136
148
  Naming/BlockParameterName:
137
149
  MinNameLength: 3
150
+ AllowedNames:
151
+ - to
152
+ - at
153
+ - by
154
+ - of
155
+ - on
138
156
 
139
157
  ###### METRICS #####
140
158
 
@@ -26,6 +26,12 @@ module RuboCop
26
26
  # chosen, and it is that signature the parameter cops point at. The fix
27
27
  # cascades from there.
28
28
  #
29
+ # `AllowedNames` accepts short names that are whole words of the domain,
30
+ # such as `to` as the upper bound of a range. It is not a place for
31
+ # abbreviations (`db`, `io`): those are exactly what the cop is meant to
32
+ # catch. Leading underscores are ignored when matching, so `_to` is
33
+ # allowed along with `to`.
34
+ #
29
35
  # @example
30
36
  # # bad
31
37
  # v = shelf.capacity
@@ -71,6 +77,14 @@ module RuboCop
71
77
  #
72
78
  # # good
73
79
  # book_title = build
80
+ #
81
+ # @example AllowedNames: [to]
82
+ # # bad
83
+ # at = schedule.first
84
+ #
85
+ # # good
86
+ # from = options.fetch(:from)
87
+ # to = options.fetch(:to)
74
88
  class ShortName < Base
75
89
  MSG = 'Name `%<name>s` spells %<length>d letter(s); at least %<minimum>d are required. ' \
76
90
  'A letter or an abbreviation carries no meaning to the next reader — write the ' \
@@ -81,11 +95,13 @@ module RuboCop
81
95
 
82
96
  ANONYMOUS_NAME_PATTERN = /\A_+\z/
83
97
 
98
+ LEADING_UNDERSCORES_PATTERN = /\A_+/
99
+
84
100
  SCOPE_TYPES = %i[def defs block numblock itblock].freeze
85
101
 
86
102
  def on_lvasgn(node)
87
103
  name = node.children.first
88
- return if anonymous?(name) || rescued_error?(node) || forwarded_by_shorthand?(node, name)
104
+ return if anonymous?(name) || allowed?(name) || rescued_error?(node) || forwarded_by_shorthand?(node, name)
89
105
 
90
106
  length = spelled_length(name)
91
107
  return if length >= min_name_length
@@ -105,6 +121,12 @@ module RuboCop
105
121
  ANONYMOUS_NAME_PATTERN.match?(name.to_s)
106
122
  end
107
123
 
124
+ # Leading underscores are stripped before the lookup, as the core
125
+ # `Naming/MethodParameterName` does, so `_to` is allowed along with `to`.
126
+ def allowed?(name)
127
+ allowed_names.include?(name.to_s.sub(LEADING_UNDERSCORES_PATTERN, ''))
128
+ end
129
+
108
130
  def rescued_error?(node)
109
131
  parent = node.parent
110
132
  parent&.resbody_type? && parent.exception_variable == node
@@ -126,6 +148,10 @@ module RuboCop
126
148
  def min_name_length
127
149
  cop_config.fetch('MinNameLength', DEFAULT_MIN_NAME_LENGTH)
128
150
  end
151
+
152
+ def allowed_names
153
+ cop_config.fetch('AllowedNames', [])
154
+ end
129
155
  end
130
156
  end
131
157
  end
@@ -5,7 +5,7 @@ module RuboCop
5
5
  module Vicenzo
6
6
  module RSpec
7
7
  # Checks for nested `context` blocks where the inner `context`
8
- # starts with "when", "with", or "without". It suggests replacing it with "and", "but", or "however".
8
+ # starts with "when", "with", or "without". It suggests replacing it with "and" or "but".
9
9
  #
10
10
  # @example
11
11
  # # bad
@@ -22,7 +22,7 @@ module RuboCop
22
22
  # end
23
23
  # end
24
24
  class NestedContextImproperStart < RuboCop::Cop::RSpec::Base
25
- MSG = 'Nested `context` should start with `and`, `but`, or `however`, not `when`, `with`, or `without`.'
25
+ MSG = 'Nested `context` should start with `and` or `but`, not `when`, `with`, or `without`.'
26
26
 
27
27
  FORBIDDEN_PREFIXES = %w[when with without].freeze
28
28
 
@@ -59,8 +59,7 @@ module RuboCop
59
59
 
60
60
  return unless description_node&.str_type?
61
61
 
62
- text = description_node.value.to_s.strip
63
- first_word = text.split.first&.downcase
62
+ first_word = description_node.value.lstrip[/\A[[:alpha:]]+/]&.downcase
64
63
 
65
64
  return unless FORBIDDEN_PREFIXES.include?(first_word)
66
65
 
@@ -0,0 +1,184 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'describe_inside_context'
4
+ require_relative 'mixin/described_method'
5
+ require_relative 'mixin/premise_tracking'
6
+ require_relative 'mixin/subject_reference'
7
+
8
+ module RuboCop
9
+ module Cop
10
+ module Vicenzo
11
+ module RSpec
12
+ # A describe that exercises an entry point a sibling describe already names is a scenario of that entry
13
+ # point, escaped into a group of its own. Make it a context inside the describe naming the entry point.
14
+ #
15
+ # A describe names *what* is exercised, never *when*. A scenario usually escapes because the premises of
16
+ # the entry point's describe - a temporary directory, a `before` writing a file - did not fit it. Those
17
+ # premises belong in the contexts that read them: move them down, and the scenario fits back in. Left
18
+ # outside, the tree claims the entry point has fewer cases than it has, and the escaped one never states
19
+ # its premise as a context sentence.
20
+ #
21
+ # Only describes that name nothing are checked: a describe naming a class, an instance method
22
+ # (`'#name'`) or a class method (`'.name'`) states what it exercises, even when it calls another entry
23
+ # point to build its premises. Groups such as `describe 'GET /users'`, `describe 'enums'` or
24
+ # `describe 'callbacks'` are reported only when a sibling names the entry point they call.
25
+ #
26
+ # An entry point is reached by `described_class.name` (or `described_class.(...)` for `.call`) for a
27
+ # class method, and by `subject.name`, the named subject or `described_class.new(...).name` for an
28
+ # instance method. Calls inside a nested describe that names a class or an entry point belong to that
29
+ # describe, so they do not count.
30
+ #
31
+ # @example
32
+ # # bad - the reference file is a scenario of `.from_file`, outside its describe
33
+ # RSpec.describe ImageLoader do
34
+ # describe '.from_file' do
35
+ # let(:directory) { Dir.mktmpdir }
36
+ #
37
+ # after { FileUtils.remove_entry(directory) }
38
+ #
39
+ # context 'when the file does not exist' do
40
+ # it { expect { described_class.from_file(File.join(directory, 'missing.bin')) }.to raise_error(Errno::ENOENT) }
41
+ # end
42
+ # end
43
+ #
44
+ # describe 'loading the real reference file', :local_file do
45
+ # it { expect(described_class.from_file(reference_path)).to have_attributes(size: 393_232) }
46
+ # end
47
+ # end
48
+ #
49
+ # # good - every scenario of `.from_file` is a context inside it, carrying its own premises
50
+ # RSpec.describe ImageLoader do
51
+ # describe '.from_file' do
52
+ # context 'when the file does not exist' do
53
+ # let(:directory) { Dir.mktmpdir }
54
+ #
55
+ # after { FileUtils.remove_entry(directory) }
56
+ #
57
+ # it { expect { described_class.from_file(File.join(directory, 'missing.bin')) }.to raise_error(Errno::ENOENT) }
58
+ # end
59
+ #
60
+ # context 'when the file is the real reference file', :local_file do
61
+ # it { expect(described_class.from_file(reference_path)).to have_attributes(size: 393_232) }
62
+ # end
63
+ # end
64
+ # end
65
+ class ScenarioDescribe < RuboCop::Cop::RSpec::Base
66
+ include PremiseTracking
67
+ include SubjectReference
68
+
69
+ MSG = 'This `%<group>s` exercises `%<entry_point>s`, which the sibling `%<sibling>s` already names: ' \
70
+ 'make it a `context` inside that group.'
71
+
72
+ CLASS_METHOD = '.'
73
+ INSTANCE_METHOD = '#'
74
+
75
+ # @!method describe_definition?(node)
76
+ def_node_matcher :describe_definition?, <<~PATTERN
77
+ (any_block (send #rspec? {#{DescribeInsideContext::DESCRIBES.map(&:inspect).join(' ')}} ...) ...)
78
+ PATTERN
79
+
80
+ # @!method described_class_reference?(node)
81
+ def_node_matcher :described_class_reference?, '(send nil? :described_class)'
82
+
83
+ # @!method new_instance?(node)
84
+ def_node_matcher :new_instance?, '(send (send nil? :described_class) :new ...)'
85
+
86
+ def on_block(node)
87
+ return unless spec_group?(node)
88
+
89
+ describes = child_describes(node)
90
+ named = named_entry_points(describes)
91
+
92
+ return if named.empty?
93
+
94
+ describes.each { |describe| check_candidate(describe, named) }
95
+ end
96
+
97
+ alias on_numblock on_block
98
+
99
+ private
100
+
101
+ def child_describes(group)
102
+ describes = []
103
+ each_child_block(group) { |child| describes << child if describe_definition?(child) }
104
+ describes
105
+ end
106
+
107
+ # The first sibling naming each entry point, keyed by the entry point as written: `.name` or `#name`.
108
+ def named_entry_points(describes)
109
+ describes.each_with_object({}) do |describe, named|
110
+ entry_point = entry_point_named_by(describe)
111
+ named[entry_point] ||= describe if entry_point
112
+ end
113
+ end
114
+
115
+ def check_candidate(describe, named)
116
+ return if names_something?(describe)
117
+
118
+ entry_point = first_reached_entry_point(describe, named)
119
+ return unless entry_point
120
+
121
+ add_offense(describe.send_node, message: message(describe, entry_point, named[entry_point]))
122
+ end
123
+
124
+ # `'.from_file'`, `'#size'` and the forms carrying a signature. A bare name, such as `'call'`, could be
125
+ # either, so it names nothing.
126
+ def entry_point_named_by(describe)
127
+ description = describe.send_node.first_argument
128
+ return unless description&.str_type?
129
+
130
+ match = DescribedMethod::PREFIXED_METHOD_DESCRIPTION.match(description.value)
131
+ "#{description.value[0]}#{match[:name]}" if match
132
+ end
133
+
134
+ # A class changes what `described_class` is below it, and an entry point is what the group exercises:
135
+ # either way, the group states what it is about.
136
+ def names_something?(describe)
137
+ describe.send_node.first_argument&.const_type? || !entry_point_named_by(describe).nil?
138
+ end
139
+
140
+ # Walks the group in source order, leaving out the nested describes that name something: what is
141
+ # called there belongs to them.
142
+ def first_reached_entry_point(node, named)
143
+ node.each_child_node do |child|
144
+ next if describe_definition?(child) && names_something?(child)
145
+
146
+ entry_point = reached_entry_point(child, named) || first_reached_entry_point(child, named)
147
+ return entry_point if entry_point
148
+ end
149
+
150
+ nil
151
+ end
152
+
153
+ def reached_entry_point(node, named)
154
+ return unless node.call_type? && node.receiver
155
+
156
+ class_method = "#{CLASS_METHOD}#{node.method_name}"
157
+ instance_method = "#{INSTANCE_METHOD}#{node.method_name}"
158
+
159
+ if named.has_key?(class_method) && described_class_reference?(node.receiver)
160
+ class_method
161
+ elsif named.has_key?(instance_method) && instance_receiver?(node)
162
+ instance_method
163
+ end
164
+ end
165
+
166
+ def instance_receiver?(node)
167
+ new_instance?(node.receiver) || subject_reference?(node.receiver, subject_names(node))
168
+ end
169
+
170
+ def message(describe, entry_point, sibling)
171
+ sibling_send = sibling.send_node
172
+
173
+ format(
174
+ MSG,
175
+ group: describe.method_name,
176
+ entry_point:,
177
+ sibling: "#{sibling_send.method_name} #{sibling_send.first_argument.source}"
178
+ )
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Vicenzo
6
6
  module RSpec
7
- # Checks for `context` blocks with no parent scenario that start with "and", "but", or "however".
7
+ # Checks for `context` blocks with no parent scenario that start with "and" or "but".
8
8
  # It suggests starting them with "when", "with", or "without" instead.
9
9
  #
10
10
  # A conjunction continues the scenario of the enclosing context. When the closest example group is
@@ -34,7 +34,7 @@ module RuboCop
34
34
  # end
35
35
  # end
36
36
  #
37
- # @example ForbiddenPrefixes: ['and', 'but', 'however', 'also']
37
+ # @example ForbiddenPrefixes: ['and', 'but', 'also']
38
38
  # # bad
39
39
  # describe '#available_colors' do
40
40
  # context 'also when the color pink is not available' do
@@ -45,7 +45,7 @@ module RuboCop
45
45
  MSG = 'Unnested `context` should start with `when`, `with`, or `without`, not `%<prefix>s`.'
46
46
 
47
47
  CONTEXTS = %i[context fcontext xcontext].freeze
48
- DEFAULT_FORBIDDEN_PREFIXES = %w[and but however].freeze
48
+ DEFAULT_FORBIDDEN_PREFIXES = %w[and but].freeze
49
49
 
50
50
  # @!method context_definition?(node)
51
51
  def_node_matcher :context_definition?, <<~PATTERN
@@ -14,6 +14,7 @@ require_relative 'vicenzo/rspec/nested_let_redefinition'
14
14
  require_relative 'vicenzo/rspec/nested_subject_redefinition'
15
15
  require_relative 'vicenzo/rspec/leaky_definition'
16
16
  require_relative 'vicenzo/rspec/let_aliasing_subject'
17
+ require_relative 'vicenzo/rspec/scenario_describe'
17
18
  require_relative 'vicenzo/rspec/subject_defined_as_let'
18
19
  require_relative 'vicenzo/rspec/subject_is_method_result'
19
20
  require_relative 'vicenzo/rspec/top_level_context'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Vicenzo
5
- VERSION = '0.10.0'
5
+ VERSION = '0.11.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-vicenzo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Vicenzo
@@ -98,6 +98,7 @@ files:
98
98
  - lib/rubocop/cop/vicenzo/rspec/nested_let_redefinition.rb
99
99
  - lib/rubocop/cop/vicenzo/rspec/nested_subject_redefinition.rb
100
100
  - lib/rubocop/cop/vicenzo/rspec/returned_chain.rb
101
+ - lib/rubocop/cop/vicenzo/rspec/scenario_describe.rb
101
102
  - lib/rubocop/cop/vicenzo/rspec/subject_defined_as_let.rb
102
103
  - lib/rubocop/cop/vicenzo/rspec/subject_is_method_result.rb
103
104
  - lib/rubocop/cop/vicenzo/rspec/top_level_context.rb