Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ConstNode#absolute? raising NoMethodError when the constant is not namespaced #115

Merged
merged 1 commit into from Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,9 @@

## master (unreleased)

### Bug fixes
* [#115](https://github.com/rubocop-hq/rubocop-ast/pull/115): Fix `ConstNode#absolute?` when the constant is not namespaced. ([@dvandersluis][])

## 0.4.0 (2020-09-11)

### New features
Expand Down Expand Up @@ -97,3 +100,4 @@
[@owst]: https://github.com/owst
[@fatkodima]: https://github.com/fatkodima
[@koic]: https://github.com/koic
[@dvandersluis]: https://github.com/dvandersluis
2 changes: 2 additions & 0 deletions lib/rubocop/ast/node/const_node.rb
Expand Up @@ -28,6 +28,8 @@ 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 'with a non-namespaced constant' do
let(:source) { 'Foo' }

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

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

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

describe '#each_path' do
Expand Down