Skip to content

Commit 735fc40

Browse files
authored
[Fix #3209] Fix cljfmt options serialization for format-code (#3866)
1 parent 75dc57a commit 735fc40

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- [#3865](https://github.com/clojure-emacs/cider/pull/3865): Add default session feature to bypass sesman's project-based dispatch (`cider-set-default-session`, `cider-clear-default-session`).
88

9+
### Bugs fixed
10+
11+
- [#3209](https://github.com/clojure-emacs/cider/issues/3209): Fix `cider-format` dropping non-map cljfmt options (e.g. `remove-consecutive-blank-lines?`).
12+
913
## 1.21.0 (2026-02-07)
1014

1115
### Changes

lisp/cider-client.el

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,16 @@ you need to encode it as the following plist:
265265
If non-nil, FORMAT-OPTIONS specifies the options cljfmt will use to format
266266
the code. See `cider-format-code-options' for details."
267267
(when format-options
268-
(let* ((indents (cadr (assoc "indents" format-options)))
269-
(alias-map (cadr (assoc "alias-map" format-options))))
270-
(apply #'nrepl-dict
271-
`(,@(when indents
272-
`("indents" ,(thread-last indents
273-
(seq-mapcat #'identity)
274-
(apply #'nrepl-dict))))
275-
,@(when alias-map
276-
`("alias-map" ,(thread-last alias-map
277-
(seq-mapcat #'identity)
278-
(apply #'nrepl-dict)))))))))
268+
(apply #'nrepl-dict
269+
(thread-last format-options
270+
(seq-mapcat
271+
(pcase-lambda (`(,key ,value))
272+
(list key
273+
(if (member key '("indents" "alias-map"))
274+
(thread-last value
275+
(seq-mapcat #'identity)
276+
(apply #'nrepl-dict))
277+
value))))))))
279278

280279
(defcustom cider-print-fn 'pprint
281280
"Sets the function to use for printing.

test/cider-client-tests.el

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,23 @@
143143
(let ((ns " (ns bar)\n"))
144144
(expect (cider-ns-form-p ns) :to-equal 0))))
145145

146+
(describe "cider--nrepl-format-code-request-options"
147+
(it "preserves non-map formatter options"
148+
(let ((opts (cider--nrepl-format-code-request-options
149+
'(("remove-consecutive-blank-lines?" t)
150+
("remove-multiple-non-indenting-spaces?" t)))))
151+
(expect (nrepl-dict-get opts "remove-consecutive-blank-lines?") :to-be-truthy)
152+
(expect (nrepl-dict-get opts "remove-multiple-non-indenting-spaces?") :to-be-truthy)))
153+
154+
(it "encodes nested map formatter options as nREPL dicts"
155+
(let* ((opts (cider--nrepl-format-code-request-options
156+
'(("indents" (("org.me/foo" (("inner" 0)))))
157+
("alias-map" (("me" "org.me"))))))
158+
(indents (nrepl-dict-get opts "indents"))
159+
(alias-map (nrepl-dict-get opts "alias-map")))
160+
(expect (nrepl-dict-get indents "org.me/foo") :to-equal '(("inner" 0)))
161+
(expect (nrepl-dict-get alias-map "me") :to-equal "org.me"))))
162+
146163
(describe "cider-expected-ns"
147164
(before-each
148165
(spy-on 'cider-connected-p :and-return-value t)

0 commit comments

Comments
 (0)