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
Changes from 1 commit
21b3c40
870a0ae
e31ea0f
d562510
60542c6
35bd54f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,18 @@ | |
|
||
module Liquid | ||
class BlockBody | ||
LiquidTagToken = /\A\s*(\w+)\s*(.*?)\z/o | ||
FullToken = /\A#{TagStart}#{WhitespaceControl}?(\s*)(\w+)(\s*)(.*?)#{WhitespaceControl}?#{TagEnd}\z/om | ||
ContentOfVariable = /\A#{VariableStart}#{WhitespaceControl}?(.*?)#{WhitespaceControl}?#{VariableEnd}\z/om | ||
LiquidTagToken = /\A\s*(\w+)\s*(.*?)\z/o | ||
FullToken = /\A#{TagStart}#{WhitespaceControl}?(\s*)(\w+)(\s*)(.*?)#{WhitespaceControl}?#{TagEnd}\z/om | ||
ContentOfVariable = /\A#{VariableStart}#{WhitespaceControl}?(.*?)#{WhitespaceControl}?#{VariableEnd}\z/om | ||
WhitespaceOrNothing = /\A\s*\z/ | ||
TAGSTART = "{%" | ||
VARSTART = "{{" | ||
TAGSTART = "{%" | ||
VARSTART = "{{" | ||
|
||
attr_reader :nodelist | ||
|
||
def initialize | ||
@nodelist = [] | ||
@blank = true | ||
@blank = true | ||
end | ||
|
||
def parse(tokenizer, parse_context, &block) | ||
|
@@ -34,15 +34,15 @@ def parse(tokenizer, parse_context, &block) | |
# caller raise a syntax error | ||
return yield token, token | ||
end | ||
tag_name = Regexp.last_match(1) | ||
markup = Regexp.last_match(2) | ||
tag_name = Regexp.last_match(1) | ||
markup = Regexp.last_match(2) | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
@blank &&= new_tag.blank? | ||
@nodelist << new_tag | ||
end | ||
parse_context.line_number = tokenizer.line_number | ||
|
@@ -61,7 +61,7 @@ def parse(tokenizer, parse_context, &block) | |
raise_missing_tag_terminator(token, parse_context) | ||
end | ||
tag_name = Regexp.last_match(2) | ||
markup = Regexp.last_match(4) | ||
markup = Regexp.last_match(4) | ||
|
||
if parse_context.line_number | ||
# newlines inside the tag should increase the line number, | ||
|
@@ -79,8 +79,8 @@ def parse(tokenizer, parse_context, &block) | |
# 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) | ||
@blank &&= new_tag.blank? | ||
@nodelist << new_tag | ||
when token.start_with?(VARSTART) | ||
whitespace_handler(token, parse_context) | ||
|
@@ -92,7 +92,7 @@ def parse(tokenizer, parse_context, &block) | |
end | ||
parse_context.trim_whitespace = false | ||
@nodelist << token | ||
@blank &&= !!(token =~ WhitespaceOrNothing) | ||
@blank &&= !!(token =~ WhitespaceOrNothing) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the side-effect of using automated corrections.. 😞 : There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
end | ||
parse_context.line_number = tokenizer.line_number | ||
end | ||
|
@@ -121,7 +121,7 @@ def render(context) | |
def render_to_output_buffer(context, output) | ||
context.resource_limits.render_score += @nodelist.length | ||
|
||
idx = 0 | ||
idx = 0 | ||
while (node = @nodelist[idx]) | ||
previous_output_size = output.bytesize | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,8 @@ def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_erro | |
self.exception_renderer = ->(_e) { raise } | ||
end | ||
|
||
@interrupts = [] | ||
@filters = [] | ||
@interrupts = [] | ||
@filters = [] | ||
@global_filter = nil | ||
end | ||
# rubocop:enable Metrics/ParameterLists | ||
|
@@ -60,7 +60,7 @@ def strainer | |
# Note that this does not register the filters with the main Template object. see <tt>Template.register_filter</tt> | ||
# for that | ||
def add_filters(filters) | ||
filters = [filters].flatten.compact | ||
filters = [filters].flatten.compact | ||
@filters += filters | ||
@strainer = nil | ||
end | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
e.template_name ||= template_name | ||
e.line_number ||= line_number | ||
e.line_number ||= line_number | ||
errors.push(e) | ||
exception_renderer.call(e).to_s | ||
end | ||
|
@@ -138,12 +138,12 @@ def new_isolated_subcontext | |
static_environments: static_environments, | ||
registers: StaticRegisters.new(registers) | ||
).tap do |subcontext| | ||
subcontext.base_scope_depth = base_scope_depth + 1 | ||
subcontext.base_scope_depth = base_scope_depth + 1 | ||
subcontext.exception_renderer = exception_renderer | ||
subcontext.filters = @filters | ||
subcontext.strainer = nil | ||
subcontext.errors = errors | ||
subcontext.warnings = warnings | ||
subcontext.filters = @filters | ||
subcontext.strainer = nil | ||
subcontext.errors = errors | ||
subcontext.warnings = warnings | ||
end | ||
end | ||
|
||
|
@@ -188,7 +188,7 @@ def find_variable(key, raise_on_not_found: true) | |
try_variable_find_in_environments(key, raise_on_not_found: raise_on_not_found) | ||
end | ||
|
||
variable = variable.to_liquid | ||
variable = variable.to_liquid | ||
variable.context = self if variable.respond_to?(:context=) | ||
|
||
variable | ||
|
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.
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
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 one comes down from a change to the Shopify style guide. I've been pulling this out of recent PR's
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.
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.
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.
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.