Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threaded cond-> indents strangely #45

Open
duelinmarkers opened this issue Jul 19, 2015 · 6 comments
Open

Threaded cond-> indents strangely #45

duelinmarkers opened this issue Jul 19, 2015 · 6 comments

Comments

@duelinmarkers
Copy link

cond-> and cond->> fit neatly into bigger -> forms, but the default indenting rules don't seem to work for that usage when conditions and threaded forms are each on their own line.

So cljfmt likes this:

(-> v
    (cond->
     a b
     c d))

But wants to change this:

(-> v
    (cond->
      a
      b
      c
      d))

like so:

 (-> v
     (cond->
-      a
+     a
       b
       c
       d))

It wants the first arg indented 1 space, the rest indented 2.

(Incidentally my out of date version of cider doesn't like either of those indentations and has its own bad ideas about always treating the first arg specially.)

@weavejester
Copy link
Owner

cljfmt currently doesn't take the outer form into consideration when performing indentation. Perhaps a rule can be added to look for an outer -> form, and if so, shift the indentation around.

@duelinmarkers
Copy link
Author

I don't think looking at the outer form should be necessary, I just included it to motivate my not wanting to treat the first argument as special. It seems to me a better rule for cond-> and cond->> would be [[:inner 0]], so all of the following would be considered correct:

(cond-> a
  b c
  d e)

(-> v
    (cond->
      a b
      c d))

(-> v
    (cond->
      a
      b
      c
      d))

@weavejester
Copy link
Owner

What about this form:

(-> v
    (cond-> a b
            c d))

There are also other forms that are affected by an outer ->. For example:

(-> (StringBuilder.)
    (doto
      (.append "foo")
      (.append "bar"))
    (.toString))

I think it's worth putting in a specific rule for -> like forms.

@colinphill-reify
Copy link

colinphill-reify commented Sep 17, 2021

Popping in to say I've also encountered this. It seems that it's less to do with nesting forms and more to do with the placement of the first value in a threading form, so that cljfmt will issue suggestions like this even when there is only one threading form:

(cond->
-  a
+ a
   b
   c
   d))

When the threaded value is given its own line, cljfmt wants it indented by one space – but wants subsequent forms indented by two. This caused a bit of confusion for my team when a happened to be a map, so that it looked like cljfmt wanted us to align b, c, and d as if they were members of the map.

It may be worth noting that, besides being a little bit surprising, this formatting is also incompatible with parinfer.

@miridius
Copy link
Contributor

Are there any plans to fix/support this? It's causing us some issues due to style conflicts with other editors/formatters

@weavejester
Copy link
Owner

I'm happy to accept a pull request for this, of course, but I don't have any plans in the near future for resolving this myself. Unfortunately I have a backlog of issues and features that I need to tackle before this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants