From a38279566a82c39253973e49a2a56634ded50212 Mon Sep 17 00:00:00 2001 From: dalu <25452934+dalugm@users.noreply.github.com> Date: Fri, 15 Dec 2023 10:03:18 +0800 Subject: [PATCH] Add support for `cljfmt` (#271) --- CHANGELOG.md | 3 +++ apheleia-formatters.el | 9 +++++++++ test/formatters/installers/cljfmt.bash | 1 + test/formatters/samplecode/cljfmt/in.clj | 12 ++++++++++++ test/formatters/samplecode/cljfmt/in.cljs | 6 ++++++ test/formatters/samplecode/cljfmt/in.edn | 4 ++++ test/formatters/samplecode/cljfmt/out.clj | 12 ++++++++++++ test/formatters/samplecode/cljfmt/out.cljs | 6 ++++++ test/formatters/samplecode/cljfmt/out.edn | 2 ++ 9 files changed, 55 insertions(+) create mode 100644 test/formatters/installers/cljfmt.bash create mode 100644 test/formatters/samplecode/cljfmt/in.clj create mode 100644 test/formatters/samplecode/cljfmt/in.cljs create mode 100644 test/formatters/samplecode/cljfmt/in.edn create mode 100644 test/formatters/samplecode/cljfmt/out.clj create mode 100644 test/formatters/samplecode/cljfmt/out.cljs create mode 100644 test/formatters/samplecode/cljfmt/out.edn diff --git a/CHANGELOG.md b/CHANGELOG.md index cf8c6ac..a6fef33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,12 +20,15 @@ The format is based on [Keep a Changelog]. ([#263]). * [denofmt](https://docs.deno.com/runtime/manual/tools/formatter) for js, jsx, ts, tsx, json, jsonc, md files. ([#264]) +* [cljfmt](https://github.com/weavejester/cljfmt) for clojure, + clojurescript, edn files. ([#271]) [#229]: https://github.com/radian-software/apheleia/pull/229 [#260]: https://github.com/radian-software/apheleia/pull/260 [#261]: https://github.com/radian-software/apheleia/pull/261 [#263]: https://github.com/radian-software/apheleia/pull/263 [#264]: https://github.com/radian-software/apheleia/pull/264 +[#271]: https://github.com/radian-software/apheleia/pull/271 ## 4.0 (released 2023-11-23) ### Breaking changes diff --git a/apheleia-formatters.el b/apheleia-formatters.el index fa48c16..2446b0e 100644 --- a/apheleia-formatters.el +++ b/apheleia-formatters.el @@ -41,6 +41,7 @@ (or (apheleia-formatters-local-buffer-file-name) (apheleia-formatters-mode-extension) ".c"))) + (cljfmt . ("cljfmt" "fix" "-")) (cmake-format . ("cmake-format" "-")) (crystal-tool-format . ("crystal" "tool" "format" "-")) (css-beautify "css-beautify" "--file" "-" "--end-with-newline" @@ -276,6 +277,14 @@ rather than using this system." (c-ts-mode . clang-format) (c++-mode . clang-format) (caml-mode . ocamlformat) + (clojure-dart-ts-mode . cljfmt) + (clojure-jank-ts-mode . cljfmt) + (clojure-mode . cljfmt) + (clojure-ts-mode . cljfmt) + (clojurec-mode . cljfmt) + (clojurec-ts-mode . cljfmt) + (clojurescript-mode . cljfmt) + (clojurescript-ts-mode . cljfmt) (cmake-mode . cmake-format) (cmake-ts-mode . cmake-format) (common-lisp-mode . lisp-indent) diff --git a/test/formatters/installers/cljfmt.bash b/test/formatters/installers/cljfmt.bash new file mode 100644 index 0000000..87f2589 --- /dev/null +++ b/test/formatters/installers/cljfmt.bash @@ -0,0 +1 @@ +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/weavejester/cljfmt/HEAD/install.sh)" diff --git a/test/formatters/samplecode/cljfmt/in.clj b/test/formatters/samplecode/cljfmt/in.clj new file mode 100644 index 0000000..c783b0f --- /dev/null +++ b/test/formatters/samplecode/cljfmt/in.clj @@ -0,0 +1,12 @@ +(ns hello +(:require [java-time.api :as t])) + +(defn time-str + "Returns a string representation of a datetime in the local time zone." + [instant] + (t/format + (t/with-zone (t/formatter "hh:mm a") (t/zone-id)) +instant)) + +(defn run [opts] +(println "Hello world, the time is" (time-str (t/instant)))) diff --git a/test/formatters/samplecode/cljfmt/in.cljs b/test/formatters/samplecode/cljfmt/in.cljs new file mode 100644 index 0000000..1649480 --- /dev/null +++ b/test/formatters/samplecode/cljfmt/in.cljs @@ -0,0 +1,6 @@ +(ns hello-world.core +(:require react-dom)) + +(.render js/ReactDOM +(.createElement js/React "h2" nil "Hello, React!") + (.getElementById js/document "app")) diff --git a/test/formatters/samplecode/cljfmt/in.edn b/test/formatters/samplecode/cljfmt/in.edn new file mode 100644 index 0000000..88af84a --- /dev/null +++ b/test/formatters/samplecode/cljfmt/in.edn @@ -0,0 +1,4 @@ +{:deps {clojure.java-time/clojure.java-time +{:mvn/version "1.1.0"} + } + } diff --git a/test/formatters/samplecode/cljfmt/out.clj b/test/formatters/samplecode/cljfmt/out.clj new file mode 100644 index 0000000..6738667 --- /dev/null +++ b/test/formatters/samplecode/cljfmt/out.clj @@ -0,0 +1,12 @@ +(ns hello + (:require [java-time.api :as t])) + +(defn time-str + "Returns a string representation of a datetime in the local time zone." + [instant] + (t/format + (t/with-zone (t/formatter "hh:mm a") (t/zone-id)) + instant)) + +(defn run [opts] + (println "Hello world, the time is" (time-str (t/instant)))) diff --git a/test/formatters/samplecode/cljfmt/out.cljs b/test/formatters/samplecode/cljfmt/out.cljs new file mode 100644 index 0000000..e985c42 --- /dev/null +++ b/test/formatters/samplecode/cljfmt/out.cljs @@ -0,0 +1,6 @@ +(ns hello-world.core + (:require react-dom)) + +(.render js/ReactDOM + (.createElement js/React "h2" nil "Hello, React!") + (.getElementById js/document "app")) diff --git a/test/formatters/samplecode/cljfmt/out.edn b/test/formatters/samplecode/cljfmt/out.edn new file mode 100644 index 0000000..9c0ad45 --- /dev/null +++ b/test/formatters/samplecode/cljfmt/out.edn @@ -0,0 +1,2 @@ +{:deps {clojure.java-time/clojure.java-time + {:mvn/version "1.1.0"}}}