Fix rubocop offenses

This commit is contained in:
Guilherme Carreiro
2026-03-06 16:18:00 +01:00
parent 19458fbc45
commit 2635245329
3 changed files with 14 additions and 16 deletions
+8 -8
View File
@@ -108,12 +108,12 @@ module Liquid
next unless token.start_with?("{%") next unless token.start_with?("{%")
j = 2 j = 2
j += 1 if token.getbyte(j) == 45 # '-' j += 1 if token.getbyte(j) == 45 # '-'
j += 1 while token.getbyte(j) == 32 # ' ' j += 1 while token.getbyte(j) == 32 # ' '
if token.getbyte(j) == 101 && # 'e' if token.getbyte(j) == 101 && # 'e'
token.getbyte(j + 1) == 110 && # 'n' token.getbyte(j + 1) == 110 && # 'n'
token.getbyte(j + 2) == 100 # 'd' token.getbyte(j + 2) == 100 # 'd'
has_any_end_tag = true has_any_end_tag = true
break break
end end
@@ -133,7 +133,7 @@ module Liquid
# Advance past "{%", optional "-", and spaces to reach tag name # Advance past "{%", optional "-", and spaces to reach tag name
j = 2 j = 2
j += 1 if token.getbyte(j) == 45 # '-' j += 1 if token.getbyte(j) == 45 # '-'
j += 1 while token.getbyte(j) == 32 # ' ' j += 1 while token.getbyte(j) == 32 # ' '
# Extract tag name: scan word characters [a-zA-Z0-9_] # Extract tag name: scan word characters [a-zA-Z0-9_]
@@ -142,18 +142,18 @@ module Liquid
while byte && ((byte >= 97 && byte <= 122) || # a-z while byte && ((byte >= 97 && byte <= 122) || # a-z
(byte >= 65 && byte <= 90) || # A-Z (byte >= 65 && byte <= 90) || # A-Z
(byte >= 48 && byte <= 57) || # 0-9 (byte >= 48 && byte <= 57) || # 0-9
byte == 95) # _ byte == 95) # _
j += 1 j += 1
byte = token.getbyte(j) byte = token.getbyte(j)
end end
next if j == name_start # no tag name found next if j == name_start # no tag name found
name = token.byteslice(name_start, j - name_start) name = token.byteslice(name_start, j - name_start)
if name.start_with?("end") if name.start_with?("end")
base = name.byteslice(3, name.bytesize - 3) base = name.byteslice(3, name.bytesize - 3)
stack = open_stacks[base] stack = open_stacks[base]
if stack.length > 0 unless stack.empty?
open_pos = stack.pop open_pos = stack.pop
@has_matching_end_tag[open_pos] = true @has_matching_end_tag[open_pos] = true
end end
+4 -6
View File
@@ -151,14 +151,12 @@ Benchmark.ips do |x|
x.config(time: 10, warmup: 5) x.config(time: 10, warmup: 5)
TEMPLATES.each do |label, source| TEMPLATES.each do |label, source|
begin Liquid::Template.parse(source, environment: env)
x.report("parse: #{label}") do
Liquid::Template.parse(source, environment: env) Liquid::Template.parse(source, environment: env)
x.report("parse: #{label}") do
Liquid::Template.parse(source, environment: env)
end
rescue Liquid::SyntaxError => e
puts " Skipping '#{label}' - #{e.message}"
end end
rescue Liquid::SyntaxError => e
puts " Skipping '#{label}' - #{e.message}"
end end
x.compare! x.compare!
+2 -2
View File
@@ -108,7 +108,7 @@ class TokenizerTest < Minitest::Test
def test_matching_end_tag_handles_nested_same_name_tags def test_matching_end_tag_handles_nested_same_name_tags
tokenizer = new_tokenizer( tokenizer = new_tokenizer(
'{% render "a" %}{% render "b" %}inner{% endrender %}outer{% endrender %}' '{% render "a" %}{% render "b" %}inner{% endrender %}outer{% endrender %}',
) )
tokenizer.send(:shift) # {% render "a" %} tokenizer.send(:shift) # {% render "a" %}
# Should find the outer endrender (depth-aware), not the inner one # Should find the outer endrender (depth-aware), not the inner one
@@ -126,7 +126,7 @@ class TokenizerTest < Minitest::Test
def test_matching_end_tag_returns_false_when_only_nested_end_tag def test_matching_end_tag_returns_false_when_only_nested_end_tag
# Only a nested endrender exists (consumed by the inner render), no outer endrender # Only a nested endrender exists (consumed by the inner render), no outer endrender
tokenizer = new_tokenizer( tokenizer = new_tokenizer(
'{% render "a" %}{% render "b" %}{% endrender %}' '{% render "a" %}{% render "b" %}{% endrender %}',
) )
tokenizer.send(:shift) # {% render "a" %} tokenizer.send(:shift) # {% render "a" %}
# The endrender belongs to the inner render (depth 1 -> 0), not the outer (depth 0) # The endrender belongs to the inner render (depth 1 -> 0), not the outer (depth 0)