Skip to content

Commit

Permalink
Merge pull request #347 from camsaul/support-default-spec
Browse files Browse the repository at this point in the history
Add ':default' custom indentation rule
  • Loading branch information
weavejester authored Aug 21, 2024
2 parents 68d534e + 47715d7 commit c832761
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 @@ -337,6 +337,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 @@ -1260,6 +1260,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 c832761

Please sign in to comment.