cljfmt icon indicating copy to clipboard operation
cljfmt copied to clipboard

Thread macro is not honored

Open introom opened this issue 2 years ago • 7 comments

Give the following code:

(-> zz
    (as-> x
          foo))

It should be formatted as:

(-> zz
    (as-> x
        foo))

Which also happens to be what emacs clojure mode does.

However, cljfmt thinks the code is already formatted.

Steps to reproduce: clojure -Sdeps '{:deps {cljfmt {:mvn/version "0.8.0"}}}' -m cljfmt.main check example.clj

introom avatar Mar 08 '22 14:03 introom

Why should it be formatted that way? Can you give some justification?

weavejester avatar Mar 08 '22 15:03 weavejester

It's like macro body forms two spaces indented.

foo here belongs to the body part.

https://github.com/bbatsov/clojure-style-guide#body-indentation

introom avatar Mar 08 '22 15:03 introom

Similar to the fashion foo is indented here:

(as-> y x
  foo)

introom avatar Mar 08 '22 15:03 introom

The section of the Clojure style guide you link to recommends that forms shouldn't be indented 4 spaces, but in your original post you have indented 4 spaces. Was that a typo?

weavejester avatar Mar 08 '22 15:03 weavejester

The issue is not about the format of -> but rather the inconsistency on how cljfmt handles as->.

Cljfmt requires that the body form to be two space indents, for example,

;; cljfmt thinks foo is correctly indented (1)
(as-> y
      x
  foo)

;; cljfmt thinks foo is not correctly indented (2)
(as-> y
      x
      foo)

The problem is, when the as-> is inside thread->, an implicit argument is placed; however, cljfmt seems to ignore it and formats it similar to the above case (2).

(-> y
    (as-> x
          foo))

introom avatar Mar 08 '22 15:03 introom

Ah, yes, that's a known missing feature. Currently cljfmt is not aware of the threading macros when handling block indentation.

weavejester avatar Mar 08 '22 15:03 weavejester

Duplicate of https://github.com/weavejester/cljfmt/issues/223.

or avatar May 10 '22 08:05 or

Closed due to duplicate.

weavejester avatar Feb 02 '23 15:02 weavejester