Skip to content

Commit

Permalink
Merge pull request #346 from camsaul/ignore-metadata-on-first-symbol-…
Browse files Browse the repository at this point in the history
…in-list

Fix indentation for symbols preceded by metadata
  • Loading branch information
weavejester authored Aug 21, 2024
2 parents 8d8e26d + 103984e commit 68d534e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cljfmt/src/cljfmt/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@
(some-> zloc z/down ns-token?)))

(defn- token-value [zloc]
(when (token? zloc) (z/sexpr zloc)))
(let [zloc (skip-meta zloc)]
(when (token? zloc) (z/sexpr zloc))))

(defn- reader-conditional? [zloc]
(and (reader-macro? zloc) (#{"?" "?@"} (-> zloc z/down token-value str))))
Expand Down
14 changes: 13 additions & 1 deletion cljfmt/test/cljfmt/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,19 @@
":foo)"]
["(def ^:private foo"
" :foo)"])
"hanging metadata and name on def does not hang subsequent indentation"))
"hanging metadata and name on def does not hang subsequent indentation")

(testing "metadata on the first symbol in a list should be ignored when looking for matching indentation rules"
(is (reformats-to?
["(^:amazing fn [x y]"
"(+ x y))"]
["(^:amazing fn [x y]"
" (+ x y))"]))
(is (reformats-to?
["(^{:amazing true} fn [x y]"
"(+ x y))"]
["(^{:amazing true} fn [x y]"
" (+ x y))"]))))

(testing "fuzzy matches"
(is (reformats-to?
Expand Down

0 comments on commit 68d534e

Please sign in to comment.