CmHook is GIT commit hook the code validator for PHP (Code Sniffer), CSS (base only), JS (JsHint) code and commit message formatter/filler with the issue tracker integration (JIRA, GitHub).
The main purpose of this project is
- checking coding standards before commit (by using PHP CodeSniffer, JSHint, RuboCop, or any lint tool)
- filling up commit messages automatically to proper format (details)
Supported file types: php, phtml, js, coffee, css, scss, xml, sh, scss, css, json, less, html, htm.
Target commit message:
Implemented #33: Make smth good now
- Added my file.
This commit message will be generated automatically, we need to type only commit description:
$ git add myfile.php
$ git commit -m 'Added my file.'
See more details about short commit messages.
To get last beta version please define your minimum-stability
.
{
"minimum-stability": "beta",
"prefer-stable": true
}
Due to reason the package requires one package which still in "dev", please fetch it first:
$ composer global require chobie/jira-api-restclient ^2.0@dev
Now fetch the package:
$ composer global require andkirby/commithook ~2.0@beta
If a project already have base configuration files all what you need to:
- define interpreters (PHP for PHPCS, Ruby for Rubocop, NodeJs for JSHint)
- PHP example:
(You may try to use PHP Windows Binaries Downloader (gist))
$ commithook config --xpath code/interpreter/php d:/s/php-7.0.14/php.exe --project-self
- PHP example:
- Install extra code validators:
- PHPCS
$ composer global require squizlabs/php_codesniffer:~2.0@stable
- JSHint (original).
- Rubocop installation.
- PHPCS
- (optional) Perhaps, you have to define binaries for extra code validators in case they are not allow to use globally. (e.g. JSHint, any see how to install any "linter" in this example.)
- Install GIT hook files
$ commithook install
- Enable your tracker integration:
$ commithook tracker:wizard
Here is an example of .bashrc
file for global using.
If global way doesn't work you may use installation via create-project
.
Initialize configuration wizard
GIT integration: hook files installation
Ignore validation
Protect code
Enable JsHint validation (Javascript)
Commit message format
Ignore commit message validation
Active task in commit message
Auto-explode commit message into the list
The code validation works with GIT but it doesn't support git cache. It means if you added a file (git add file.php
), changed it, and trying to commit (without adding it into GIT cache). In commit, of course, you will get code from cache but validators will validate your real file. (#113)
You may quickly find gaps/trailing spaces in your code by the regular expression:
(\n\s*\n\s*\})|(\n\s*\n\s*\n)|(\{\n\s*\n)| +\n
Just use it in your IDE.
Tested on Windows in GIT Bash v2.9.
Feel free to create your faced issue.