Here is my bash script pre-commit-hook.sh for this plugin (for Drupal projects):
#!/bin/bash
# Run CodeSniffer before commit in PhpStorm
# How to: # 1. Do basic configuration of phpcs & phpcbf for Drupal and PhpStorm as described here: # https://www.drupal.org/docs/8/modules/code-review-module/installing-coder-sniffer # Highlighting and auto-fixing errors in PhpStorm should work after this step. # 2. Install "Pre Commit Hook Plugin" in PhpStorm and configure it to use this file (pre-commit-hook.sh) # in Settings -> Hooks -> Pre Commit Hook. # This should show warning dialog before commit files that are incompatible with # Drupal and DrupalPractice standards.
for i; do out=`phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,js,yml ${i}` # standard exit code not available # echo $? # checking for "ERROR" in output # echo ${out} if [[ ${out} == *"ERROR"* ]]; then problemFound=true checkFiles="${checkFiles} ${i}" fi done
if ${problemFound}; then echo "Problem(s) in file(s):" echo "---------------------" echo ${checkFiles} echo "---------------------" exit 1 fi
That box (the text just above it) says "AFTER Commit" while you need BEFORE ...
Before Commit has "Perform code analysis" -- CodeSniffer is just an ordinary inspection
It doesn't work for me with PhpStorm 7.1.3.
Code Sniffer inspections works well in editor window and show style errors yet allow files to be committed.
Do I need to enable it somewhere?
Thanks
Attachment(s):
Screenshot from 2014-08-08 15:15:30.png
Screenshot from 2014-08-08 15:15:04.png
Screenshot from 2014-08-08 15:14:16.png
Maybe change severity to some higher level (Error or whatever)...
Other than that -- no ideas.
I solved it with Pre Commit Hook Plugin.
Here is my bash script pre-commit-hook.sh for this plugin (for Drupal projects):
I hope that it helps someone :)