Skip to content

Commit

Permalink
Fix ConstNode#ancestor? raising NoMethodError when the constant i…
Browse files Browse the repository at this point in the history
…s not namespaced.
  • Loading branch information
dvandersluis committed Sep 16, 2020
1 parent c457a21 commit 0621fd4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rubocop/ast/node/const_node.rb
Expand Up @@ -28,6 +28,7 @@ def module_name?

# @return [Boolean] if the constant starts with `::` (aka s(:cbase))
def absolute?
return false unless namespace
each_path.first.cbase_type?
end

Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/ast/const_node_spec.rb
Expand Up @@ -31,6 +31,20 @@

it { expect(const_node.absolute?).to eq false }
end

context 'non-namespaced constant' do
let(:source) { 'Foo' }

it { expect(const_node.absolute?).to eq false }
end
end

describe '#relative?' do
context 'non-namespaced constant' do
let(:source) { 'Foo' }

it { expect(const_node.relative?).to eq true }
end
end

describe '#each_path' do
Expand Down

0 comments on commit 0621fd4

Please sign in to comment.