Skip to content

Commit

Permalink
Check Ruby syntax on haml -c
Browse files Browse the repository at this point in the history
Close #880
  • Loading branch information
k0kubun committed May 3, 2017
1 parent 19743dd commit 83da985
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/haml/exec.rb
Expand Up @@ -301,6 +301,11 @@ def process_result
engine = ::Haml::Engine.new(template, @options[:for_engine])

if @options[:check_syntax]
error = validate_ruby(engine.precompiled)
if error
puts error.message.split("\n").first
exit 1
end
puts "Syntax OK"
return
end
Expand Down Expand Up @@ -333,7 +338,7 @@ def process_result

def validate_ruby(code)
begin
eval("BEGIN {return nil}; #{code}")
eval("BEGIN {return nil}; #{code}", binding, @options[:filename])
rescue ::SyntaxError # Not to be confused with Haml::SyntaxError
$!
end
Expand Down

0 comments on commit 83da985

Please sign in to comment.