Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit update #25

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Pre-commit
# @see http://pre-commit.com/
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
sha: master
rev: v1.3.0
hooks:
- id: check-yaml
files: \.(yaml|yml)$
42 changes: 42 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
- id: php-lint-all
name: PHP Syntax Check (Comprehensive)
description: Check PHP Syntax on ALL PHP staged files with user friendly messages and colors
entry: pre_commit_hooks/php-lint.sh
language: script
files: \.php$
args: [-s all]

- id: php-lint
name: PHP Syntax Check (Quick)
description: Runs php -l on all staged files. Exits when it hits the first errored file
entry: php -l
language: system
files: \.php$

- id: php-unit
name: PHP Unit
description: Run the full php unit test. Checks which PHPUnit executable is available first and then runs it. Preference order is vendor/bin, phpunit and phpunit.phar.
entry: pre_commit_hooks/php-unit.sh
language: script
files: \.php$

- id: php-cs
name: PHP Codesniffer
description: Run php codesniffer against all staged files.
entry: pre_commit_hooks/php-cs.sh
language: script
files: \.php$

- id: php-cbf
name: PHP Codesniffer (Code Beutifier and Formatter)
description: Run php codesniffer against all staged files.
entry: pre_commit_hooks/php-cbf.sh
language: script
files: \.php$

- id: php-cs-fixer
name: PHP Coding Standards Fixer
description: Run php coding standards fixer against all staged files.
entry: pre_commit_hooks/php-cs-fixer.sh
language: script
files: \.php$
2 changes: 1 addition & 1 deletion pre_commit_hooks/helpers/locate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if [ -f "$vendor_command" ]; then
elif hash $global_command 2>/dev/null; then
exec_command=$global_command
elif [ -f "$local_command" ]; then
phpcsfixer_command=$prefixed_local_command
exec_command=$prefixed_local_command
else
echo -e "${bldred}No valid ${title} found!${txtrst}"
echo "Please have one available as one of the following:"
Expand Down
6 changes: 3 additions & 3 deletions pre_commit_hooks/php-cbf.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env sh

# Bash PHP Code Beautifier and Fixer Hook
# This script fails if the PHP Code Beautifier and Fixer output has the word "ERROR" in it.
Expand All @@ -19,7 +19,7 @@ msg_color_yellow='\e[0;33m'
msg_color_none='\e[0m' # No Color

# Loop through the list of paths to run PHP Code Beautifier and Fixer against
echo -en "${msg_color_yellow}Begin PHP Code Beautifier and Fixer ...${msg_color_none} \n"
echo -e "${msg_color_yellow}Begin PHP Code Beautifier and Fixer ...${msg_color_none} \n"
phpcbf_local_exec="phpcbf.phar"
phpcbf_command="php $phpcbf_local_exec"

Expand Down Expand Up @@ -50,7 +50,7 @@ echo "Running command $phpcbf_command"
command_result=`eval $phpcbf_command`
if [[ $command_result =~ ERROR ]]
then
echo -en "${msg_color_magenta}Errors detected by PHP Code Beautifier and Fixer ... ${msg_color_none} \n"
echo -e "${msg_color_magenta}Errors detected by PHP Code Beautifier and Fixer ... ${msg_color_none} \n"
echo "$command_result"
exit 1
fi
Expand Down
9 changes: 5 additions & 4 deletions pre_commit_hooks/php-cs-fixer.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env sh

################################################################################
#
# Bash PHP Coding Standards Fixer
Expand Down Expand Up @@ -62,9 +63,9 @@ done;
# There is currently debate about exit codes in php-cs-fixer
# https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/1211
if [ "$php_errors_found" = true ]; then
echo -en "\n${txtylw}${title} updated the following files:${txtrst}\n"
echo -en "${error_message}"
echo -en "\n${bldred}Please review and commit.${txtrst}\n"
echo -e "\n${txtylw}${title} updated the following files:${txtrst}\n"
echo -e "${error_message}"
echo -e "\n${bldred}Please review and commit.${txtrst}\n"
exit 1
fi

Expand Down
8 changes: 4 additions & 4 deletions pre_commit_hooks/php-cs.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env sh

# Bash PHP Codesniffer Hook
# This script fails if the PHP Codesniffer output has the word "ERROR" in it.
Expand All @@ -19,7 +19,7 @@ msg_color_yellow='\033[0;33m'
msg_color_none='\033[0m' # No Color

# Loop through the list of paths to run php codesniffer against
echo -en "${msg_color_yellow}Begin PHP Codesniffer ...${msg_color_none} \n"
echo -e "${msg_color_yellow}Begin PHP Codesniffer ...${msg_color_none} \n"
phpcs_local_exec="phpcs.phar"
phpcs_command="php $phpcs_local_exec"

Expand Down Expand Up @@ -49,9 +49,9 @@ echo "Running command $phpcs_command"
command_result=`eval $phpcs_command`
if [[ $command_result =~ ERROR ]]
then
echo -en "${msg_color_magenta}Errors detected by PHP CodeSniffer ... ${msg_color_none} \n"
echo -e "${msg_color_magenta}Errors detected by PHP CodeSniffer ... ${msg_color_none} \n"
echo "$command_result"
exit 1
fi

exit 0
exit 0
8 changes: 4 additions & 4 deletions pre_commit_hooks/php-lint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env sh

# Bash PHP Linter for Pre-commits
#
Expand Down Expand Up @@ -51,7 +51,7 @@ while getopts ":s:" optname
done

# Loop through the list of paths to run php lint against
echo -en "${msg_color_yellow}Begin PHP Linter ...${msg_color_none} \n"
echo -e "${msg_color_yellow}Begin PHP Linter ...${msg_color_none} \n"

parse_error_count=0
for path in ${*:$arg_lookup_start}
Expand All @@ -69,8 +69,8 @@ do
done;

if [ "$php_errors_found" = true ]; then
echo -en "${msg_color_magenta}$parse_error_count${msg_color_none} ${msg_color_yellow}PHP Parse error(s) were found!${msg_color_none} \n"
echo -e "${msg_color_magenta}$parse_error_count${msg_color_none} ${msg_color_yellow}PHP Parse error(s) were found!${msg_color_none} \n"
exit 1
fi

exit 0
exit 0
6 changes: 3 additions & 3 deletions pre_commit_hooks/php-unit.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env sh

# Bash PHP Unit Task Runner
#
Expand All @@ -17,7 +17,7 @@ msg_color_yellow='\e[0;33m'
msg_color_none='\e[0m' # No Color

# Loop through the list of paths to run php lint against
echo -en "${msg_color_yellow}Begin PHP Unit Task Runner ...${msg_color_none} \n"
echo -e "${msg_color_yellow}Begin PHP Unit Task Runner ...${msg_color_none} \n"

phpunit_local_exec="phpunit.phar"
phpunit_command="php $phpunit_local_exec"
Expand Down Expand Up @@ -48,4 +48,4 @@ then
echo "$command_result"
exit 1
fi
exit 0
exit 0