Skip to content

Instantly share code, notes, and snippets.

@mikaelz
Created April 10, 2017 13:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikaelz/c5d08ce9b7c575594c20e7dd75f71a05 to your computer and use it in GitHub Desktop.
Save mikaelz/c5d08ce9b7c575594c20e7dd75f71a05 to your computer and use it in GitHub Desktop.
PHP lint files, for example due migration to PHP7
#!/bin/bash
find . -name '*.php' | xargs -i php -l {} | grep -v 'No syntax errors'
@axelpale
Copy link

axelpale commented Nov 12, 2020

Cool idea! Sadly, on macOS Mojave 10.14.6 the snippet throws an error:

$ find . -name '*.php' | xargs -i php -l {} | grep -v 'No syntax errors'
xargs: illegal option -- i
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
         [-L number] [-n number [-x]] [-P maxprocs] [-s size]
         [utility [argument ...]]

It seems that -i flag is deprecated. Fortunately, I got the snippet working by replacing -i by -I {}.

$ find . -name '*.php' | xargs -I {} php -l {} | grep -v 'No syntax errors'

Parse error: syntax error, unexpected 'if' (T_IF) in ./src/example.php on line 30
Errors parsing ./src/example.php

Note: the snippet seems to exit at the first lint issue. I had to fix the issue and run the snippet again and again to catch all the issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment