Skip to content

Commit

Permalink
Add ':default' custom indentation rule
Browse files Browse the repository at this point in the history
  • Loading branch information
camsaul committed Aug 20, 2024
1 parent 8d8e26d commit 47715d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cljfmt/src/cljfmt/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
8 changes: 8 additions & 0 deletions cljfmt/test/cljfmt/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 47715d7

Please sign in to comment.