diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ef4ad28c..0b44f1a16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/rubocop/ast/builder.rb b/lib/rubocop/ast/builder.rb index f360d8731..d85a24ab5 100644 --- a/lib/rubocop/ast/builder.rb +++ b/lib/rubocop/ast/builder.rb @@ -26,6 +26,7 @@ class Builder < Parser::Builders::Default case: CaseNode, class: ClassNode, def: DefNode, + def_e: DefNode, defined?: DefinedNode, defs: DefNode, ensure: EnsureNode, diff --git a/spec/rubocop/ast/def_node_spec.rb b/spec/rubocop/ast/def_node_spec.rb index 3aba8082e..7c8bff7d4 100644 --- a/spec/rubocop/ast/def_node_spec.rb +++ b/spec/rubocop/ast/def_node_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 919b63dc3..b605d907c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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