PHP Lint in Makefile

I ran into a little problem adding php -l to a Makefile. PHP lint is a little verbose outputting “No syntax errors detected” for every file that has no problems. I don’t really want that output but getting rid of it with grep -v means that make treats no errors (grep didn’t find any lines to show) as a failure and errors (grep found some lines to show) as a success. make then terminates in the success case and continues or exits with success in the failure case!

lint:
	@! find . -name "*.php" | grep -v "^./vendor" | xargs -I{} php -l '{}' | grep -v "No syntax errors detected"

The trick is to negate the exit code of the entire pipeline like so:

lint:
	@! find . -name "*.php" | grep -v "^./vendor" | xargs -I{} php -l '{}' | grep -v "No syntax errors detected"

Leave a Reply

Your email address will not be published.