Skip to content

Commit

Permalink
Merge pull request #1263 from rubocop/fix-metrics-classlength-2
Browse files Browse the repository at this point in the history
Fix .rubocop_todo.yml
  • Loading branch information
pirj committed Apr 21, 2022
2 parents a1a3351 + 648e5ff commit 2f8ec8a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 37 deletions.
2 changes: 0 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-performance
- rubocop-rake
Expand Down
16 changes: 0 additions & 16 deletions .rubocop_todo.yml

This file was deleted.

31 changes: 12 additions & 19 deletions lib/rubocop/cop/rspec/described_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ class DescribedClass < Base
PATTERN

# @!method contains_described_class?(node)
def_node_search :contains_described_class?, <<-PATTERN
(send nil? :described_class)
PATTERN
def_node_search :contains_described_class?,
'(send nil? :described_class)'

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

def scope_change?(node)
scope_changing_syntax?(node) ||
scope_changing_syntax?(node) ||
common_instance_exec_closure?(node) ||
skippable_block?(node)
end

def skippable_block?(node)
node.block_type? && !rspec_block?(node) && skip_blocks?
end

def skip_blocks?
cop_config['SkipBlocks']
node.block_type? && !rspec_block?(node) && cop_config['SkipBlocks']
end

def offensive?(node)
Expand All @@ -152,6 +147,7 @@ def offensive?(node)

def offensive_described_class?(node)
return unless node.const_type?

# E.g. `described_class::CONSTANT`
return if contains_described_class?(node)

Expand All @@ -172,14 +168,13 @@ def full_const_name(node)
# @return [Array<Symbol>]
# @example
# # nil represents base constant
# collapse_namespace([], :C) # => [:C]
# collapse_namespace([:A, :B], [:C) # => [:A, :B, :C]
# collapse_namespace([:A, :B], [:B, :C) # => [:A, :B, :C]
# collapse_namespace([:A, :B], [nil, :C) # => [nil, :C]
# collapse_namespace([:A, :B], [nil, :B, :C) # => [nil, :B, :C]
# collapse_namespace([], [:C]) # => [:C]
# collapse_namespace([:A, :B], [:C]) # => [:A, :B, :C]
# collapse_namespace([:A, :B], [:B, :C]) # => [:A, :B, :C]
# collapse_namespace([:A, :B], [nil, :C]) # => [nil, :C]
# collapse_namespace([:A, :B], [nil, :B, :C]) # => [nil, :B, :C]
def collapse_namespace(namespace, const)
return const if namespace.empty?
return const if const.first.nil?
return const if namespace.empty? || const.first.nil?

start = [0, (namespace.length - const.length)].max
max = namespace.length
Expand All @@ -196,9 +191,7 @@ def collapse_namespace(namespace, const)
# const_name(s(:const, s(:const, nil, :M), :C)) # => [:M, :C]
# const_name(s(:const, s(:cbase), :C)) # => [nil, :C]
def const_name(node)
# rubocop:disable InternalAffairs/NodeDestructuring
namespace, name = *node
# rubocop:enable InternalAffairs/NodeDestructuring
namespace, name = *node # rubocop:disable InternalAffairs/NodeDestructuring
if !namespace
[name]
elsif namespace.const_type?
Expand Down

0 comments on commit 2f8ec8a

Please sign in to comment.