-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
expect_correction with loop #8062
Conversation
end | ||
|
||
# Prepare for next loop | ||
cop.instance_variable_set(:@corrections, []) |
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.
This bit is ugly! Is there another way to accomplish the same thing?
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.
It also won't work after #7868 lands...
d1f3649
to
bdbc534
Compare
In some places, we spec what happens after one auto-correct iteration and what happens after _many_ auto-correct iterations.
bdbc534
to
856e421
Compare
@pirj Maybe you want to take a look at this PR? |
API-wise, I like that it's very convenient; I wonder if it would it better to also spec the intermediate steps? E.g. expect_offense(<<~RUBY)
# ... code with offense
RUBY
expect_correction_offense(<<~RUBY)
# ... corrected code with offense
RUBY
expect_correction(<<~RUBY)
# ... final corrected code without offense
RUBY One advantage I see is that it makes it clear how the final correction is had. Also it specs what happens if someone entered the intermediate code for some reason. Maybe that's too strict or verbose though? |
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.
Don't see any flaws 👍
|
||
def expect_correction(correction) | ||
def expect_correction(correction, loop: false) |
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.
What are the implications of always using loop: true
?
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.
rspec
execution time didn't change with loop: true
(I've actually removed this parameter and removed loop: true
around the code.
I've faced an RuboCop::Runner::InfiniteCorrectionLoop
and some other spec failures. Is this due to disagreeing cops?
I still feel this raises questions:
|
I think it's best to discuss them in a dedicated ticket. This PR improves the status quo, which is why I decided to merge it, but I agree that there's plenty of room for improvement. |
In some places, we spec what happens after
one
auto-correct iteration, and in some places we spec what happens after many auto-correct iterations.As mentioned in #8003, there is no longer any reason to use helpers like
autocorrect_source_with_loop
. This PR removes that method and all our uses of it.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.