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

Have correctors accept node instead of range #7863

Merged
merged 2 commits into from Apr 10, 2020

Conversation

marcandre
Copy link
Contributor

This PR allows correctors to accept nodes in addition to ranges.

E.g: corrector.insert_before(node, 'blah')

Also provides better errors in case of wrong argument
Before: "undefined method `source_buffer' for 1..3:Range"
After: "Expected a Parser::Source::Range or Rubocop::AST::Node, got Range"

I don't think it would be particularly useful, but we could actually accept ranges like 1..3 if we wanted too...

This assumes #7862 is merged.

@marcandre marcandre force-pushed the correct_node branch 2 times, most recently from 5ee7276 to a363f15 Compare April 9, 2020 23:34
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 10, 2020

Might be a good idea to also mention this in the docs.

@marcandre marcandre changed the title Correct node Have correctors accept node instead of range Apr 10, 2020
@marcandre
Copy link
Contributor Author

marcandre commented Apr 10, 2020

Might be a good idea to also mention this in the docs.

I modified slightly manual/development.md but couldn't find anywhere else...

I amended the PR with simplifications using this (mostly due to accepting node, a few using wrap, sometimes both at once...)

Provide better errors in case of wrong argument
Before: "undefined method `source_buffer' for 1..3:Range"
After: "Expected a Parser::Source::Range or Rubocop::AST::Node, got Range"
@bbatsov bbatsov merged commit 9c3f904 into rubocop:master Apr 10, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 10, 2020

Nicely done! 🙇‍♂️

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.

None yet

2 participants