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
Scattered let autocorrect #903
Conversation
@Darhazer FYI the build failed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool @Darhazer ! I was thinking that maybe we could inherit Layout/ClassStructure
and provide some RSpec/Structure
with the defaults in the proper order. I remember when we opted by swapping the nodes and it would automatically adjust the spacing because the nodes do not hold the spaces.
@bquorning fixed. Sorry, I wanted to share the code with a colleague and forgot to actually run the rake task |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks @Darhazer
1afc5b3
to
1d9615b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MoveNode
is incredible!
corrector.remove(node_range_with_surrounding_space(node)) | ||
RuboCop::RSpec::Corrector::MoveNode.new( | ||
node, corrector, processed_source | ||
).move_before(first_example) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
@@ -12,6 +12,76 @@ | |||
^^^^^^^^^^^^^ Group all let/let! blocks in the example group together. | |||
end | |||
RUBY | |||
|
|||
expect_correction(<<-RUBY) | |||
RSpec.describe User do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to stress on RSpec
?
|
||
end | ||
end | ||
RUBY | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just in case, maybe add an example for let!
?
Possible conflict with #904 – or at least there’s an extra test case to autocorrect. |
1d9615b
to
9941338
Compare
Updated |
I realized that we don't have an autocorrect support for scattered let, but it's quite easy to do, as we already move nodes around.
I also refactored the autocorrect part, as I had to copy/paste 3 methods one more time, and we had enough copies already.
It seems that rubocop-rspec deals with the structure much more than rubocop itself - I found only one cop there that would benefit from the new helper, that's why I left it as part of rubocop-rspec instead.
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).If you have created a new cop:
config/default.yml
.