Skip to content

Commit da38bab

Browse files
authored
Merge pull request #1 from ensi-platform/task-77886
#77886
2 parents 5ef4f61 + 11ed656 commit da38bab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1846
-1439
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
ESC_SEQ="\x1b["
4+
COL_RESET=$ESC_SEQ"39;49;00m"
5+
COL_RED=$ESC_SEQ"0;31m"
6+
COL_GREEN=$ESC_SEQ"0;32m"
7+
COL_YELLOW=$ESC_SEQ"0;33m"
8+
9+
changed_files="$(git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD)"
10+
11+
check_run() {
12+
echo "$changed_files" | grep --quiet "$1" && echo " * changes detected in $1" && echo " * running $2" && eval "$2"
13+
}
14+
15+
check_run composer.lock "composer install"
16+
check_run package-lock.json "npm install"
17+
exit 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
ESC_SEQ="\x1b["
4+
COL_RESET=$ESC_SEQ"39;49;00m"
5+
COL_RED=$ESC_SEQ"0;31m"
6+
COL_GREEN=$ESC_SEQ"0;32m"
7+
COL_YELLOW=$ESC_SEQ"0;33m"
8+
9+
changed_files="$(git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD)"
10+
11+
check_run() {
12+
echo "$changed_files" | grep --quiet "$1" && echo " * changes detected in $1" && echo " * running $2" && eval "$2"
13+
}
14+
15+
check_run composer.lock "composer install"
16+
check_run package-lock.json "npm install"
17+
exit 0

.git_hooks/pre-commit/lint-php.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
ROOT_DIR="$(pwd)/"
4+
LIST=$(git diff-index --cached --name-only --diff-filter=ACMR HEAD)
5+
ERRORS_BUFFER=""
6+
ESC_SEQ="\x1b["
7+
COL_RESET=$ESC_SEQ"39;49;00m"
8+
COL_RED=$ESC_SEQ"0;31m"
9+
COL_GREEN=$ESC_SEQ"0;32m"
10+
COL_YELLOW=$ESC_SEQ"0;33m"
11+
COL_BLUE=$ESC_SEQ"0;34m"
12+
COL_MAGENTA=$ESC_SEQ"0;35m"
13+
COL_CYAN=$ESC_SEQ"0;36m"
14+
15+
echo
16+
printf "$COL_YELLOW%s$COL_RESET\n" "Running pre-commit hook: \"php-linter\""
17+
18+
for file in $LIST
19+
do
20+
EXTENSION=$(echo "$file" | grep -E ".php$|.module$|.inc$|.install$")
21+
if [ "$EXTENSION" != "" ]; then
22+
ERRORS=$(php -l $ROOT_DIR$file 2>&1 | grep "Parse error")
23+
if [ "$ERRORS" != "" ]; then
24+
if [ "$ERRORS_BUFFER" != "" ]; then
25+
ERRORS_BUFFER="$ERRORS_BUFFER\n$ERRORS"
26+
else
27+
ERRORS_BUFFER="$ERRORS"
28+
fi
29+
echo "Syntax errors found in file: $file "
30+
fi
31+
fi
32+
done
33+
if [ "$ERRORS_BUFFER" != "" ]; then
34+
echo
35+
echo "These errors were found in try-to-commit files: "
36+
echo -e $ERRORS_BUFFER
37+
echo
38+
printf "$COL_RED%s$COL_RESET\r\n\r\n" "Can't commit, fix errors first."
39+
exit 1
40+
else
41+
echo "Okay"
42+
exit 0
43+
fi
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
EXECUTABLE_NAME=php-cs-fixer
4+
EXECUTABLE_COMMAND=fix
5+
CONFIG_FILE=.php-cs-fixer.php
6+
CONFIG_FILE_PARAMETER='--config'
7+
ROOT=`pwd`
8+
ESC_SEQ="\x1b["
9+
COL_RESET=$ESC_SEQ"39;49;00m"
10+
COL_RED=$ESC_SEQ"0;31m"
11+
COL_GREEN=$ESC_SEQ"0;32m"
12+
COL_YELLOW=$ESC_SEQ"0;33m"
13+
COL_BLUE=$ESC_SEQ"0;34m"
14+
COL_MAGENTA=$ESC_SEQ"0;35m"
15+
COL_CYAN=$ESC_SEQ"0;36m"
16+
17+
echo ""
18+
printf "$COL_YELLOW%s$COL_RESET\n" "Running pre-commit hook: \"php-cs-fixer\""
19+
20+
# possible locations
21+
locations=(
22+
$ROOT/bin/$EXECUTABLE_NAME
23+
$ROOT/vendor/bin/$EXECUTABLE_NAME
24+
)
25+
26+
for location in ${locations[*]}
27+
do
28+
if [[ -x $location ]]; then
29+
EXECUTABLE=$location
30+
break
31+
fi
32+
done
33+
34+
if [[ ! -x $EXECUTABLE ]]; then
35+
echo "executable $EXECUTABLE_NAME not found, exiting..."
36+
echo "if you're sure this is incorrect, make sure they're executable (chmod +x)"
37+
exit
38+
fi
39+
40+
echo "using \"$EXECUTABLE_NAME\" located at $EXECUTABLE"
41+
$EXECUTABLE --version
42+
43+
if [[ -f $ROOT/$CONFIG_FILE ]]; then
44+
CONFIG=$ROOT/$CONFIG_FILE
45+
echo "config file located at $CONFIG loaded"
46+
fi
47+
48+
FILES=`git status --porcelain | grep -e '^[AM]\(.*\).php$' | cut -c 3- | sed -e "s/_ide_helper.php$//" | sed -e "s/_ide_helper_models.php$//" | sed -e "s/.phpstorm.meta.php$//" | tr '\n' ' ' | sed 's/ *$//g'`
49+
if [ -z "$FILES" ]; then
50+
echo "No php files found to fix."
51+
else
52+
echo "Fixing files ${FILES} in project";
53+
if [[ -f $CONFIG ]]; then
54+
$EXECUTABLE $EXECUTABLE_COMMAND $CONFIG_FILE_PARAMETER=$CONFIG ${FILES};
55+
else
56+
$EXECUTABLE $EXECUTABLE_COMMAND ${FILES};
57+
fi
58+
git add ${FILES}
59+
fi
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# validate composer
4+
5+
ESC_SEQ="\x1b["
6+
COL_RESET=$ESC_SEQ"39;49;00m"
7+
COL_RED=$ESC_SEQ"0;31m"
8+
COL_GREEN=$ESC_SEQ"0;32m"
9+
COL_YELLOW=$ESC_SEQ"0;33m"
10+
11+
echo
12+
printf "$COL_YELLOW%s$COL_RESET\n" "Running pre-push hook: \"composer-validate\""
13+
14+
VALID=$(composer validate --strict --no-check-publish --no-check-all | grep "is valid")
15+
16+
if [ "$VALID" != "" ]; then
17+
echo "Okay"
18+
exit 0
19+
else
20+
printf "$COL_RED%s$COL_RESET\r\n" "Composer validate check failed."
21+
exit 1
22+
fi
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
ESC_SEQ="\x1b["
4+
COL_RESET=$ESC_SEQ"39;49;00m"
5+
COL_RED=$ESC_SEQ"0;31m"
6+
COL_GREEN=$ESC_SEQ"0;32m"
7+
COL_YELLOW=$ESC_SEQ"0;33m"
8+
9+
echo
10+
printf "$COL_YELLOW%s$COL_RESET\n" "Running pre-push hook: \"var-dump-checker\""
11+
12+
./vendor/bin/var-dump-check --laravel --exclude bootstrap --exclude node_modules --exclude vendor .
13+
14+
# If the grep command has no hits - echo a warning and exit with non-zero status.
15+
if [ $? == 1 ]; then
16+
printf "$COL_RED%s$COL_RESET\r\n\r\n" "Some var_dump usage found. Please fix your code"
17+
exit 1
18+
fi
19+
20+
echo "Okay"
21+
exit 0

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.komodoproject
66
.vscode
77
.phpunit.result.cache
8+
.php-cs-fixer.cache
89
composer.lock
910

1011
build

.huskyrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"hooks": {
3+
"post-checkout": ".git_hooks/post-checkout/install-dependecies.sh",
4+
"post-merge": ".git_hooks/post-merge/install-dependecies.sh",
5+
"pre-commit": ".git_hooks/pre-commit/lint-php.sh && .git_hooks/pre-commit/php-cs-fixer.sh",
6+
"pre-push": ".git_hooks/pre-push/composer-validate.sh && .git_hooks/pre-push/var-dump-checker.sh && composer test"
7+
}
8+
}

.php-cs-fixer.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
$finder = Symfony\Component\Finder\Finder::create()
4+
->in([
5+
__DIR__ . '/src',
6+
__DIR__ . '/tests',
7+
])
8+
->name('*.php')
9+
->notName('*.blade.php')
10+
->ignoreDotFiles(true)
11+
->ignoreVCS(true);
12+
13+
return (new PhpCsFixer\Config())
14+
->setRules([
15+
'@PSR2' => true,
16+
'array_syntax' => ['syntax' => 'short'],
17+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
18+
'no_unused_imports' => true,
19+
'trailing_comma_in_multiline' => true,
20+
'phpdoc_scalar' => true,
21+
'unary_operator_spaces' => true,
22+
'blank_line_before_statement' => [
23+
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
24+
],
25+
'phpdoc_single_line_var_spacing' => true,
26+
'phpdoc_var_without_name' => true,
27+
'class_attributes_separation' => [
28+
'elements' => [
29+
'method' => 'one',
30+
],
31+
],
32+
'method_argument_space' => [
33+
'on_multiline' => 'ensure_fully_multiline',
34+
'keep_multiple_spaces_after_comma' => true,
35+
],
36+
'single_trait_insert_per_statement' => true,
37+
'no_whitespace_in_blank_line' => true,
38+
'method_chaining_indentation' => true,
39+
40+
])
41+
->setFinder($finder);

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2020-present Ensi
1+
Copyright (c) 2020-present Greensight
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)