Skip to content

Commit

Permalink
Ignore metadata in front of first symbol when looking for matching rules
Browse files Browse the repository at this point in the history
  • Loading branch information
camsaul committed Aug 20, 2024
1 parent 8d8e26d commit c01ee51
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 c01ee51

Please sign in to comment.