Correl Roush
fc258c4230
git-svn-id: file:///srv/svn/scanner/trunk@7 a0501263-5b7a-4423-a8ba-1edf086583e7
36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
class LintModule extends ScannerModule {
|
|
function LintModule() {
|
|
$this->ScannerModule();
|
|
}
|
|
function preScan( $file ) {
|
|
parent::preScan( $file );
|
|
$output = array();
|
|
if( $file['revision'] > 0 ) {
|
|
global $svn_root, $svn_base;
|
|
exec( "svn cat -r {$file['revision']} {$svn_root}{$svn_base}/{$file['filename']} 2>/dev/null | php -l 2>/dev/null", $output, $result );
|
|
$file_contents = isset( $file['contents'] ) ? $file['contents'] : shell_exec( "svn cat -r {$file['revision']} {$svn_root}{$svn_base}/{$file['filename']} 2>/dev/null" );
|
|
} else {
|
|
exec( "php -l '{$file['filename']}' 2>/dev/null", $output, $result );
|
|
$file_contents = file( $file['filename'] );
|
|
}
|
|
if( $result != 0 ) {
|
|
foreach( $output as $linterror ) {
|
|
$matches = array();
|
|
if( preg_match( '/error:.*?on line (\d+)$/i', $linterror, $matches ) == 0 ) { continue; }
|
|
$this->fault(
|
|
array(
|
|
'file' => $file['filename'],
|
|
'line' => $matches[1],
|
|
'context' => $file_contents[$matches[1] - 1]
|
|
),
|
|
FAULT_MAJOR,
|
|
$linterror
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
addModule( new LintModule() );
|
|
?>
|