/ in .cljfmt.edn breaks regular expressions in :indents
With this config:
"calva.fmt.configPath": "CLOJURE-LSP"
and with this .cljfmt.edn:
{:indents {#re ".*" [[:inner 0]]}
:extra-indents {/ [[:default 1]]}}
This is ClojureLSP Server Info:
"cljfmt-raw": "{:indents {#\".*\" [[:inner 0]]}, :extra-indents {/ [[:default 1]]}}"
This breaks the regular expression in :indents so I get behavior like this:
(let [a 1]
a)
This makes me think that the regular expression is broken because now Calva is doing the default for everything (the let indentation having been overwritten by the regular expression in :indents)
If I remove the / then things start working properly.
I've tried
#re "/"
#re "\/"
#re "\\/"
None of those work. I think the problem is in how Calva is getting all the cljfmt indents as regular expressions instead of symbols?
Pinging @PEZ here since he has more knowledge about formatting-related things in Calva.
Isn't this that Calva is using 0.12.0 of cljfmt and the parsing of the config croaks, throwing cljfmt into using default indentation for everything?
Please try with v2.0.490 of Calva, @davidyang. It's using 0.13.0 of cljfmt which introduces the :default indentation specification.
Hi @PEZ - just downloaded 2.0.490 and it fixes the :default parsing but doesn't fix the / breaking the regex handling. If I have that / in my extra-indents then the regex I have in :indents isn't handled properly.
I can't reproduce. I tried this:
{:remove-surrounding-whitespace? true
:remove-trailing-whitespace? true
:remove-consecutive-blank-lines? true
:insert-missing-whitespace? true
:indents {#re ".*" [[:inner 0]]}
:extra-indents {/ [[:default 1]]}
:test {:fooa (fooa 1
2
{:a a
:aa a
:bbb bbb})
:foo (foo 1
2
3)
:foob (foob 1
2
3)
:baz (bazzo 1
:x)
:with (with-something 1
:x)
:with-special (with-special 1
:x)
:let (let []
hello)
:-> (-> foo/bar
1
2)
:/ (/ 1
2
3
4)}
:test-2 (defn f [x]
x)}
Calva's formatter formats it to what I pasted here, and cljmft cli agrees:
❯ cljfmt check .cljfmt.edn
All source files formatted correctly
There's something I'm missing here...
If I take your file, right after I hit enter after the let [] it goes
here (making me think the :indents regex isn't being honored). What do
your cljfmt-raw look like from Clojure LSP Server Info? Is it possible
this is incorrect:
"cljfmt-raw": "{:remove-trailing-whitespace? true, :remove-consecutive-blank-lines? false, :sort-ns-references? true, :indents {#"." [[:inner 0]]}, :extra-indents {returning-let [[:block 1]], = [[:default 0]], < [[:default 0]], this-as [[:block 1]], memoize [[:block 1]], <= [[:default 0]], * [[:default 0]], -> [[:default 0]], p/then [[:block 1]], > [[:default 0]], timing/trace [[:block 1]], some->> [[:default 0]], and-let [[:block 1]], - [[:default 0]], or [[:default 0]], system/defkey [[:inner 0] [:inner 1]], page [[:block 1]], / [[:default 0]],
= [[:default 0]], some-> [[:default 0]], head [[:block 1]], rum.core/bind-context [[:block 1]], + [[:default 0]], rum.core/derived-atom [[:block 2]], str [[:default 0]], returning [[:block 1]], == [[:default 0]], and [[:default 0]], ->> [[:default 0]], locking-value [[:block 1]]}}"
[image: Screenshot 2025-03-09 at 2.33.06 PM.png]
On Sun, Mar 9, 2025 at 1:51 PM Peter Strömberg @.***> wrote:
I can't reproduce. I tried this:
{:remove-surrounding-whitespace? true :remove-trailing-whitespace? true :remove-consecutive-blank-lines? true :insert-missing-whitespace? true :indents {#re ".*" [[:inner 0]]} :extra-indents {/ [[:default 1]]}
:test {:fooa (fooa 1 2 {:a a :aa a :bbb bbb}) :foo (foo 1 2 3) :foob (foob 1 2 3) :baz (bazzo 1 :x) :with (with-something 1 :x) :with-special (with-special 1 :x) :let (let [] hello) :-> (-> foo/bar 1 2) :/ (/ 1 2 3 4)} :test-2 (defn f [x] x)}
Calva's formatter formats it to what I pasted here, and cljmft cli agrees:
❯ cljfmt check .cljfmt.edn All source files formatted correctly
There's something I'm missing here...
— Reply to this email directly, view it on GitHub https://github.com/BetterThanTomorrow/calva/issues/2744#issuecomment-2708986002, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACNRJHU7C5SDGJNHGKALL2TR5R3AVCNFSM6AAAAABYSGDPHKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMBYHE4DMMBQGI . You are receiving this because you were mentioned.Message ID: @.***> [image: PEZ]PEZ left a comment (BetterThanTomorrow/calva#2744) https://github.com/BetterThanTomorrow/calva/issues/2744#issuecomment-2708986002
I can't reproduce. I tried this:
{:remove-surrounding-whitespace? true :remove-trailing-whitespace? true :remove-consecutive-blank-lines? true :insert-missing-whitespace? true :indents {#re ".*" [[:inner 0]]} :extra-indents {/ [[:default 1]]}
:test {:fooa (fooa 1 2 {:a a :aa a :bbb bbb}) :foo (foo 1 2 3) :foob (foob 1 2 3) :baz (bazzo 1 :x) :with (with-something 1 :x) :with-special (with-special 1 :x) :let (let [] hello) :-> (-> foo/bar 1 2) :/ (/ 1 2 3 4)} :test-2 (defn f [x] x)}
Calva's formatter formats it to what I pasted here, and cljmft cli agrees:
❯ cljfmt check .cljfmt.edn All source files formatted correctly
There's something I'm missing here...
— Reply to this email directly, view it on GitHub https://github.com/BetterThanTomorrow/calva/issues/2744#issuecomment-2708986002, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACNRJHU7C5SDGJNHGKALL2TR5R3AVCNFSM6AAAAABYSGDPHKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMBYHE4DMMBQGI . You are receiving this because you were mentioned.Message ID: @.***>
I see. So it's the indenter, not the formatter. Thanks! I'll have a closer look.
We seem to try to support JS regexes, so a leading / trips things up. Right now I can't remember or even imagine a reason why we would want to support that.