PHP Precommit Tools to lint/review/clean all your web files (php/js/scss/xml/yml/json)
Based on https://github.com/sjparkinson/static-review
This Code Reviewing tool can check:
- GIT merge conflict markers
- GIT NOCOMMIT markers
- Forgot debugging (JS,PHP) statements
- PHP Syntax Error
- XML Syntax Error
- YML Syntax Error
- JSON Syntax Error
- JS Syntax Error & auto-fix it
- Composer .json validation
- Composer Sync .json and .lock files
It optimizes PHP Syntax with specific php-cs-fixer rules (See PhpCsFixerReview.php) :
- Automatically Fix coding standards issues (PHP CS Fixer)
It optimizes SCSS Syntax :
- Automatically Fix coding standards issues (Sass-convert)
It reports about bad JS statements with specific eslint rules (See Rules/.eslintrc)
It reports about bad SCSS statements specific scss-lint rules (See Rules/.scsslint.yml)
It reports about bad PHP statements :
- Mess Detection (Unused code, complexity...) with phpmd rules (See Rules/phpmd.xml)
- Copy/Paste detection
- Code sniffing to notify missing PHPDOC function
Execute check-requirements command:
./bin/precommit checkRequirements
Change PHP Cli Configuration if necessary with:
phar.readonly = Off
To install precommit tool and generate phar package:
Launch install script ./install_precommit.sh
This script will install all required libraries, create a phar file with sources files, and move it to /usr/local/bin
In your project path, just execute install command precommit install
To know which project is configured with pre-commit, you can simply execute precommit listRepo [WORKSPACE_PATH]
Get latest libraries version with a "composer global update"
Just update your GIT fork and re-launch install script.
After the installation, you can execute "precommit" command to:
- checkRequirements : Execute check requirements
- check : Execute pre-commit
- checkFile [file] : Execute pre-commit checks on single file
- php-cs-fixer [file] : Execute php-cs-fixer rule on single file
- install : Install pre-commit hook on your current project
- delete : Delete pre-commit hook on your current project
- listRepo [workspace_path] : Analyse all git projects to get pre-commit informations
In order to check file manually in PhpStorm:
- Go to Settings / External Tools
- Add new one and fill info like this:
- Program: "precommit"
- Parameters: "checkFile
$FilePath$ " - Working Directory: "$ProjectFileDir$"
- libxml2-utils
- PHP Cs Fixer Install (https://github.com/FriendsOfPHP/PHP-CS-Fixer)
- PHP Mess Detector
- PHP CPD
- PHPCS
- ESLint (http://eslint.org/) - Install (see https://github.com/nodejs/node-v0.x-archive/wiki/Installing-Node.js-via-package-manager)
- sass
- scss-lint (https://github.com/brigade/scss-lint)