Skip to content

Commit 993110f

Browse files
authored
Merge pull request #325 from alma/fix/pre-commit
Fix/pre commit
2 parents aca456b + c29d540 commit 993110f

19 files changed

+205
-129
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ ij_json_wrap_long_lines = false
776776

777777
[{*.htm,*.html,*.sht,*.shtm,*.shtml}]
778778
ij_html_add_new_line_before_tags = body,div,p,form,h1,h2,h3
779-
ij_html_align_attributes = true
779+
ij_html_align_attributes = false
780780
ij_html_align_text = false
781781
ij_html_attribute_wrap = normal
782782
ij_html_block_comment_add_space = false

.pre-commit-config.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,22 @@ repos:
2323
- id: coding-standard-fixer
2424
name: PHP and WordPress coding standards Fixer test
2525
language: system
26-
entry: ./bin/coding-standard-fixer.sh
26+
pass_filenames: false
27+
entry: task lint:fix
2728
stages: [ pre-commit ]
2829

2930
- id: coding-standard
3031
name: Check the PHP and WordPress coding standards
3132
language: system
32-
entry: ./bin/coding-standard.sh
33+
pass_filenames: false
34+
entry: task lint
35+
stages: [ pre-commit ]
36+
37+
- id: php-compatibility
38+
name: Check the PHP compatibility
39+
language: system
40+
pass_filenames: false
41+
entry: task php-compatibility
3342
stages: [ pre-commit ]
3443

3544
# - repo: https://github.com/returntocorp/semgrep

Taskfile.yml

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,50 @@ tasks:
1818
cmds:
1919
- docker compose build --build-arg UID="$(id -u)" php5-6
2020

21-
test:
22-
desc: Run tests
23-
deps:
24-
- build:test
25-
cmds:
26-
- docker compose run --rm test
27-
- docker compose down --remove-orphans
28-
29-
pre-commit:install:
30-
desc: Install pre-commit hooks
21+
lint:build:
22+
desc: Build lint container (php-cs-fixer)
3123
cmds:
32-
- pre-commit install --hook-type commit-msg
33-
- pre-commit install
24+
- docker build -t lint:wc -f lint.Dockerfile .
3425

3526
lint:
36-
desc: Run linter
27+
desc: Run lint container
3728
deps:
38-
- build:php5-6
29+
- lint:build
3930
cmds:
40-
- docker compose run --rm php5-6 php ./vendor/bin/phpcs --standard=phpcs.xml ./
31+
- ./bin/lint.sh
4132

4233
lint:fix:
43-
desc: Run linter with autofix
34+
desc: Run lint container
4435
deps:
45-
- build:php5-6
36+
- lint:build
37+
cmds:
38+
- ./bin/lint-fix.sh
39+
40+
php-compatibility:build:
41+
desc: Build php-compatibility container (phpcs)
4642
cmds:
47-
- docker compose run --rm php5-6 php ./vendor/bin/phpcbf --standard=phpcs.xml ./
43+
- docker build -t php-compatibility:wc -f lint.Dockerfile .
4844

4945
php-compatibility:
50-
desc: Check compatibility code
46+
desc: Check compatibility code in PHP-CS container
5147
deps:
52-
- build:php5-6
48+
- php-compatibility:build
49+
cmds:
50+
- ./bin/php-compatibility.sh
51+
52+
test:
53+
desc: Run tests
54+
deps:
55+
- build:test
5356
cmds:
54-
- docker compose run --rm php5-6 php ./vendor/bin/phpcs -d memory_limit=512M -p ./ --standard=PHPCompatibility -s --runtime-set testVersion 5.6-8.1 --ignore='*/vendor/*,build/*'
57+
- docker compose run --rm test
58+
- docker compose down --remove-orphans
59+
60+
pre-commit:install:
61+
desc: Install pre-commit hooks
62+
cmds:
63+
- pre-commit install --hook-type commit-msg
64+
- pre-commit install
5565

5666
dist:
5767
desc: Build zip file

alma-gateway-for-woocommerce.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
* @return Alma\Woocommerce\AlmaPlugin
6868
* @noinspection PhpIncludeInspection
6969
*/
70+
71+
7072
function alma_plugin() {
7173
static $plugin;
7274

bin/coding-standard-fixer.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

bin/coding-standard.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

bin/lint-fix.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
docker run --rm -v "$(pwd):/app" -w /app lint:wc -v --standard=phpcs.xml ./
3+
EXIT_CODE=$?
4+
5+
if [[ $EXIT_CODE -ne 0 ]]; then
6+
echo "Fix the errors with PHPcbf automatic fixer before commit!"
7+
exit 1
8+
fi

bin/lint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
docker run --rm -v "$(pwd):/app" -w /app lint:wc -v --standard=phpcs.xml ./
3+
EXIT_CODE=$?
4+
5+
if [[ $EXIT_CODE -ne 0 ]]; then
6+
echo "Fix the errors before commit!"
7+
exit 1
8+
fi

bin/php-compatibility.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
docker run --rm -v "$(pwd):/app" -v "$(pwd)/.php_cs.cache:/app/.php_cs.cache" --entrypoint /composer/vendor/bin/phpcs \
3+
php-compatibility:wc -p . --standard=PHPCompatibility -s --runtime-set testVersion 5.6-8.4 --ignore=\*/vendor/\*,build/*,node_modules/*,coverage/*
4+
EXIT_CODE=$?
5+
6+
if [[ $EXIT_CODE -ne 0 ]]; then
7+
echo "Check PHP code compatibility before commit!"
8+
exit 1
9+
fi

compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ services:
4040
php5-6:
4141
build:
4242
context: ./
43-
dockerfile: Dockerfile.legacy
43+
dockerfile: legacy.Dockerfile
4444
volumes:
4545
- ./:/home/phpuser
4646
- /home/phpuser/src/vendor # do not mount vendor inside container

0 commit comments

Comments
 (0)