This repository has been archived by the owner on Jun 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Iikka Timlin
committed
Sep 17, 2020
0 parents
commit c081fd8
Showing
6 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.json] | ||
indent_size = 4 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Run PHPCS on pre-commit hook | ||
|
||
## Installation | ||
1. Add following lines to composer.json: | ||
```json | ||
scripts: { | ||
"install-pre-commit-hook": ["bash ./vendor/urbanproof/phpcs-pre-commit/setup.sh"], | ||
"post-install-cmd": ["@install-pre-commit-hook"], | ||
"post-update-cmd": ["@install-pre-commit-hook"] | ||
}, | ||
"repositories": [ | ||
{ | ||
"type": "vcs", | ||
"url": "https://github.com/Urbanproof/phpcs-pre-commit.git" | ||
} | ||
] | ||
``` | ||
2. Require; `composer require --dev "urbanproof/phpcs-pre-commit"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "urbanproof/phpcs-pre-commit", | ||
"description": "Run code quality checks automatically before each commit.", | ||
"type": "library", | ||
"require": { | ||
"squizlabs/php_codesniffer": "^3.5.6" | ||
}, | ||
"license": "WTFPL v2", | ||
"authors": [ | ||
{ | ||
"name": "Iikka Timlin", | ||
"homepage": "https://github.com/Urbanproof/" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
PROJECT=`php -r "echo dirname(dirname(dirname(dirname(realpath('$0')))));"` | ||
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php` | ||
|
||
# This checks if a list of files was given. If so, it will be used instead of parsing the files in the index | ||
if [ "$#" -eq 1 ] | ||
then | ||
oIFS=$IFS | ||
IFS=' | ||
' | ||
SFILES="$1" | ||
IFS=$oIFS | ||
fi | ||
SFILES=${SFILES:-$STAGED_FILES_CMD} | ||
|
||
echo "Running PHP Linter..." | ||
for FILE in $SFILES | ||
do | ||
php -l -d display_errors=0 $PROJECT/$FILE | ||
if [ $? != 0 ] | ||
then | ||
echo "File $FILE contains PHP errors. Fix before commit." | ||
exit 1 | ||
fi | ||
FILES="$FILES $PROJECT/$FILE" | ||
done | ||
|
||
if [ "$FILES" != "" ] | ||
then | ||
echo "Running PHPCS" | ||
./vendor/bin/phpcs | ||
if [ $? != 0 ] | ||
then | ||
echo "Code style / security issues detected. Fix the errors before commit!" | ||
echo "Run the following command to list issues:" | ||
echo " ./vendor/bin/phpcs" | ||
echo "on run" | ||
echo " ./vendor/bin/phpcbf" | ||
echo "to fix issues automatically (wherever possible)." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
exit $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
SOURCE="$PWD/vendor/urbanproof/phpcs-pre-commit/pre-commit" | ||
TARGET="$PWD/.git/hooks/pre-commit" | ||
chmod +x $SOURCE | ||
ln -s $SOURCE $TARGET | ||
echo "Pre-commit hook installed." |