Closed benzado closed 12 years ago
Not sure how to fix this. Detect if erubis is installed, and then use that to validate the not-really-ERB?
Checking for erubis isn't enough; apparently Rails 3 is using a customized version of erubis.
A dude named Zach Powell pointed out on Stack Overflow that if you just replace all instances of <%=
with <%
then the problems go away, and the resulting code is equivalent as far as the syntax checker is concerned. That would mean replacing line 32 with
"sed 's/<%=/<%/g' #{file} | erb -xT - | #{compiler_ruby} -wc"
My first impulse was to make this an option, using git config
, but considering it does no harm for non-Rails-3 ERB, maybe it should just be the default behavior.
Turns out the above hack (replacing <%=
with <%
) isn't harmless; expressions like <%= value %>
become <% value %>
and result in the warning "possibly useless use of a variable in void context."
As a workaround I'm removing -w
from the command line; merely doing a plain syntax check.
I think checking for erubis
is probably the way to go. I've implemented a completely untested version of this in 1c3e09f, if you'd like to try it out.
Cool! It (mostly) works. I'm submitting a change request with my further patches.
Rails 3 uses a variant of ERB that is not 100% compatible with the version that ships with Ruby. Specifically, this construct
results in errors under the
erb
tool but is OK under Rails.More http://timelessrepo.com/block-helpers-in-rails3
As a result, the pre-commit hook finds errors where there are none.