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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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.


Lint/ImplicitStringConcatenation:
Description: Checks for adjacent string literals on the same line, which could
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -11,7 +11,7 @@ desc('run test suite with default parser')
Rake::TestTask.new(:base_test) do |t|
t.libs << '.' << 'lib' << 'test'
t.test_files = FileList['test/{integration,unit}/**/*_test.rb']
t.verbose = false
t.verbose = false
end

desc('run test suite with warn error mode')
Expand Down
6 changes: 3 additions & 3 deletions example/server/liquid_servlet.rb
Expand Up @@ -12,16 +12,16 @@ def do_POST(req, res)
private

def handle(_type, req, res)
@request = req
@request = req
@response = res

@request.path_info =~ /(\w+)\z/
@action = Regexp.last_match(1) || 'index'
@action = Regexp.last_match(1) || 'index'
@assigns = send(@action) if respond_to?(@action)

@response['Content-Type'] = "text/html"
@response.status = 200
@response.body = Liquid::Template.parse(read_template).render(@assigns, filters: [ProductsFilter])
@response.body = Liquid::Template.parse(read_template).render(@assigns, filters: [ProductsFilter])
end

def read_template(filename = @action)
Expand Down
16 changes: 8 additions & 8 deletions lib/liquid/block_body.rb
Expand Up @@ -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)
Expand All @@ -35,7 +35,7 @@ def parse(tokenizer, parse_context, &block)
return yield token, token
end
tag_name = Regexp.last_match(1)
markup = Regexp.last_match(2)
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
Expand All @@ -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,
Expand Down
13 changes: 7 additions & 6 deletions lib/liquid/condition.rb
Expand Up @@ -35,10 +35,11 @@ def self.operators
attr_accessor :left, :operator, :right

def initialize(left = nil, operator = nil, right = nil)
@left = left
@left = left
@operator = operator
@right = right
@child_relation = nil
@right = right

@child_relation = nil
@child_condition = nil
end

Expand All @@ -62,12 +63,12 @@ def evaluate(context = Context.new)
end

def or(condition)
@child_relation = :or
@child_relation = :or
@child_condition = condition
end

def and(condition)
@child_relation = :and
@child_relation = :and
@child_condition = condition
end

Expand Down Expand Up @@ -115,7 +116,7 @@ def interpret_condition(left, right, op, context)
# return this as the result.
return context.evaluate(left) if op.nil?

left = context.evaluate(left)
left = context.evaluate(left)
right = context.evaluate(right)

operation = self.class.operators[op] || raise(Liquid::ArgumentError, "Unknown operator #{op}")
Expand Down
14 changes: 7 additions & 7 deletions lib/liquid/context.rb
Expand Up @@ -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
Expand Down Expand Up @@ -87,7 +87,7 @@ def pop_interrupt
def handle_error(e, line_number = nil)
e = internal_error unless e.is_a?(Liquid::Error)
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
Expand Down Expand Up @@ -138,11 +138,11 @@ 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.filters = @filters
subcontext.strainer = nil
subcontext.errors = errors
subcontext.errors = errors
subcontext.warnings = warnings
end
end
Expand Down Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions lib/liquid/errors.rb
Expand Up @@ -40,19 +40,19 @@ def message_prefix
end
end

ArgumentError = Class.new(Error)
ContextError = Class.new(Error)
FileSystemError = Class.new(Error)
StandardError = Class.new(Error)
SyntaxError = Class.new(Error)
StackLevelError = Class.new(Error)
TaintedError = Class.new(Error)
MemoryError = Class.new(Error)
ZeroDivisionError = Class.new(Error)
FloatDomainError = Class.new(Error)
UndefinedVariable = Class.new(Error)
ArgumentError = Class.new(Error)
ContextError = Class.new(Error)
FileSystemError = Class.new(Error)
StandardError = Class.new(Error)
SyntaxError = Class.new(Error)
StackLevelError = Class.new(Error)
TaintedError = Class.new(Error)
MemoryError = Class.new(Error)
ZeroDivisionError = Class.new(Error)
FloatDomainError = Class.new(Error)
UndefinedVariable = Class.new(Error)
UndefinedDropMethod = Class.new(Error)
UndefinedFilter = Class.new(Error)
UndefinedFilter = Class.new(Error)
MethodOverrideError = Class.new(Error)
InternalError = Class.new(Error)
InternalError = Class.new(Error)
end
2 changes: 1 addition & 1 deletion lib/liquid/file_system.rb
Expand Up @@ -47,7 +47,7 @@ class LocalFileSystem
attr_accessor :root

def initialize(root, pattern = "_%s.liquid")
@root = root
@root = root
@pattern = pattern
end

Expand Down
6 changes: 3 additions & 3 deletions lib/liquid/forloop_drop.rb
Expand Up @@ -3,10 +3,10 @@
module Liquid
class ForloopDrop < Drop
def initialize(name, length, parentloop)
@name = name
@length = length
@name = name
@length = length
@parentloop = parentloop
@index = 0
@index = 0
end

attr_reader :name, :length, :parentloop
Expand Down
12 changes: 6 additions & 6 deletions lib/liquid/lexer.rb
Expand Up @@ -15,12 +15,12 @@ class Lexer
'?' => :question,
'-' => :dash,
}.freeze
IDENTIFIER = /[a-zA-Z_][\w-]*\??/
IDENTIFIER = /[a-zA-Z_][\w-]*\??/
SINGLE_STRING_LITERAL = /'[^\']*'/
DOUBLE_STRING_LITERAL = /"[^\"]*"/
NUMBER_LITERAL = /-?\d+(\.\d+)?/
DOTDOT = /\.\./
COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains(?=\s)/
NUMBER_LITERAL = /-?\d+(\.\d+)?/
DOTDOT = /\.\./
COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains(?=\s)/
WHITESPACE_OR_NOTHING = /\s*/

def initialize(input)
Expand All @@ -33,7 +33,7 @@ def tokenize
until @ss.eos?
@ss.skip(WHITESPACE_OR_NOTHING)
break if @ss.eos?
tok = if (t = @ss.scan(COMPARISON_OPERATOR))
tok = if (t = @ss.scan(COMPARISON_OPERATOR))
[:comparison, t]
elsif (t = @ss.scan(SINGLE_STRING_LITERAL))
[:string, t]
Expand All @@ -46,7 +46,7 @@ def tokenize
elsif (t = @ss.scan(DOTDOT))
[:dotdot, t]
else
c = @ss.getch
c = @ss.getch
if (s = SPECIALS[c])
[s, c]
else
Expand Down
7 changes: 5 additions & 2 deletions lib/liquid/parse_context.rb
Expand Up @@ -7,9 +7,11 @@ class ParseContext

def initialize(options = {})
@template_options = options ? options.dup : {}
@locale = @template_options[:locale] ||= I18n.new

@locale = @template_options[:locale] ||= I18n.new
@warnings = []
self.depth = 0

self.depth = 0
self.partial = false
end

Expand All @@ -20,6 +22,7 @@ def [](option_key)
def partial=(value)
@partial = value
@options = value ? partial_options : @template_options

@error_mode = @options[:error_mode] || Template.error_mode
end

Expand Down
2 changes: 1 addition & 1 deletion lib/liquid/parse_tree_visitor.rb
Expand Up @@ -11,7 +11,7 @@ def self.for(node, callbacks = Hash.new(proc {}))
end

def initialize(node, callbacks)
@node = node
@node = node
@callbacks = callbacks
end

Expand Down
4 changes: 2 additions & 2 deletions lib/liquid/parser.rb
Expand Up @@ -3,9 +3,9 @@
module Liquid
class Parser
def initialize(input)
l = Lexer.new(input)
l = Lexer.new(input)
@tokens = l.tokenize
@p = 0 # pointer to current location
@p = 0 # pointer to current location
end

def jump(point)
Expand Down
2 changes: 1 addition & 1 deletion lib/liquid/parser_switching.rb
Expand Up @@ -21,7 +21,7 @@ def parse_with_selected_parser(markup)
def strict_parse_with_error_context(markup)
strict_parse(markup)
rescue SyntaxError => e
e.line_number = line_number
e.line_number = line_number
e.markup_context = markup_context(markup)
raise e
end
Expand Down
3 changes: 2 additions & 1 deletion lib/liquid/partial_cache.rb
Expand Up @@ -8,7 +8,8 @@ def self.load(template_name, context:, parse_context:)
return cached if cached

file_system = (context.registers[:file_system] ||= Liquid::Template.file_system)
source = file_system.read_template_file(template_name)
source = file_system.read_template_file(template_name)

parse_context.partial = true

partial = Liquid::Template.parse(source, parse_context)
Expand Down
6 changes: 3 additions & 3 deletions lib/liquid/profiler.rb
Expand Up @@ -64,7 +64,7 @@ def start
end

def finish
@end_time = Time.now
@end_time = Time.now
@total_time = @end_time - @start_time

if @children.empty?
Expand Down Expand Up @@ -112,11 +112,11 @@ def self.current_profile
def initialize(partial_name = "<root>")
@partial_stack = [partial_name]

@root_timing = Timing.new("", current_partial)
@root_timing = Timing.new("", current_partial)
@timing_stack = [@root_timing]

@render_start_at = Time.now
@render_end_at = @render_start_at
@render_end_at = @render_start_at
end

def start
Expand Down
6 changes: 3 additions & 3 deletions lib/liquid/range_lookup.rb
Expand Up @@ -4,7 +4,7 @@ module Liquid
class RangeLookup
def self.parse(start_markup, end_markup)
start_obj = Expression.parse(start_markup)
end_obj = Expression.parse(end_markup)
end_obj = Expression.parse(end_markup)
if start_obj.respond_to?(:evaluate) || end_obj.respond_to?(:evaluate)
new(start_obj, end_obj)
else
Expand All @@ -14,12 +14,12 @@ def self.parse(start_markup, end_markup)

def initialize(start_obj, end_obj)
@start_obj = start_obj
@end_obj = end_obj
@end_obj = end_obj
end

def evaluate(context)
start_int = to_integer(context.evaluate(@start_obj))
end_int = to_integer(context.evaluate(@end_obj))
end_int = to_integer(context.evaluate(@end_obj))
start_int..end_int
end

Expand Down
2 changes: 1 addition & 1 deletion lib/liquid/registers/disabled_tags.rb
Expand Up @@ -20,7 +20,7 @@ def disable(tags)

def increment(tag)
@disabled_tags[tag] ||= 0
@disabled_tags[tag] += 1
@disabled_tags[tag] += 1
end

def decrement(tag)
Expand Down
4 changes: 2 additions & 2 deletions lib/liquid/resource_limits.rb
Expand Up @@ -7,8 +7,8 @@ class ResourceLimits

def initialize(limits)
@render_length_limit = limits[:render_length_limit]
@render_score_limit = limits[:render_score_limit]
@assign_score_limit = limits[:assign_score_limit]
@render_score_limit = limits[:render_score_limit]
@assign_score_limit = limits[:assign_score_limit]
reset
end

Expand Down