Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#232] Format from elixir project dir #239

Merged
merged 4 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ The format is based on [Keep a Changelog].
* Autoload the apheleia-goto-error command ([#215]).
* Use `lisp-indent` as default formatter for `emacs-lisp-mode` ([#223])
* Use `hclfmt` for formatting hashicorp HCL files ([#231])
* The `mix format` formatter will respect `.formatter.exs` files even
if they are present in a parent directory rather than the same
directory as the file being formatted ([#232]).

### Internal Changes
* Refactored the organisation of the apheleia package for ease of
Expand Down Expand Up @@ -104,6 +107,7 @@ The format is based on [Keep a Changelog].
[#215]: https://github.com/radian-software/apheleia/pull/215
[#223]: https://github.com/radian-software/apheleia/pull/223
[#231]: https://github.com/radian-software/apheleia/pull/231
[#232]: https://github.com/radian-software/apheleia/issues/232
[#236]: https://github.com/radian-software/apheleia/pull/236

## 3.2 (released 2023-02-25)
Expand Down
2 changes: 1 addition & 1 deletion apheleia-formatters.el
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
(lisp-indent . apheleia-indent-lisp-buffer)
(ktlint . ("ktlint" "--log-level=none" "--stdin" "-F" "-"))
(latexindent . ("latexindent" "--logfile=/dev/null"))
(mix-format . ("mix" "format" "-"))
(mix-format . ("apheleia-mix" "format" "-"))
(nixfmt . ("nixfmt"))
(ocamlformat . ("ocamlformat" "-" "--name" filepath
"--enable-outside-detected-project"))
Expand Down
22 changes: 22 additions & 0 deletions scripts/formatters/apheleia-mix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# This function prints the name of the current directory if it
# contains a file or directory named after the first argument, or the
# parent directory if it contains such a file, or the parent's parent,
# and so on. If no such file is found it returns nonzero.
# https://unix.stackexchange.com/a/22215
find_upwards() {
fname="$1"

path="${PWD}"
while [[ -n "${path}" && ! -e "${path}/${fname}" ]]; do
path="${path%/*}"
done
[[ -n "${path}" ]] && echo "${path}"
}

if dir="$(find_upwards .formatter.exs)"; then
cd -- "${dir}" || exit
fi

exec mix "$@"