From eb04c337a18135afca8125da9aaf73ecc1f48524 Mon Sep 17 00:00:00 2001 From: Aaron Tavistock Date: Thu, 27 Apr 2023 15:23:50 -0700 Subject: [PATCH] Adding support for Elixir pre-commits --- README.md | 7 +++++++ modules/hooks.nix | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/README.md b/README.md index f0c159bc..d3965d89 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,13 @@ use nix - [elm-review](https://github.com/jfmengels/elm-review) - [elm-test](https://github.com/rtfeldman/node-test-runner) +## Elixir + +- [mix-format](https://hexdocs.pm/mix/main/Mix.Tasks.Format.html) +- [mix-test](https://hexdocs.pm/mix/1.13/Mix.Tasks.Test.html) +- [credo](https://github.com/rrrene/credo) +- [dialyzer](https://github.com/jeremyjh/dialyxir) + ## OCaml - [dune-fmt](https://dune.build/) diff --git a/modules/hooks.nix b/modules/hooks.nix index 110549ec..8268565b 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -421,6 +421,16 @@ in default = true; }; }; + + credo = { + strict = + mkOption { + type = types.bool; + description = lib.mdDoc "Whether to auto-promote the changes."; + default = true; + }; + }; + }; config.hooks = @@ -1223,5 +1233,35 @@ in in "${pkgs.dune_3}/bin/dune build @fmt ${auto-promote}"; pass_filenames = false; }; + + mix-format = { + name = "mix-format"; + descriptiion = "Runs the built-in Elixir syntax formatter"; + entry = "${pkgs.elixir}/bin/mix format"; + types = [ "elixir" ]; + }; + + mix-test = { + name = "mix-test"; + descriptiion = "Runs the built-in Elixir test framework"; + entry = "${pkgs.elixir}/bin/mix test"; + types = [ "elixir" ]; + }; + + credo = { + name = "credo"; + descriptiion = "Runs a static code analysis using Credo"; + entry = + let strict = if settings.credo.strict then "--strict" else ""; + in "${pkgs.elixir}/bin/mix credo"; + types = [ "elixir" ]; + }; + + dialyzer = { + name = "dialyzer"; + descriptiion = "Runs a static code analysis using Dialyzer"; + entry = "${pkgs.elixir}/bin/mix dialyzer"; + types = [ "elixir" ]; + }; }; }