phplint
phplint copied to clipboard
How to suppress "No syntax errors detected" messages?
When I run my gulp commands that include the phpLint job, when all my PHP is correct, I get the following output, one per file:
No syntax errors detected in src/server/sessionEnd.php
Is there a way to suppress this? Ideally, I would like to see output only when there is a syntax error.
The code I am using:
gulp.task('lint:php', lintPHP);
function lintPHP(callback) {
return phplint(['src/**/*.php'],
{limit: 10, stdout: true, stderr: true},
function(err, stdout, stderr) {
if(err) {
process.exit(1);
} else {
callback();
}
});
}
You can see that this is basically a cut/paste from the gulp example on the README along with some of the options as seen in the Grunt example. I have also removed the callback(err)
call since it was just printing a useless stack-trace (below). I was trying to play around with the options and calls but couldn't get quite what I was looking for.
# This is the second part of the output if I include the callback(err) call
# before the process.exit(1) as in the original example
[10:16:18] 'lint:php' errored after 474 ms
[10:16:18] Error: Command failed: /bin/sh -c php -l src/server/leaderboardRequest.php
at ChildProcess.exithandler (child_process.js:751:12)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Socket.<anonymous> (child_process.js:1183:11)
at Socket.emit (events.js:107:17)
at Pipe.close (net.js:485:12)
Hi @MatthewHerbst
I think this is what you're looking for, let me know if it helps.
var opt = {
limit: 10,
stdout: false,
stderr: false
}
return phplint(['src/**/*.php'], opt, function(err, stdout, stderr) {
if (err) {
console.log(err.message);
process.exit(1);
} else {
callback();
}
});
Thanks for the reply. The problem with doing that is that if there actually is a syntax error, it only gives the message
Command failed: /bin/sh -c php -l src/server/leaderboardRequest.php
instead of telling me the line number and such of the error (which seems to require stdout
to be true
based on what I've been trying). From just doing a console.log(err)
I can see that the err
object doesn't actually contain error information about the syntax error (such as the line number) itself.
that's not what i'm getting @MatthewHerbst
~/source/demo
❯ cat gulpfile.js
var gulp = require('gulp');
var phplint = require('phplint').lint;
gulp.task('default', main);
function main(callback) {
var opt = {
limit: 10,
stdout: false,
stderr: false
}
return phplint(['src/**/*.php'], opt, function(err, stdout, stderr) {
if (err) {
console.log(err.message);
process.exit(1);
} else {
callback();
}
});
}
~/source/demo
❯ cat src/bad.php
<?php
function () {
echo ''
}
~/source/demo
❯ gulp
[17:39:57] Using gulpfile ~/source/demo/gulpfile.js
[17:39:57] Starting 'default'...
Command failed: /bin/sh -c php -l src/bad.php
PHP Parse error: syntax error, unexpected '}', expecting ',' or ';' in src/bad.php on line 5
Fascinating. I can't tell where our difference is.
gulp.task('lint:php', lintPHP);
function lintPHP(callback) {
return phplint(['src/server/**/*.php'],
{limit: 10, stdout: false, stderr: false},
function(err, stdout, stderr) {
if(err) {
console.log(err.message);
process.exit(1);
} else {
callback();
}
});
}
// mherbst@scml-mherbst:~/Repos/dvt$ cat src/server/leaderboardRequest.php
<?php
require_once('db.php');
session_start();
$db = new db();
$leaderboard = $db->connect()->getLeaderboard()
header('Content-Type: application/json');
echo json_encode($leaderboard);
mherbst@scml-mherbst:~/Repos/dvt$ gulp lint:php
[11:07:55] Using gulpfile ~/Repos/dvt/gulpfile.js
[11:07:55] Starting 'lint:php'...
Command failed: /bin/sh -c php -l src/server/leaderboardRequest.php
mherbst@scml-mherbst:~/Repos/dvt$
I wonder why I get the whitespace but you get the correct error string. For completeness:
// From package.json
...
"gulp": "^3.9.0",
"phplint": "^1.5.2"
...
Hi @MatthewHerbst, @wayneashleyberry,
I was having the same issue - it's a php.ini setting that toggles the syntax error messages with line info etc.
display_errors = On
Also worth noting that in MAMP Pro, in the GUI under Server -> PHP -> Error handling the buttons to write error messages to the display weren't updating my actual php.ini file, so had to modify it manually in: Applications/MAMP/bin/php/(your_version)/conf/php.ini
@DaveVP I tried changing my /usr/local/etc/php/5.5/php.ini
to all three possible options:
display_errors = On
display_errors = Off
display_errors = stderr
and still see
No syntax errors detected in <my_file>
for each file.
My lintPHP
gulp task is:
function lintPHP(callback) {
phplint(['src/server/**/*.php'],
{limit: 10, stdout: true, stderr: true},
function(err, stdout, stderr) {
if(err) {
//console.log(err.message);
process.exit(1);
} else {
callback();
}
});
}
Did I miss something?
Ah, may have been premature sharing my findings here, sorry.
This setting fixed the output for running php -l file.php
straight off the command line, but like you, it's not affected the output of my gulp task task either.
Perhaps this setting isn't being inherited from your environment and is prescribed somewhere in the node module?
Interestingly I tried 'manually' running this command through a gulp-exec and gulp-shell stream and still no syntax error. Could it be a wider node php issue?
This is working for me now - I had to set display_errors = stderr
in php.ini, here's the gulp task:
gulp.task('phplint', function() {
phplint('theme/*.php', {limit: 10, stdout: false, stderr: true}, function (err, stdout, stderr) {
if (stderr) {
console.log(stderr);
process.exit(1)
}
})
});
is your error_reporting set to error_reporting = E_ALL
in php.ini?
@DaveVP changing from stdout: true
to stdout: false
did the trick for me! For me to have the process.exit(1)
work I still had to check against err
rather than stderr
. (And yeah, I've already got error_reporting = E_ALL
in the php.ini)