[Fix #8642] Fix a false negative for Style/SpaceInsideHashLiteralBraces
when a correct empty hash precedes the incorrect hash
#8649
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #8642.
I'm not 100% sure I understand what
ConfigurableEnforcedStyle
is doing (it'd be great if it could have more documentation added!), but the problem here is that the detected style was flipping betweenspace
andnospace
depending on which hash was being evaluated. The fix is to just pass the definedstyle
toambiguous_or_unexpected_style_detected
rather than trying to calculate it.Consider the following code (which is also added as a test):
ConfigurableEnforcedStyle
) isnil
. Because the spacing for the empty has is correct,correct_style_detected
is called, which setsdetected_as_strings
andupdated_list
to['space']
(since that is theEnforcedStyle
value).check
method, it detects an offense and runsincorrect_style_detected
. At this point, a space is requiredno_space
is passed toambiguous_or_unexpected_style_detected
. Because of this,updated_list
is set to the intersection of[space]
and[no_space]
, which is[]
, andno_acceptable_style!
is called. The offense gets registered (and corrected).no_acceptable_style?
returns true, andstyle_detected
short-circuits. This causesincorrect_style_detected
to return before adding an offense, and all further hash spacing issues are ignored in the file.My change is to not override style but pass in the style from config on both
correct_style_detected
andincorrect_style_detected
, which preventsno_acceptable_style?
from short-circuiting further offense detection. None of the other code or existing tests had to be changed.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.