From 83da985bf69696362d4f86caa9f5ec74faa58c5d Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Wed, 3 May 2017 08:13:07 -0700 Subject: [PATCH] Check Ruby syntax on `haml -c` Close #880 --- lib/haml/exec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/haml/exec.rb b/lib/haml/exec.rb index 82657f6896..de9fca38e2 100644 --- a/lib/haml/exec.rb +++ b/lib/haml/exec.rb @@ -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 @@ -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