Add formatting pre-commit to elixir projects.

pull/10/head
Joshua Potter 2023-11-29 09:18:10 -07:00
parent ac84906dad
commit 1b4efbce4b
8 changed files with 68 additions and 12 deletions

View File

@ -10,4 +10,4 @@ for path in $filesToFormat
do do
clang-format -i "$path" clang-format -i "$path"
git add "$path" git add "$path"
done; done

View File

@ -1,3 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if command -v git > /dev/null && on_git_branch; then
git config --local core.hooksPath .githooks/
fi
use flake use flake

View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
filesToFormat=$(
git --no-pager diff --name-status --no-color --cached | \
awk '$1 != "D" && $2 ~ /\.exs?$/ {print $NF}'
)
for path in $filesToFormat
do
mix format "$path"
git add "$path"
done

View File

@ -8,11 +8,6 @@ entering this directory (refer to `.envrc`). Otherwise run via:
$> nix develop $> nix develop
``` ```
## Language Server
The [elixir-ls](https://github.com/elixir-lsp/elixir-ls) LSP (version 0.17.10)
is included in this flake.
## Dependencies ## Dependencies
This project pins Mix dependencies using [mix2nix](https://github.com/ydlr/mix2nix). This project pins Mix dependencies using [mix2nix](https://github.com/ydlr/mix2nix).
@ -23,3 +18,19 @@ mix2nix > deps.nix
As of now, `mix2nix` cannot handle git dependencies found inside the `mix.lock` As of now, `mix2nix` cannot handle git dependencies found inside the `mix.lock`
file. If you have git dependencies, add them manually or use file. If you have git dependencies, add them manually or use
[FODs](https://nixos.org/manual/nixpkgs/stable/#packaging-beam-applications). [FODs](https://nixos.org/manual/nixpkgs/stable/#packaging-beam-applications).
## Language Server
The [elixir-ls](https://github.com/elixir-lsp/elixir-ls) LSP (version 0.17.10)
is included in this flake.
## Formatting
Formatting depends on the `mix format` task. A `pre-commit` hook is included in
`.githooks` that can be used to format all `*.exs?` files prior to commit.
Install via:
```bash
$> git config --local core.hooksPath .githooks/
```
If running [direnv](https://direnv.net/), this hook is installed automatically
when entering the directory.

View File

@ -1,3 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if command -v git > /dev/null && on_git_branch; then
git config --local core.hooksPath .githooks/
fi
use flake use flake

View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
filesToFormat=$(
git --no-pager diff --name-status --no-color --cached | \
awk '$1 != "D" && $2 ~ /\.exs?$/ {print $NF}'
)
for path in $filesToFormat
do
mix format "$path"
git add "$path"
done

View File

@ -34,11 +34,6 @@ and then start the local server:
$> mix phx.server $> mix phx.server
``` ```
## Language Server
The [elixir-ls](https://github.com/elixir-lsp/elixir-ls) LSP (version 0.17.10)
is included in this flake.
## Dependencies ## Dependencies
This project pins Mix dependencies using [mix2nix](https://github.com/ydlr/mix2nix). This project pins Mix dependencies using [mix2nix](https://github.com/ydlr/mix2nix).
@ -49,3 +44,19 @@ mix2nix > deps.nix
As of now, `mix2nix` cannot handle git dependencies found inside the `mix.lock` As of now, `mix2nix` cannot handle git dependencies found inside the `mix.lock`
file. If you have git dependencies, add them manually or use file. If you have git dependencies, add them manually or use
[FODs](https://nixos.org/manual/nixpkgs/stable/#packaging-beam-applications). [FODs](https://nixos.org/manual/nixpkgs/stable/#packaging-beam-applications).
## Language Server
The [elixir-ls](https://github.com/elixir-lsp/elixir-ls) LSP (version 0.17.10)
is included in this flake.
## Formatting
Formatting depends on the `mix format` task. A `pre-commit` hook is included in
`.githooks` that can be used to format all `*.exs?` files prior to commit.
Install via:
```bash
$> git config --local core.hooksPath .githooks/
```
If running [direnv](https://direnv.net/), this hook is installed automatically
when entering the directory.

View File

@ -10,4 +10,4 @@ for path in $filesToFormat
do do
black --quiet "$path" black --quiet "$path"
git add "$path" git add "$path"
done; done