diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f4c98c12..e77a9c4e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -152,12 +152,6 @@ yarn lint: script: - yarn lint -check-editorconfig: - image: mstruebing/editorconfig-checker - stage: validate - script: - - ec -v - # # Build # @@ -175,7 +169,6 @@ build-image: <<: *container_definition stage: build needs: - - check-editorconfig - phpcs - phpstan - composer validate diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 6f85fd1d..a02b5421 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -38,13 +38,23 @@ The following instructions explain how to get, build and run the latest Engelsys find resources/lang/ -type f -name '*.po' -exec sh -c 'file="{}"; msgfmt "${file%.*}.po" -o "${file%.*}.mo"' \; ``` -## Git setup (optional, recommended) -Ignore mass-changes like code formatting in Git blame: +## Pre-commit hooks +You should set up the pre-commit hook to check the code style and run tests on commit: -```bash -git config blame.ignoreRevsFile .git-blame-ignore-revs +Docker (recommended): + +```sh +echo "docker exec engelsystem_dev-es_workspace-1 bin/pre-commit" > .git/hooks/pre-commit +chmod u+x .git/hooks/pre-commit ``` +Host machine: + +```sh +ln -s ../../bin/pre-commit .git/hooks/pre-commit +``` + + ## Testing To run the unit tests use ```bash diff --git a/bin/pre-commit b/bin/pre-commit new file mode 100755 index 00000000..8049b2d1 --- /dev/null +++ b/bin/pre-commit @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +# immediate exit after an error +set -e + +yarn check +yarn lint + +composer validate +composer phpcs +composer phpstan +./vendor/bin/phpunit diff --git a/package.json b/package.json index 09e9365e..956dc958 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,10 @@ "build": "NODE_ENV=production yarn build:webpack", "build:webpack": "webpack", "build:watch": "webpack --watch", - "lint": "yarn lint:eslint && yarn lint:prettier", + "lint": "yarn lint:eslint && yarn lint:prettier && yarn lint:ec", "lint:eslint": "eslint .", "lint:prettier": "prettier --check resources/assets", + "lint:ec": "ec --exclude \"node_modules|vendor|public/assets|.git\"", "lint:fix": "yarn lint:fix:eslint && yarn lint:fix:prettier", "lint:fix:eslint": "eslint --fix .", "lint:fix:prettier": "prettier --write resources/assets" @@ -31,6 +32,7 @@ "bootstrap-icons": "^1.10.2", "css-loader": "^6.7.2", "css-minimizer-webpack-plugin": "^3.4.1", + "editorconfig-checker": "^5.0.1", "eslint": "^8.28.0", "eslint-plugin-editorconfig": "^4.0.2", "mini-css-extract-plugin": "^2.7.0", diff --git a/yarn.lock b/yarn.lock index b96c771d..1d3fb0ac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1762,6 +1762,11 @@ domutils@^2.8.0: domelementtype "^2.2.0" domhandler "^4.2.0" +editorconfig-checker@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/editorconfig-checker/-/editorconfig-checker-5.0.1.tgz#cb4bf7a9b80f1b63b141b8897d7cc326fce0d3ae" + integrity sha512-6hXq9VVDkyCxVYKdGtIj+yhVR1fi/6W6Ykz/+kItLPARulJvr2/VXgWZ5OGWx1UYm2RD6XOzWyx1JF6DLgQ/8Q== + editorconfig@^0.15.0: version "0.15.3" resolved "https://registry.yarnpkg.com/editorconfig/-/editorconfig-0.15.3.tgz#bef84c4e75fb8dcb0ce5cee8efd51c15999befc5"