aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTerje Larsen <terlar@gmail.com>2024-01-12 20:10:45 +0100
committerGitHub <noreply@github.com>2024-01-12 12:10:45 -0700
commit1d6f8217847607e1017b0e8c510b5692ce228757 (patch)
tree3ae7cef43095213c12e43cbd0e871df69b1eee88 /test
parent923cd12108c7230c251bcaaf0699b7bc3c5c7fb4 (diff)
Add support for `treefmt` (#280)
This formatter is formatting via [treefmt](https://numtide.github.io/treefmt). This is useful if the project is configuring formatters for the project and you don't have to replicate this logic within Emacs, but instead utilize treefmt directly. To do that you can set the `apheleia-formatter` to `treefmt` within the projects `.dir-locals.el`. I noticed there are tests for this, since treefmt could technically format anything, I went with treefmt formatting rust code. It also relies on having a `treefmt.toml` in the project folder, so had to add that as well in the tests.
Diffstat (limited to 'test')
-rw-r--r--test/formatters/installers/treefmt.bash11
-rw-r--r--test/formatters/samplecode/treefmt/in.rs12
-rw-r--r--test/formatters/samplecode/treefmt/out.rs9
3 files changed, 32 insertions, 0 deletions
diff --git a/test/formatters/installers/treefmt.bash b/test/formatters/installers/treefmt.bash
new file mode 100644
index 0000000..ac42f01
--- /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 <<EOT >> /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 0000000..e09c014
--- /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 0000000..28db64c
--- /dev/null
+++ b/test/formatters/samplecode/treefmt/out.rs
@@ -0,0 +1,9 @@
+fn foo() {
+ println!("a");
+}
+
+fn bar() {
+ println!("b");
+
+ println!("c");
+}