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

def_node_pattern and def_node_search now return the method name. #147

Merged
merged 1 commit into from
Nov 7, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#147](https://github.com/rubocop-hq/rubocop-ast/pull/147): `def_node_pattern` and `def_node_search` now return the method name. ([@marcandre][])
2 changes: 2 additions & 0 deletions lib/rubocop/ast/node_pattern/method_definer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def def_helper(base, method_name, **defaults)
end
src = yield method_name
base.class_eval(src, location.path, location.lineno)

method_name
end

def emit_node_search(method_name)
Expand Down
13 changes: 11 additions & 2 deletions spec/rubocop/ast/node_pattern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2054,9 +2054,10 @@ def withargs(foo, bar, qux)

let(:keyword_defaults) { {} }
let(:method_name) { :my_matcher }
let(:line_no) { __LINE__ + 2 }
let(:line_no) { __LINE__ + 1 }
let(:call_helper) { MyClass.public_send helper_name, method_name, pattern, **keyword_defaults }
let(:defined_class) do
MyClass.public_send helper_name, method_name, pattern, **keyword_defaults
call_helper
MyClass
end
let(:ruby) { ':hello' }
Expand All @@ -2076,6 +2077,10 @@ def withargs(foo, bar, qux)
context 'def_node_matcher' do
let(:helper_name) { :def_node_matcher }

it 'returns the method name' do
expect(call_helper).to eq method_name
end

context 'when called on matching code' do
it { expect(instance).to match_code(node) }
end
Expand All @@ -2099,6 +2104,10 @@ def withargs(foo, bar, qux)
let(:helper_name) { :def_node_search }
let(:ruby) { 'foo(:hello, :world)' }

it 'returns the method name' do
expect(call_helper).to eq method_name
end

context('without a predicate name') do
context 'when called on matching code' do
it 'returns an enumerator yielding the matches' do
Expand Down