Start sniffer code before the commit

Hello!

I want to do a check with the sniffer code in the git version control system before the commit.

How do I insert the php code sniffer in ?

codesniffer.jpg

Sincerely yours

Stephan

1
4 comments

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

0
Avatar
Permanently deleted user

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
0

Maybe change severity to some higher level (Error or whatever)...

Other than that -- no ideas.

0
Avatar
Permanently deleted user

I solved it with Pre Commit Hook Plugin.

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.

echo "Running CodeSniffer..."
problemFound=false
checkFiles=""

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

exit 0

I hope that it helps someone :)

0

Please sign in to leave a comment.