Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cljfmt/src/cljfmt/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,10 @@
(when-not (ns-require-form? grandparent-node)
(when (or (z/vector? grandparent-node)
(z/list? grandparent-node))
(first (z/child-sexprs grandparent-node))))))
(some-> (z/find (-> grandparent-node z/down skip-meta)
(comp skip-meta z/right)
symbol-node?)
z/sexpr)))))

#?(:clj (defn- join-ns-str [parent-namespace current-ns]
(if parent-namespace
Expand Down
51 changes: 50 additions & 1 deletion cljfmt/test/cljfmt/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,56 @@
" (method [this x]"
" \"This is a docstring for a protocol method.\"))"]
opts)
"only :cljs; skip metadata in front of symbol"))))
"only :cljs; skip metadata in front of symbol")))
(testing "reader conditionals in ns (:require ...) should be handled correctly"
(let [opts '{:remove-blank-lines-in-forms? true
:extra-blank-line-forms {potemkin/defprotocol+ :all}
:extra-indents {potemkin/defprotocol+ [[:block 1] [:inner 1]]}
#?@(:cljs [:alias-map {"p" "potemkin"}])}]
(is (reformats-to?
["(ns x"
"(:require"
"#?@(:clj [[potemkin :as p]])))"
""
"(#?(:clj p/defprotocol+ :cljs defprotocol) Protocol"
"(my-method [_this]"
"\"This is a great method.\")"
""
"(another-method [_this]"
"\"Another nice method.\"))"]
["(ns x"
" (:require"
" #?@(:clj [[potemkin :as p]])))"
""
"(#?(:clj p/defprotocol+ :cljs defprotocol) Protocol"
" (my-method [_this]"
" \"This is a great method.\")"
""
" (another-method [_this]"
" \"Another nice method.\"))"]
opts))
(is (reformats-to?
["(ns x"
"(:require"
"#?(:clj [potemkin :as p])))"
""
"(#?(:clj p/defprotocol+ :cljs defprotocol) Protocol"
"(my-method [_this]"
"\"This is a great method.\")"
""
"(another-method [_this]"
"\"Another nice method.\"))"]
["(ns x"
" (:require"
" #?(:clj [potemkin :as p])))"
""
"(#?(:clj p/defprotocol+ :cljs defprotocol) Protocol"
" (my-method [_this]"
" \"This is a great method.\")"
""
" (another-method [_this]"
" \"Another nice method.\"))"]
opts)))))

(testing "namespaced maps"
(is (reformats-to?
Expand Down
Loading