Skip to content
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

Add ForceEqualSignAlignment to .rubocop.yml #1190

Merged
merged 6 commits into from Oct 21, 2019

Conversation

alebruck
Copy link
Contributor

Fixes #1169 by adding cop ForceEqualSignAlignment and updating all reported issues.

For now, I had to disable SpaceAroundOperators as this cop seems to have an issue that causes an infinite loop(not possible to achieve a green state). I reported it on rubocop rubocop/rubocop#7422 and I can enable it again once this issue is resolved.

@shopmike shopmike self-requested a review October 14, 2019 07:01
@shopmike
Copy link
Contributor

@ashmaroli you raised this originally, so will await feedback

Copy link
Contributor

@ashmaroli ashmaroli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I see the extent of the damage to readability this can cause, I'm not so inclined on having this merged in the current state.
IMHO, the better alternative would be to not enforcing EqualSignAlignment globally but rather have the best of both worlds by aligning where it improves readability and forgoing the alignment if it hampers readability..

@@ -892,7 +892,7 @@ Lint/FormatParameterMismatch:
Enabled: true

Lint/HandleExceptions:
Enabled: true
AllowComments: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to edit this file since it is auto-generated using upstream data.
If this change is absolutely necessary for this PR to pass, the better alternative would be to redefine the setting in the local .rubocop.yml

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one comes down from a change to the Shopify style guide. I've been pulling this out of recent PR's

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.. Then you (@shopmike) should push this change to master directly then. It may not be ideal but a lot better than pulling the change out from multiple PRs..

Shopify could also consider shipping the Official Style Guide as a Ruby gem so that its updates do not explicitly show up in downstream repos.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the plan is to push this through as its own PR, just hasn't been a priority.

The config rarely changes and when it does I don't mind the fact it forces everyone to follow it as generally it would only be done when enough people have agreed that it applies to all projects.

unless (tag = registered_tags[tag_name])
# end parsing if we reach an unknown tag and let the caller decide
# determine how to proceed
return yield tag_name, markup
end
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
@blank &&= new_tag.blank?
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does RuboCop force this realignment if you were to revert manually and then autocorrect after?
The reason I ask is the benefits of operator-alignment is lost when there is a block of code separating two realigned lines..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only thing that breaks the behaviour is an empty line from when I was playing around with this. In cases where the formatting isn't ideal, you need to space it.

@@ -92,7 +92,7 @@ def parse(tokenizer, parse_context, &block)
end
parse_context.trim_whitespace = false
@nodelist << token
@blank &&= !!(token =~ WhitespaceOrNothing)
@blank &&= !!(token =~ WhitespaceOrNothing)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the side-effect of using automated corrections.. 😞 :
As a human, you can tell from a distance that this change significantly hampers readability instead of improving it..
(View the entire file for proper judgement).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good way to be able to find where needing to space should be done. Searching for 15+ spaces provides most of the weird auto-corrections in which case I would space

@@ -85,9 +85,9 @@ def pop_interrupt
end

def handle_error(e, line_number = nil)
e = internal_error unless e.is_a?(Liquid::Error)
e = internal_error unless e.is_a?(Liquid::Error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if you could replace single letter variables with something longer yet apt to mitigate this excess whitespace..

If its not too much trouble, I recommend that you follow this suggestion for all similar scenarios

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only issue with most of these examples is that by making the variable longer, the next line is usually the same variable but accessing long method names or nested methods.

Copy link
Contributor Author

@alebruck alebruck Oct 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we keep this cop and try to address these cases individually by small refactoring to improve readability or should we postpone the enforcement of this cop?

@alebruck
Copy link
Contributor Author

Now that I see the extent of the damage to readability this can cause, I'm not so inclined on having this merged in the current state.
IMHO, the better alternative would be to not enforcing EqualSignAlignment globally but rather have the best of both worlds by aligning where it improves readability and forgoing the alignment if it hampers readability..

As now we have a reference on all equal alignments in the code base, should we revert the ForceEqualSignAlignment cop and leave all the changes that make sense(reverting cases that don't bring much benefit)?

@ashmaroli
Copy link
Contributor

should we revert the ForceEqualSignAlignment cop and leave all the changes that make sense

@alebruck I would prefer that if you don't mind the extra effort. Either ways, I'm thankful that you attempted to resolve this issue.

@alebruck
Copy link
Contributor Author

@ashmaroli Could you please check this one again? No new cops but the alignment improvements required for the cop are already here. I would leave any refactoring related to var name in a different PR as it looks like we could use more refactoring than just renaming.

@ashmaroli
Copy link
Contributor

@alebruck I had sent you a PR on your fork: alebruck#1
Did you not see that?

@alebruck
Copy link
Contributor Author

@ashmaroli oh, somehow I got no notification from that, sorry about that 😅

@ashmaroli
Copy link
Contributor

@shopmike My concerns have been addressed.
Requesting a re-review and a squash-merge..

tokens = []
while (t = tokenizer.shift)
tokens = []
while (t = tokenizer.shift)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about the only one that doesn't seem to make sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I missed that! 😛
It should be something like:

    tokenizer = Liquid::Tokenizer.new(source)
    tokens    = []

    while (t = tokenizer.shift)

I can't push to this branch directly,.. so its your call..

@shopmike
Copy link
Contributor

Awesome thanks for resolving this outstanding issue @ashmaroli @alebruck . Also congrats on your first contribution to Liquid @alebruck 🎉

@shopmike shopmike merged commit e83b1e4 into Shopify:master Oct 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix equal alignment in ruby styling
3 participants