From a3a5151c4da20c0a50514ae25f39d214d3f6ca97 Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Wed, 10 Apr 2024 07:32:38 -0500 Subject: [PATCH] chore: setup git hooks to run linter for you By using git hooks, you can make sure your code is linted and formatted as expected. Added docs to readme for how to install these hooks. commit-id:8d6cc4bc --- README.md | 5 +++++ lefthook.yml | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 lefthook.yml diff --git a/README.md b/README.md index c6dcd55..b01a43a 100644 --- a/README.md +++ b/README.md @@ -312,6 +312,11 @@ Follow the steps below to compile the Wendy project on your machine for contribu [mint][14] used to run other development CLI commands such as linter/formatter. [taskfile][15] an alternative to `Makefile` to run commands. +[lefthook](https://github.com/evilmartians/lefthook/blob/HEAD/docs/install.md) for git hooks. + +* Install git hooks: + +`lefthook install` * Generate the boilerplate code, otherwise you will not be able to compile the code. diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 0000000..dd08dca --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,17 @@ +# Configuration for lefthook tool to manage git hooks +# https://github.com/evilmartians/lefthook + +# Commands to run before committing code. +pre-commit: + commands: + lint: + # Format code and then `git add` modified files from formatter. + run: task format && git add {staged_files} + +# Commands to run before pushing code +pre-push: + commands: + lint: + # Run linter giving you errors to fix. + # By using `|| echo "..."`, we do not block you from pushing code. Running lint in a git hooks is to warn you about lint errors early, but not block you from pushing code with errors if you decide to push. + run: task lint || echo -e "\n\n ⚠️ Linting contains errors that will prevent you from merging a pull request. Fix errors above if you are planning on making a pull request." \ No newline at end of file