[TxMt] Re: php syntax check
Sven Axelsson
sven.axelsson at gmail.com
Thu Feb 18 17:54:15 UTC 2010
On 18 February 2010 17:35, sunburn <jojo at mouton-rebelle.com> wrote:
>
> I used to have a textmate command that was running a zend studio binairies
> in command line to check php syntax ; it was a lot better than the simple
> php syntax check bundled with the php Bundle, as it told me when a var was
> not declared, and asked for coding standard respect.
>
> I can't find it anywhere, if someone could help me....
Make a TextMate command like this, changing zca to point to your
ZendCodeAnalyzer binary:
#!/usr/bin/env ruby
require ENV['TM_SUPPORT_PATH'] + '/lib/textmate'
zca = 'Path to ZendCodeAnalyzer'
result = `#{zca} #{ENV['TM_FILEPATH']} 2>&1`
result = result.sub(/^Zend.*\n/, '').sub(/^Analyzing.*\n/,
'').gsub(/^.*\(line (\d+)\)/, 'line \1')
puts result.empty? ? 'No errors' : result
TextMate.go_to :line => $1 if result =~ /line (\d+)/
If you find the default settings too strict you can disable some of
the checks. I actually have several TextMate commans for this
disabling different checks. Here's one of those:
#!/usr/bin/env ruby
require ENV['TM_SUPPORT_PATH'] + '/lib/textmate'
zca = 'Path to ZendCodeAnalyzer'
disable = '--disable var-use-before-def-global --disable bool-assign
--disable var-arg-unused'
all_lines = `#{zca} #{ENV['TM_FILEPATH']} 2>&1 | wc -l`.to_i
vubdg_lines = `zca --disable var-use-before-def-global
#{ENV['TM_FILEPATH']} 2>&1 | wc -l`.to_i
ba_lines = `zca --disable bool-assign #{ENV['TM_FILEPATH']} 2>&1 | wc -l`.to_i
vau_lines = `zca --disable var-arg-unused #{ENV['TM_FILEPATH']} 2>&1 |
wc -l`.to_i
result = `zca #{disable} #{ENV['TM_FILEPATH']} 2>&1`
result = result.sub(/^Zend.*\n/, '').sub(/^Analyzing.*\n/,
'').gsub(/^.*\(line (\d+)\)/, 'line \1')
puts "(Ignoring #{all_lines - vubdg_lines} globals)"
puts "(Ignoring #{all_lines - ba_lines} assignments in conditions)"
puts "(Ignoring #{all_lines - vau_lines} unused variables)"
puts result.empty? ? 'No other errors' : result
TextMate.go_to :line => $1 if result =~ /line (\d+)/
This command will run ZCA several times, counting the ignored
warnings, but not actually displaying them.
--
Sven Axelsson
++++++++++[>++++++++++>+++++++++++>++++++++++>++++++
>++++<<<<<-]>++++.+.++++.>+++++.>+.<<-.>>+.>++++.<<.
+++.>-.<<++.>>----.<++.>>>++++++.<<<<.>>++++.<----.
More information about the textmate
mailing list