From 0a2ec1b4ae548fc4cfeca3fa4ca10579e6a97cf9 Mon Sep 17 00:00:00 2001 From: Terje Larsen Date: Mon, 8 Jan 2024 19:33:17 +0100 Subject: [PATCH] Add support for `treefmt` --- CHANGELOG.md | 1 + apheleia-formatters.el | 1 + test/formatters/installers/treefmt.bash | 11 +++++++++++ test/formatters/samplecode/treefmt/in.rs | 12 ++++++++++++ test/formatters/samplecode/treefmt/out.rs | 9 +++++++++ 5 files changed, 34 insertions(+) create mode 100644 test/formatters/installers/treefmt.bash create mode 100644 test/formatters/samplecode/treefmt/in.rs create mode 100644 test/formatters/samplecode/treefmt/out.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c02196f..d0e7a56e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ The format is based on [Keep a Changelog]. clojurescript, edn files. ([#271]) * Stylua is used now in `lua-ts-mode` as well as just `lua-mode`, by default ([#275]). +* [`treefmt`](https://numtide.github.io/treefmt) for project configured formatters ([#280]). ### Bugs fixed * Apheleia sometimes failed to determine indent level from Emacs diff --git a/apheleia-formatters.el b/apheleia-formatters.el index c96c4c5f..a9c08b43 100644 --- a/apheleia-formatters.el +++ b/apheleia-formatters.el @@ -185,6 +185,7 @@ (stylua . ("stylua" "-")) (rustfmt . ("rustfmt" "--quiet" "--emit" "stdout")) (terraform . ("terraform" "fmt" "-")) + (treefmt . ("treefmt" "--stdin" filepath)) (xmllint . ("xmllint" "--format" "-")) (yapf . ("yapf")) (yq-csv . ("yq" "--prettyPrint" "--no-colors" diff --git a/test/formatters/installers/treefmt.bash b/test/formatters/installers/treefmt.bash new file mode 100644 index 00000000..ac42f01d --- /dev/null +++ b/test/formatters/installers/treefmt.bash @@ -0,0 +1,11 @@ +ver="$(latest_release numtide/treefmt)" + +wget "https://github.com/numtide/treefmt/releases/download/${ver}/treefmt-x86_64-unknown-linux-gnu.tar.gz" -O - | tar -C /usr/local/bin -xz +chmod +x /usr/local/bin/treefmt + +apt-get install -y rustfmt +cat <> /tmp/treefmt.toml +[formatter.rust] +command = "rustfmt" +includes = ["*.rs"] +EOT diff --git a/test/formatters/samplecode/treefmt/in.rs b/test/formatters/samplecode/treefmt/in.rs new file mode 100644 index 00000000..e09c014b --- /dev/null +++ b/test/formatters/samplecode/treefmt/in.rs @@ -0,0 +1,12 @@ +fn foo() { + println!("a"); +} + + + +fn bar() { + println!("b"); + + + println!("c"); +} diff --git a/test/formatters/samplecode/treefmt/out.rs b/test/formatters/samplecode/treefmt/out.rs new file mode 100644 index 00000000..28db64c3 --- /dev/null +++ b/test/formatters/samplecode/treefmt/out.rs @@ -0,0 +1,9 @@ +fn foo() { + println!("a"); +} + +fn bar() { + println!("b"); + + println!("c"); +}