From 1972a61f28579756c3a391d45da4854b41add96f Mon Sep 17 00:00:00 2001 From: Zachary Belford Date: Wed, 21 May 2025 22:42:04 -0600 Subject: [PATCH] Add husky pre-commit hook --- .husky/_/husky.sh | 23 +++++++++++++++++++++++ .husky/pre-commit | 5 +++++ CONTRIBUTING.md | 20 ++++++++++++++++++++ README.md | 2 ++ package.json | 4 +++- 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 .husky/_/husky.sh create mode 100755 .husky/pre-commit create mode 100644 CONTRIBUTING.md diff --git a/.husky/_/husky.sh b/.husky/_/husky.sh new file mode 100755 index 000000000..071c00439 --- /dev/null +++ b/.husky/_/husky.sh @@ -0,0 +1,23 @@ +#!/bin/sh +if [ -z "$husky_skip_init" ]; then + debug() { + [ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1" + } + readonly hook_name="$(basename "$0")" + debug "starting $hook_name..." + if [ "$HUSKY" = "0" ]; then + debug "HUSKY env variable is set to 0, skipping hook" + exit 0 + fi + if [ -f ~/.huskyrc ]; then + debug "sourcing ~/.huskyrc" + . ~/.huskyrc + fi + export husky_skip_init=1 + sh -e "$0" "$@" + exitCode="$?" + if [ "$exitCode" != 0 ]; then + echo "husky - $hook_name hook exited with code $exitCode (error)" + fi + exit "$exitCode" +fi diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 000000000..2c8a6bcd2 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,5 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npm run lint +npm run format-check diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..1c83f734f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,20 @@ +# Contributing to Shardus Core + +Thank you for considering a contribution! + +## Getting Started + +Install dependencies using `npm install`. This command also sets up the git hooks required for development. + +## Commit Workflow + +Before each commit the `pre-commit` hook runs `npm run lint` and `npm run format-check`. These checks ensure that the code style and lint rules are satisfied. + +You can run them manually at any time with: + +```sh +npm run lint +npm run format-check +``` + +Please also make sure the unit tests pass with `npm test` before submitting a pull request. diff --git a/README.md b/README.md index 2bc6bdadc..604ac4702 100644 --- a/README.md +++ b/README.md @@ -67,3 +67,5 @@ This command will guide you through the steps necessary to release the package. ## Contributing Contributions are very welcome! Everyone interacting in our codebases, issue trackers, and any other form of communication, including chat rooms and mailing lists, is expected to follow our [code of conduct](./CODE_OF_CONDUCT.md) so we can all enjoy the effort we put into this project. + +Please see our [contribution guidelines](./CONTRIBUTING.md) for details on the development workflow and available npm scripts. diff --git a/package.json b/package.json index 21802f8e9..68af36ec3 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "release:minor": "npm run prepare && npm version minor && git push --follow-tags && npm publish", "release:major": "npm run prepare && npm version major && git push --follow-tags && npm publish", "format-check": "prettier --check \"**/*.{js,jsx,ts,tsx,json}\"", - "format-fix": "prettier --write \"**/*.{js,jsx,ts,tsx,json}\"" + "format-fix": "prettier --write \"**/*.{js,jsx,ts,tsx,json}\"", + "postinstall": "husky install" }, "repository": { "type": "git", @@ -107,6 +108,7 @@ "npm-run-all": "4.1.5", "prettier": "2.8.1", "replace-in-file": "6.3.5", + "husky": "^9.0.11", "shx": "0.3.4", "ts-jest": "27.0.5", "typescript": "4.9.4",