Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .ameba.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Lint/NotNil:
Enabled: false
Lint/MissingBlockArgument:
Enabled: true
Documentation/DocumentationAdmonition:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false

14 changes: 12 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Download source
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Crystal
uses: crystal-lang/install-crystal@v1
- name: Check formatting
Expand All @@ -27,4 +27,14 @@ jobs:
run: shards update
- name: Run tests
run: crystal spec --order=random
if: matrix.os == 'ubuntu-latest'
ameba:
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Download source
uses: actions/checkout@v4
- name: Run ameba linter
uses: crystal-ameba/github-action@v0.12.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion spec/integration/integration_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GoldenTest

private def context : Liquid::Context
vars = @context.as_h?
raise "Bad context: #{@context.to_s}" if vars.nil?
raise "Bad context: #{@context}" if vars.nil?

# Golden liquid run ruby tests with `render!`, that raises an exception on first error, this is the strict behavior
# of liquid crystal.
Expand Down
10 changes: 5 additions & 5 deletions src/liquid/blank.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ require "./drop"

module Liquid
class Blank < Drop
def ==(str : String)
str.empty?
def ==(other : String)
other.empty?
end

def ==(array : Array)
array.empty?
def ==(other : Array)
other.empty?
end

def ==(_nil : Nil)
def ==(other : Nil)
true
end

Expand Down
2 changes: 1 addition & 1 deletion src/liquid/blocks/for.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Liquid::Block
@loop_var = gmatch["var"]
@loop_over = if rmatch = gmatch["range"].match(RANGE)
rmatch["start"].to_i..rmatch["end"].to_i
elsif (rmatch = gmatch["range"].match VARNAME)
elsif rmatch = gmatch["range"].match VARNAME
rmatch["varname"]
else
raise SyntaxError.new("Invalid for node: #{content}.")
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/blocks/include.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Liquid::Block
varname = File.basename(@template_name, File.extname(@template_name))
@template_vars[varname] = Expression.new match["value"]
elsif groups = content.scan INCLUDE_VARS
groups.each do |group|
groups.each do |_|
next if groups.empty?

groups.each do |group|
Expand Down
12 changes: 6 additions & 6 deletions src/liquid/drop.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ module Liquid
end

class String
def ==(any : Liquid::Drop)
any == self
def ==(other : Liquid::Drop)
other == self
end
end

struct Nil
def ==(any : Liquid::Drop)
any == self
def ==(other : Liquid::Drop)
other == self
end
end

class Array
def ==(any : Liquid::Drop)
any == self
def ==(other : Liquid::Drop)
other == self
end
end
6 changes: 3 additions & 3 deletions src/liquid/expression.cr
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ module Liquid
private def apply_filters(ctx : Context, operand : Any, filter_stack : Stack?) : Any
return operand if filter_stack.nil?

while filter_stack.any?
while !filter_stack.empty?
item = filter_stack.shift
return expression_error(ctx, "Expected a filter, got #{item}.") if !item.is_a?(Operator) || !item.filter?

Expand Down Expand Up @@ -184,7 +184,7 @@ module Liquid
filter_args = ctx.filter_args
filter_options = ctx.filter_options

while stack.any?
while !stack.empty?
item = stack.first
return if item.is_a?(Operator) && item.filter?

Expand Down Expand Up @@ -218,7 +218,7 @@ module Liquid
raw = obj.raw
return call_drop_method(ctx, raw, method) if raw.is_a?(Drop)
return call_hash_method(ctx, raw, method) if raw.is_a?(Hash)
return call_nil_method(ctx, method) if raw.is_a?(Nil)
return call_nil_method(ctx, method) if raw.nil?

return expression_error(ctx, "Tried to call ##{method} on a #{raw.class.name}.") if !raw.responds_to?(:size)

Expand Down
2 changes: 1 addition & 1 deletion src/liquid/filters/abs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Liquid::Filters
extend Filter

def self.filter(data : Any, args : Array(Any), options : Hash(String, Any)) : Any
raise FilterArgumentException.new("Unexpected argument for abs filter") if args && args.any?
raise FilterArgumentException.new("Unexpected argument for abs filter") unless args.empty?

if data.raw.is_a? Number
Any.new data.raw.as(Number).abs
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/filters/arg_test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Liquid::Filters
extend Filter

def self.filter(data : Any, args : Array(Any), options : Hash(String, Any)) : Any
if (a = args)
if a = args
Any.new(a.map(&.to_s).join(", "))
else
Any.new(nil)
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/filters/capitalize.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Liquid::Filters
extend Filter

def self.filter(data : Any, args : Array(Any), options : Hash(String, Any)) : Any
raise FilterArgumentException.new("Unexpected argument for capitalize filter") if args && args.any?
raise FilterArgumentException.new("Unexpected argument for capitalize filter") unless args.empty?

raw = data.raw
if raw.is_a?(String)
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/filters/ceil.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Liquid::Filters
extend Filter

def self.filter(data : Any, args : Array(Any), options : Hash(String, Any)) : Any
raise FilterArgumentException.new("Unexpected argument for ceil filter") if args && args.any?
raise FilterArgumentException.new("Unexpected argument for ceil filter") unless args.empty?

if (raw = data.raw) && raw.is_a? Number
Any.new(raw.ceil.to_i)
Expand Down
4 changes: 2 additions & 2 deletions src/liquid/filters/date.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ module Liquid::Filters
def self.filter(data : Any, args : Array(Any), options : Hash(String, Any)) : Any
raise FilterArgumentException.new "date filter require an argument" unless args && args.size == 1

format = if (arg = args.first.as_s?)
format = if arg = args.first.as_s?
arg
else
raise FilterArgumentException.new "First argument of date filter should be a string"
end

if (time = data.as_t?)
if time = data.as_t?
Any.new time.to_s format
elsif (d = data.as_s?) && d == "now"
Any.new Time.utc.to_s format
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/filters/downcase.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Liquid::Filters
extend Filter

def self.filter(data : Any, args : Array(Any), options : Hash(String, Any)) : Any
raise FilterArgumentException.new("downcase filter expects no arguments.") if args.any?
raise FilterArgumentException.new("downcase filter expects no arguments.") unless args.empty?

raw = data.raw
if raw.responds_to?(:downcase)
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/filters/floor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Liquid::Filters
extend Filter

def self.filter(data : Any, args : Array(Any), options : Hash(String, Any)) : Any
raise FilterArgumentException.new("Unexpected argument for floor filter") if args && args.any?
raise FilterArgumentException.new("Unexpected argument for floor filter") unless args.empty?

if (raw = data.raw) && raw.is_a? Number
Any.new(raw.floor.to_i)
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/filters/lstrip.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Liquid::Filters
extend Filter

def self.filter(data : Any, args : Array(Any), options : Hash(String, Any)) : Any
if (str = data.as_s?)
if str = data.as_s?
Any.new str.lstrip
else
data
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/filters/map.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Liquid::Filters
raise FilterArgumentException.new "map filter expects argument to be a string" unless args.first.raw.is_a?(String)

if (raw = data.raw) && raw.is_a?(Array) && (first = args.first?)
result = raw.compact_map { |r| self.responds_to(r, first.as_s) }
result = raw.compact_map { |obj| self.responds_to(obj, first.as_s) }
if result.empty?
data
else
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/filters/rstrip.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Liquid::Filters
extend Filter

def self.filter(data : Any, args : Array(Any), options : Hash(String, Any)) : Any
if (str = data.as_s?)
if str = data.as_s?
Any.new str.rstrip
else
data
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/filters/split.cr
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Liquid::Filters
return Any.new(nil) if raw_data.nil?

if raw_data.responds_to?(:split)
array = raw_data.split(arg).map { |s| Any.new(s) }
array = raw_data.split(arg).map { |obj| Any.new(obj) }
Any.new(array)
else
Any{data}
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/filters/strip.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Liquid::Filters
extend Filter

def self.filter(data : Any, args : Array(Any), options : Hash(String, Any)?) : Any
if (str = data.as_s?)
if str = data.as_s?
Any.new str.strip
else
data
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/filters/upcase.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Liquid::Filters
extend Filter

def self.filter(data : Any, args : Array(Any), options : Hash(String, Any)?) : Any
raise FilterArgumentException.new("upcase filter expects no arguments.") if args.any?
raise FilterArgumentException.new("upcase filter expects no arguments.") unless args.empty?

raw = data.raw
if raw.responds_to?(:upcase)
Expand Down
12 changes: 6 additions & 6 deletions src/liquid/match_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ require "./blocks"
module Liquid
class MatchVisitor < Visitor
def visit(node : Node) : String
return node.children.map { |e| self.visit e }.join
node.children.map { |e| self.visit e }.join
end

def visit(node : Block::RawNode) : String
return node.content
node.content
end

def visit(node : ExpressionNode)
return ".*"
".*"
end

def visit(node : Conditional) : String
Expand All @@ -29,7 +29,7 @@ module Liquid
child_nodes << ""
end

return "(#{child_nodes.join("|")})"
"(#{child_nodes.join("|")})"
end

def visit(node : Case)
Expand All @@ -47,13 +47,13 @@ module Liquid
child_nodes << ""
end

return "(#{child_nodes.join("|")})"
"(#{child_nodes.join("|")})"
end

def visit(node : For)
child_nodes = node.children.map { |e| self.visit e }

return "(#{child_nodes.join})*"
"(#{child_nodes.join})*"
end
end
end
2 changes: 1 addition & 1 deletion src/liquid/template.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Liquid
match_string = visitor.visit @root
match_regex = /^#{match_string}$/

return match_regex.matches?(target_string)
match_regex.matches?(target_string)
end

def render(data, io : IO) : Nil
Expand Down