Skip to content

Commit

Permalink
Add DefNode#endless? (Ruby 3.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre authored and mergify[bot] committed Sep 29, 2020
1 parent ce8e7bc commit 210ce65
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### New features

* [#49](https://github.com/rubocop-hq/rubocop-ast/pull/49): Add `DefNode#endless?` (Ruby 3.0). ([@marcandre][])

## 0.7.1 (2020-09-28)

### Bug fixes
Expand Down
5 changes: 5 additions & 0 deletions lib/rubocop/ast/node/def_node.rb
Expand Up @@ -58,6 +58,11 @@ def body
def receiver
children[-4]
end

# @return [Boolean] if the definition is without an `end` or not.
def endless?
!loc.end
end
end
end
end
14 changes: 14 additions & 0 deletions spec/rubocop/ast/def_node_spec.rb
Expand Up @@ -516,4 +516,18 @@
it { expect(def_node.body.begin_type?).to be(true) }
end
end

describe '#endless?' do
context 'with standard method definition' do
let(:source) { 'def foo; 42; end' }

it { expect(def_node.endless?).to be(false) }
end

context 'with endless method definition', :ruby30 do
let(:source) { 'def foo() = 42' }

it { expect(def_node.endless?).to be(true) }
end
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -34,6 +34,10 @@
let(:ruby_version) { 2.7 }
end

RSpec.shared_context 'ruby 3.0', :ruby30 do
let(:ruby_version) { 3.0 }
end

# ...
module DefaultRubyVersion
extend RSpec::SharedContext
Expand Down

0 comments on commit 210ce65

Please sign in to comment.