-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Style/LambdaCall skips subsequent checks after finding a violation #9225
Comments
@sswander You should move as if offense?(node)
add_offense(node) do |corrector|
opposite_style_detected
autocorrect(corrector, node)
end
else
correct_style_detected
end and add a test case with producing 2 violations at the same time. |
@fatkodima nice, thanks for the pointer! I'll give this a try 👍 |
sswander
added a commit
to sswander/rubocop
that referenced
this issue
Dec 18, 2020
- The Cop used to ignore all violations after encountering an opposite style because during the first encounter, we set no_acceptable_style! and in the next iterations we early returned nil for opposite_style_detected check. This caused the Cop to never got around to adding the offense - This fixed the behaviour by letting the Cop add the offense first before checking for opposite_style_detected - Specs updated to illustrate the multiple opposite style scenario
8 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My colleague @kelvinngsl and I might have found an unexpected behaviour in
Style/LambdaCall
. It might also be related to Style/LambdaCall's implementation ofConfigurableEnforcedStyle
mixin.With
EnforcedStyle: braces
, when the firstblk.call
is found, it is reported as an offense, but all subsequent code that violates the braces code style got skipped.With
EnforcedStyle: call
, when the firstblk.()
is found, it is reported as an offense, but all subsequent code that violates the braces code style got skipped.I have included example and steps to reproduce in the section below.
Some finding that might be helpful:
opposite_style_detected
inlib/rubocop/cop/style/lambda_call.rb
. Once an opposite style is detected, theConfigurableEnforcedStyle
mixin turned the config into{ 'Enabled' => false }
, thus ignoring any subsequent violations.If this is indeed an issue, I am willing to give fixing it a try. However I'm not really sure where to start, so some pointer would be appreciated 🙇
(1.5.2)
.Expected behavior
RuboCop should detect all
blk.call
violations whenEnforcedStyle: braces
. Conversely, RuboCop should detect allblk.()
violations whenEnforcedStyle: call
.Actual behavior
It seems that once RuboCop found the first violation, the rest of the violations get ignored, so not all of the violations end up getting reported.
Steps to reproduce the problem
The following example illustrates an exaggeration of the unexpected behaviour by adding an inline disable. The root cause should be as reported above, which is RuboCop ignoring subsequent violations.
The following example uses
EnforcedStyle: braces
. However, the same behaviour also happens withEnforcedStyle: call
and when the codebase uses the opposite pattern.rubocop.yml:
test.rb:
RuboCop result:
RuboCop version
The text was updated successfully, but these errors were encountered: