Skip to content

Commit

Permalink
Support "Endless method definition" syntax for Ruby 2.8 (3.0)
Browse files Browse the repository at this point in the history
This PR supports "Endless method definition" syntax for Ruby 2.8 (3.0).
Parser gem supports this syntax by whitequark/parser#676.

Ref: https://bugs.ruby-lang.org/issues/16746
  • Loading branch information
koic committed Jun 25, 2020
1 parent 4377a64 commit 81d230e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@
* [#41](https://github.com/rubocop-hq/rubocop-ast/pull/41): Add `delimiters` and related predicates for `RegexpNode`. ([@owst][])
* [#46](https://github.com/rubocop-hq/rubocop-ast/pull/46): Basic support for [non-legacy AST output from parser](https://github.com/whitequark/parser/#usage). Note that there is no support (yet) in main RuboCop gem. ([@marcandre][])
* [#48](https://github.com/rubocop-hq/rubocop-ast/pull/48): Support `Parser::Ruby28` for Ruby 2.8 (3.0) parser. ([@koic][])
* [#49](https://github.com/rubocop-hq/rubocop-ast/pull/49): Support "Endless method definition" syntax for Ruby 2.8 (3.0). ([@koic][])

## 0.0.3 (2020-05-15)

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/ast/builder.rb
Expand Up @@ -26,6 +26,7 @@ class Builder < Parser::Builders::Default
case: CaseNode,
class: ClassNode,
def: DefNode,
def_e: DefNode,
defined?: DefinedNode,
defs: DefNode,
ensure: EnsureNode,
Expand Down
18 changes: 18 additions & 0 deletions spec/rubocop/ast/def_node_spec.rb
Expand Up @@ -15,6 +15,12 @@

it { expect(def_node.is_a?(described_class)).to be(true) }
end

context 'with a def_e node', :ruby28 do
let(:source) { 'def foo() = 42' }

it { expect(def_node.is_a?(described_class)).to be(true) }
end
end

describe '#method_name' do
Expand All @@ -41,6 +47,12 @@

it { expect(def_node.method_name).to eq(:-@) }
end

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

it { expect(def_node.method_name).to eq(:foo) }
end
end

describe '#method?' do
Expand Down Expand Up @@ -109,6 +121,12 @@

it { expect(def_node.arguments.size).to eq(1) }
end

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

it { expect(def_node.arguments.size).to eq(2) }
end
end

describe '#first_argument' do
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -30,6 +30,10 @@
let(:ruby_version) { 2.7 }
end

RSpec.shared_context 'ruby 2.8', :ruby28 do
let(:ruby_version) { 2.8 }
end

module DefaultRubyVersion
extend RSpec::SharedContext

Expand Down

0 comments on commit 81d230e

Please sign in to comment.