Skip to content

Commit 648e5ff

Browse files
committed
Shave off bits from a long class
1 parent 1cf43e2 commit 648e5ff

File tree

3 files changed

+7
-32
lines changed

3 files changed

+7
-32
lines changed

.rubocop.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
inherit_from: .rubocop_todo.yml
2-
31
require:
42
- rubocop-performance
53
- rubocop-rake

.rubocop_todo.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

lib/rubocop/cop/rspec/described_class.rb

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ class DescribedClass < Base
7878
PATTERN
7979

8080
# @!method contains_described_class?(node)
81-
def_node_search :contains_described_class?, <<-PATTERN
82-
(send nil? :described_class)
83-
PATTERN
81+
def_node_search :contains_described_class?,
82+
'(send nil? :described_class)'
8483

8584
def on_block(node)
8685
# In case the explicit style is used, we need to remember what's
@@ -129,17 +128,13 @@ def message(offense)
129128
end
130129

131130
def scope_change?(node)
132-
scope_changing_syntax?(node) ||
131+
scope_changing_syntax?(node) ||
133132
common_instance_exec_closure?(node) ||
134133
skippable_block?(node)
135134
end
136135

137136
def skippable_block?(node)
138-
node.block_type? && !rspec_block?(node) && skip_blocks?
139-
end
140-
141-
def skip_blocks?
142-
cop_config['SkipBlocks']
137+
node.block_type? && !rspec_block?(node) && cop_config['SkipBlocks']
143138
end
144139

145140
def offensive?(node)
@@ -152,6 +147,7 @@ def offensive?(node)
152147

153148
def offensive_described_class?(node)
154149
return unless node.const_type?
150+
155151
# E.g. `described_class::CONSTANT`
156152
return if contains_described_class?(node)
157153

@@ -178,8 +174,7 @@ def full_const_name(node)
178174
# collapse_namespace([:A, :B], [nil, :C]) # => [nil, :C]
179175
# collapse_namespace([:A, :B], [nil, :B, :C]) # => [nil, :B, :C]
180176
def collapse_namespace(namespace, const)
181-
return const if namespace.empty?
182-
return const if const.first.nil?
177+
return const if namespace.empty? || const.first.nil?
183178

184179
start = [0, (namespace.length - const.length)].max
185180
max = namespace.length
@@ -196,9 +191,7 @@ def collapse_namespace(namespace, const)
196191
# const_name(s(:const, s(:const, nil, :M), :C)) # => [:M, :C]
197192
# const_name(s(:const, s(:cbase), :C)) # => [nil, :C]
198193
def const_name(node)
199-
# rubocop:disable InternalAffairs/NodeDestructuring
200-
namespace, name = *node
201-
# rubocop:enable InternalAffairs/NodeDestructuring
194+
namespace, name = *node # rubocop:disable InternalAffairs/NodeDestructuring
202195
if !namespace
203196
[name]
204197
elsif namespace.const_type?

0 commit comments

Comments
 (0)