Browse Source

feat: set up husky and pre commit hook for linting and format check

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
pull/3867/head
dw-0 11 months ago
parent
commit
69eb529625
  1. 7
      .husky/pre-commit
  2. 1
      DEVELOPMENT.md
  3. 26
      git-hooks/pre-commit
  4. 16
      package-lock.json
  5. 3
      package.json

7
.husky/pre-commit

@ -0,0 +1,7 @@
# Run lint and abort if there are any lint errors
# --quiet will supress warnings which would cause this check to fail too
# this is temporary until all warnings are fixed
npm run lint --quiet || exit 1
# Run format:check on modified and uncommitted files and abort if there are any formatting errors
npm run format:check --uncommitted || exit 1

1
DEVELOPMENT.md

@ -14,7 +14,6 @@
1. Run `npm install` 1. Run `npm install`
1. Run `docker compose --env-file ./.env -f docker/docker-compose.dev.yml up -d` to start [PostgreSQL](https://www.postgresql.org) and [Redis](https://redis.io) 1. Run `docker compose --env-file ./.env -f docker/docker-compose.dev.yml up -d` to start [PostgreSQL](https://www.postgresql.org) and [Redis](https://redis.io)
1. Run `npm run database:setup` to initialize the database schema 1. Run `npm run database:setup` to initialize the database schema
1. Run `git config core.hooksPath ./git-hooks/` to setup git hooks
1. Start the [server](#start-server) and the [client](#start-client) 1. Start the [server](#start-server) and the [client](#start-client)
1. Open https://localhost:4200/en in your browser 1. Open https://localhost:4200/en in your browser
1. Create a new user via _Get Started_ (this first user will get the role `ADMIN`) 1. Create a new user via _Get Started_ (this first user will get the role `ADMIN`)

26
git-hooks/pre-commit

@ -1,26 +0,0 @@
#!/bin/bash
# Will check if "npm run format" is run before executing.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
echo "Running npm run format"
# Run the command and loop over its output
FILES_TO_STAGE=""
i=0
while IFS= read -r line; do
# Process each line here
((i++))
if [ $i -le 2 ]; then
continue
fi
if [[ $line == Done* ]]; then
break
fi
FILES_TO_STAGE="$FILES_TO_STAGE $line"
done < <(npm run format)
git add $FILES_TO_STAGE
echo "Files formatted. Committing..."

16
package-lock.json

@ -143,6 +143,7 @@
"eslint-plugin-cypress": "2.15.1", "eslint-plugin-cypress": "2.15.1",
"eslint-plugin-import": "2.29.1", "eslint-plugin-import": "2.29.1",
"eslint-plugin-storybook": "0.6.15", "eslint-plugin-storybook": "0.6.15",
"husky": "^9.1.6",
"jest": "29.7.0", "jest": "29.7.0",
"jest-environment-jsdom": "29.7.0", "jest-environment-jsdom": "29.7.0",
"jest-preset-angular": "14.1.0", "jest-preset-angular": "14.1.0",
@ -20653,6 +20654,21 @@
"node": ">=8.12.0" "node": ">=8.12.0"
} }
}, },
"node_modules/husky": {
"version": "9.1.6",
"resolved": "https://registry.npmjs.org/husky/-/husky-9.1.6.tgz",
"integrity": "sha512-sqbjZKK7kf44hfdE94EoX8MZNk0n7HeW37O4YrVGCF4wzgQjp+akPAkfUK5LZ6KuR/6sqeAVuXHji+RzQgOn5A==",
"dev": true,
"bin": {
"husky": "bin.js"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/typicode"
}
},
"node_modules/hyperdyperid": { "node_modules/hyperdyperid": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/hyperdyperid/-/hyperdyperid-1.2.0.tgz", "resolved": "https://registry.npmjs.org/hyperdyperid/-/hyperdyperid-1.2.0.tgz",

3
package.json

@ -33,7 +33,7 @@
"format:check": "nx format:check", "format:check": "nx format:check",
"format:write": "nx format:write", "format:write": "nx format:write",
"help": "nx help", "help": "nx help",
"lint": "nx lint", "lint": "nx run-many --target=lint --all",
"ng": "nx", "ng": "nx",
"nx": "nx", "nx": "nx",
"postinstall": "prisma generate", "postinstall": "prisma generate",
@ -188,6 +188,7 @@
"eslint-plugin-cypress": "2.15.1", "eslint-plugin-cypress": "2.15.1",
"eslint-plugin-import": "2.29.1", "eslint-plugin-import": "2.29.1",
"eslint-plugin-storybook": "0.6.15", "eslint-plugin-storybook": "0.6.15",
"husky": "9.1.6",
"jest": "29.7.0", "jest": "29.7.0",
"jest-environment-jsdom": "29.7.0", "jest-environment-jsdom": "29.7.0",
"jest-preset-angular": "14.1.0", "jest-preset-angular": "14.1.0",

Loading…
Cancel
Save