This repository was archived by the owner on Jun 28, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +100
-0
lines changed Expand file tree Collapse file tree 6 files changed +100
-0
lines changed Original file line number Diff line number Diff line change
1
+ root = true
2
+
3
+ [* ]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [* .json ]
12
+ indent_size = 4
13
+
14
+ [* .md ]
15
+ trim_trailing_whitespace = false
16
+ indent_size = 4
Original file line number Diff line number Diff line change
1
+ /vendor /
Original file line number Diff line number Diff line change
1
+ # Run PHPCS on pre-commit hook
2
+
3
+ ## Installation
4
+ 1 . Add following lines to composer.json:
5
+ ``` json
6
+ scripts: {
7
+ "install-pre-commit-hook" : [" bash ./vendor/urbanproof/phpcs-pre-commit/setup.sh" ],
8
+ "post-install-cmd" : [" @install-pre-commit-hook" ],
9
+ "post-update-cmd" : [" @install-pre-commit-hook" ]
10
+ },
11
+ "repositories" : [
12
+ {
13
+ "type" : " vcs" ,
14
+ "url" : " https://github.com/Urbanproof/phpcs-pre-commit.git"
15
+ }
16
+ ]
17
+ ```
18
+ 2 . Require; `composer require --dev "urbanproof/phpcs-pre-commit"`
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " urbanproof/phpcs-pre-commit" ,
3
+ "description" : " Run code quality checks automatically before each commit." ,
4
+ "type" : " library" ,
5
+ "require" : {
6
+ "squizlabs/php_codesniffer" : " ^3.5.6"
7
+ },
8
+ "license" : " WTFPL v2" ,
9
+ "authors" : [
10
+ {
11
+ "name" : " Iikka Timlin" ,
12
+ "homepage" : " https://github.com/Urbanproof/"
13
+ }
14
+ ]
15
+ }
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ PROJECT=` php -r " echo dirname(dirname(dirname(dirname(realpath('$0 ')))));" `
3
+ STAGED_FILES_CMD=` git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\ .php`
4
+
5
+ # This checks if a list of files was given. If so, it will be used instead of parsing the files in the index
6
+ if [ " $# " -eq 1 ]
7
+ then
8
+ oIFS=$IFS
9
+ IFS='
10
+ '
11
+ SFILES=" $1 "
12
+ IFS=$oIFS
13
+ fi
14
+ SFILES=${SFILES:- $STAGED_FILES_CMD }
15
+
16
+ echo " Running PHP Linter..."
17
+ for FILE in $SFILES
18
+ do
19
+ php -l -d display_errors=0 $PROJECT /$FILE
20
+ if [ $? != 0 ]
21
+ then
22
+ echo " File $FILE contains PHP errors. Fix before commit."
23
+ exit 1
24
+ fi
25
+ FILES=" $FILES $PROJECT /$FILE "
26
+ done
27
+
28
+ if [ " $FILES " != " " ]
29
+ then
30
+ echo " Running PHPCS"
31
+ ./vendor/bin/phpcs
32
+ if [ $? != 0 ]
33
+ then
34
+ echo " Code style / security issues detected. Fix the errors before commit!"
35
+ echo " Run the following command to list issues:"
36
+ echo " ./vendor/bin/phpcs"
37
+ echo " on run"
38
+ echo " ./vendor/bin/phpcbf"
39
+ echo " to fix issues automatically (wherever possible)."
40
+ exit 1
41
+ fi
42
+ fi
43
+
44
+ exit $?
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ SOURCE=" $PWD /vendor/urbanproof/phpcs-pre-commit/pre-commit"
3
+ TARGET=" $PWD /.git/hooks/pre-commit"
4
+ chmod +x $SOURCE
5
+ ln -s $SOURCE $TARGET
6
+ echo " Pre-commit hook installed."
You can’t perform that action at this time.
0 commit comments