From 2121ea49cc9fc8b3ec9d989ad2fb22506bf10505 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Fri, 10 Aug 2012 22:13:09 -0500 Subject: [PATCH] Add lint test for short_open_tags --- setup/test/lint.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/setup/test/lint.php b/setup/test/lint.php index 4566c495a..5657bb080 100644 --- a/setup/test/lint.php +++ b/setup/test/lint.php @@ -44,7 +44,40 @@ if (strlen($syntax_errors)) { echo "$syntax_errors"; exit(); } else { + echo "pass\n"; +} + +function line_number_for_offset($filename, $offset) { + $lines = file($filename); + $bytes = $line = 0; + while ($bytes < $offset) { + $bytes += strlen(array_shift($lines)); + $line += 1; + } + return $line; +} +echo "Short open tags: "; +$fails = array(); +foreach ($scripts as $s) { + $matches = array(); + if (preg_match_all('/<\?\s*(?!php|xml).*$/m', file_get_contents($s), &$matches, + PREG_OFFSET_CAPTURE) > 0) { + foreach ($matches[0] as $match) + $fails[] = array( + str_replace($root.'/', '', $s), + $match[0], + line_number_for_offset($s, $match[1])); + } +} +if (count($fails)) { + echo "FAIL\n"; + echo "-------------------------------------------------------\n"; + foreach ($fails as $f) + echo sprintf("In %s, line %d: %s\n", $f[0], $f[2], + str_replace("\n", " ", $f[1])); echo "\n"; +} else { + echo "pass\n"; } # Run phplint across all php files -- GitLab