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

parse_source: allow direct targetting of a node #119

Merged
merged 1 commit into from
Sep 24, 2020

Conversation

marcandre
Copy link
Contributor

@marcandre marcandre commented Sep 23, 2020

Many tests in rubocop-ast need to generate an AST from Ruby code and then select an inner node.

It is very difficult to tell when reading the test which node it is:

# before:
let(:send_node) { parse_source(source).ast.children[2].children[0] }
let(:source) do
  ['class Foo',
   '  bar :baz',
   '  bar :qux',
   'end'].join("\n")
end

With this PR, we can target a particular node by wrapping it between '>>' and '<<' and parse_source can then target it by matching the source:

# after:
let(:source) do
  ['class Foo',
   '>>bar :baz<<',
   '  bar :qux',
   'end'].join("\n")
end

@marcandre marcandre merged commit 746171c into rubocop:master Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant