From bab53246c043cb12f246f9d3deacafb4579ee9b5 Mon Sep 17 00:00:00 2001
From: Joao P Dubas <joao.dubas+gitea@gmail.com>
Date: Sat, 2 Nov 2024 13:19:56 +0000
Subject: [PATCH] feat: check code quality through git hooks

---
 .tool-versions |  5 +++--
 Makefile       | 12 ++++++++++--
 lefthook.yml   | 20 ++++++++++++++++++++
 3 files changed, 33 insertions(+), 4 deletions(-)
 create mode 100644 lefthook.yml

diff --git a/.tool-versions b/.tool-versions
index 8c4dd92..893736e 100644
--- a/.tool-versions
+++ b/.tool-versions
@@ -1,2 +1,3 @@
-erlang 27.1.2
-elixir 1.17.3
+erlang   27.1.2
+elixir   1.17.3
+lefthook 1.8.2
diff --git a/Makefile b/Makefile
index 9034144..932240d 100644
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,12 @@
 
 COMPOSE = docker compose -f docker-compose.yml -f docker-compose.override.yml
 
+.PHONY: system_setup
+system_setup:  ## setup system deps
+	@lefthook install
+
 .PHONY: setup
-setup:  ## setup project
+setup: system_setup  ## setup project
 	@mkdir -p priv/plts
 	@mix do local.rebar --force, local.hex --force
 	@mix do deps.get, deps.compile
@@ -13,6 +17,10 @@ setup:  ## setup project
 check_format:  ## run format checker
 	@mix format --check-formatted
 
+.PHONY: check_compile
+check_compile:  ## run compile
+	@mix compile --warnings-as-errors --force
+
 .PHONY: credo
 credo:  ## run credo
 	@mix credo suggest --strict --format=flycheck
@@ -22,7 +30,7 @@ dialyzer:  ## run dialyzer
 	@mix dialyzer --no-check --quiet --ignore-exit-status --format short
 
 .PHONY: static_code_analysis
-static_code_analysis: check_format credo dialyzer  ## run static code analysis
+static_code_analysis: check_format check_compile credo dialyzer  ## run static code analysis
 
 .PHONY: test
 test:  ## run tests
diff --git a/lefthook.yml b/lefthook.yml
new file mode 100644
index 0000000..eaf03f1
--- /dev/null
+++ b/lefthook.yml
@@ -0,0 +1,20 @@
+---
+pre-commit:
+  parallel: true
+  commands:
+    compiling:
+      glob: &elixir_files '*.{ex,exs}'
+      run: make check_compile
+    formating:
+      glob: *elixir_files
+      run: make check_format
+    linting:
+      glob: *elixir_files
+      run: make credo
+    typing:
+      glob: *elixir_files
+      run: make dialyzer
+pre-push:
+  commands:
+    testing:
+      run: make compose_test
-- 
2.47.2