Skip to content

Commit c832761

Browse files
authored
Merge pull request #347 from camsaul/support-default-spec
Add ':default' custom indentation rule
2 parents 68d534e + 47715d7 commit c832761

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cljfmt/src/cljfmt/core.cljc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@
337337
(defmethod indenter-fn :block [sym context [_ idx]]
338338
(fn [zloc] (block-indent zloc sym idx context)))
339339

340+
(defmethod indenter-fn :default [sym context [_]]
341+
(fn [zloc]
342+
(when (form-matches-key? zloc sym context)
343+
(list-indent zloc context))))
344+
340345
(defn- make-indenter [[key opts] context]
341346
(apply some-fn (map (partial indenter-fn key context) opts)))
342347

cljfmt/test/cljfmt/core_test.cljc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,14 @@
12601260
["{:one two #_comment"
12611261
" :three four}"]
12621262
{:split-keypairs-over-multiple-lines? true}))
1263+
(is (reformats-to?
1264+
["(with-timezone (java.time.OffsetDateTime.)"
1265+
"\"US/Pacific\")"]
1266+
["(with-timezone (java.time.OffsetDateTime.)"
1267+
" \"US/Pacific\")"]
1268+
{:indents {#"^with-" [[:inner 0]]
1269+
'with-timezone [[:default]]}})
1270+
"Should be able to override fuzzy indent rules for with- and explicitly specify :default indentation")
12631271
#?(:clj
12641272
(is (reformats-to?
12651273
["(ns foo.bar"

0 commit comments

Comments
 (0)