-
-
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
Fix Layout/AlignHash when mixed Hash styles are used #7068
Fix Layout/AlignHash when mixed Hash styles are used #7068
Conversation
a657a25
to
c9c64a8
Compare
c9c64a8
to
ea22a4e
Compare
@@ -102,7 +102,7 @@ def key_delta(first_pair, current_pair) | |||
end | |||
|
|||
def hash_rocket_delta(first_pair, current_pair) | |||
first_pair.loc.column + max_key_width + 1 - | |||
first_pair.loc.column + max_key_width.to_i + 1 - |
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.
Why isn't this a number in the first place? Probably we can convert it earlier and this would yield slightly better code.
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.
Fair question. I found this code to be a tad hard to follow. This value is initialized to nil as an attr_accessor, and its usage expects deltas_for_first_pair
to have been called first, but it apparently wasn’t under the particular scenario that caused the error.
Are you asking for an initializer that initializes this value to zero?
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.
To clarify, for now, I’m just trying to keep the bug fix as small as possible considering there might be other syntax scenarios that we haven’t considered yet for the new AlignHash features.
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’s probably related to AlignHash
now being able to use a mix of e.g. TableAlignment
and KeyAlignment
, leading to – as you mention – TableAlignment#deltas_for_first_pair
not being called before accessing max_key_width
, and thus doing calculations with nil
…
I agree that defaulting to 0
would be a good approach here.
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.
Okay, I'll add a constructor to default the value to zero. Stand by.
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.
Suggested changes pushed.
d616788
to
9b073e6
Compare
Thanks! |
Fixes #7066. Otherwise, this happens when mixed hash styles are used:
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.