Skip to content

Commit 05886be

Browse files
committed
Don't remove blank lines from exempted forms in function literals
1 parent d7e7bb9 commit 05886be

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

cljfmt/src/cljfmt/core.cljc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,14 +743,17 @@
743743

744744
(defn- matching-form-index? [zloc [k indexes] context]
745745
(if (= :all indexes)
746-
(and (z/list? zloc)
746+
(and (or (z/list? zloc)
747+
(= (z/tag zloc) :fn))
747748
(form-matches-key? (z/down zloc) k context))
748749
(and (z/list? (z/up zloc))
749750
(form-matches-key? zloc k context)
750751
(contains? (set indexes) (dec (index-of zloc))))))
751752

752753
(defn- matching-form? [zloc form-indexes context]
753-
(and (or (z/list? zloc) (z/list? (z/up zloc)))
754+
(and (or (z/list? zloc)
755+
(= (z/tag zloc) :fn)
756+
(z/list? (z/up zloc)))
754757
(some #(matching-form-index? zloc % context) form-indexes)))
755758

756759
(defn align-form-columns [form aligned-forms opts]

cljfmt/test/cljfmt/core_test.cljc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,22 @@
14221422
" (sequential? x)"
14231423
" :seq)"]]
14241424
(is (reformats-to? form form {:remove-blank-lines-in-forms? true}))))
1425+
(testing "Handle #() function literals"
1426+
(let [form ["(defn increase [y]"
1427+
" (let [f #(cond"
1428+
" (pos? y)"
1429+
" (inc %)"
1430+
""
1431+
" (neg? y)"
1432+
" (dec %)"
1433+
""
1434+
" :else"
1435+
" %)]"
1436+
" (f y)))"]]
1437+
(is (reformats-to?
1438+
form
1439+
form
1440+
{:remove-blank-lines-in-forms? true}))))
14251441
(testing (str ":blank-line-forms :all should only exempt the immediate"
14261442
" children of the form")
14271443
(is (reformats-to?

0 commit comments

Comments
 (0)