From 47715d7287f978dbc71fbca0de745c59b9545d8f Mon Sep 17 00:00:00 2001 From: Cam Saul Date: Tue, 20 Aug 2024 01:32:41 +0000 Subject: [PATCH] Add ':default' custom indentation rule --- cljfmt/src/cljfmt/core.cljc | 5 +++++ cljfmt/test/cljfmt/core_test.cljc | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/cljfmt/src/cljfmt/core.cljc b/cljfmt/src/cljfmt/core.cljc index 1e9f0e8..eb5373d 100644 --- a/cljfmt/src/cljfmt/core.cljc +++ b/cljfmt/src/cljfmt/core.cljc @@ -336,6 +336,11 @@ (defmethod indenter-fn :block [sym context [_ idx]] (fn [zloc] (block-indent zloc sym idx context))) +(defmethod indenter-fn :default [sym context [_]] + (fn [zloc] + (when (form-matches-key? zloc sym context) + (list-indent zloc context)))) + (defn- make-indenter [[key opts] context] (apply some-fn (map (partial indenter-fn key context) opts))) diff --git a/cljfmt/test/cljfmt/core_test.cljc b/cljfmt/test/cljfmt/core_test.cljc index 7721d1e..1ad4b94 100644 --- a/cljfmt/test/cljfmt/core_test.cljc +++ b/cljfmt/test/cljfmt/core_test.cljc @@ -1248,6 +1248,14 @@ ["{:one two #_comment" " :three four}"] {:split-keypairs-over-multiple-lines? true})) + (is (reformats-to? + ["(with-timezone (java.time.OffsetDateTime.)" + "\"US/Pacific\")"] + ["(with-timezone (java.time.OffsetDateTime.)" + " \"US/Pacific\")"] + {:indents {#"^with-" [[:inner 0]] + 'with-timezone [[:default]]}}) + "Should be able to override fuzzy indent rules for with- and explicitly specify :default indentation") #?(:clj (is (reformats-to? ["(ns foo.bar"