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

Indentation applied inconsistently depending on presence of ns form #267

Open
sheluchin opened this issue Jun 25, 2022 · 3 comments
Open

Comments

@sheluchin
Copy link

sheluchin commented Jun 25, 2022

I initially filed an issue in the vim-iced repo, but it looks like it's an issue with cljfmt.

Using Tonsky's formatting rule:

indentation.clj:

{#"^\w" [[:inner 0]]}

Starting file:

(ns foo)

(-> {:x 1}
  :x
  prn)

Expected result:

 (ns foo)

 (-> {:x 1}
-  :x
-  prn)
+    :x
+    prn)
1 file(s) formatted incorrectly

Actual result:

All source files formatted correctly

Now starting file with ns form commented out:

;(ns foo)

(-> {:x 1}
  :x
  prn)

Actual matches expected:

 ;(ns foo)

 (-> {:x 1}
-  :x
-  prn)
+    :x
+    prn)
1 file(s) formatted incorrectly

In summary, I expect the arguments to the threading macros to line up, as described in the style guide, but cljfmt's result differs depending on whether the file has a top-level ns form.

@weavejester
Copy link
Owner

This issue is a little hard to read. Can you put in your expected and actual values?

@sheluchin
Copy link
Author

@weavejester Sorry about that! I've edited it to make it a little easier on the eyes.

@rfhayashi
Copy link

rfhayashi commented Jul 22, 2022

I found that to happen if the namespace name starts with the string def. For example:

(require '[cljfmt.core :as cljfmt])

(def code "
(ns def)

(-> {}
    (assoc :a 1)
    (assoc :b 2))
")

(println
 (cljfmt/reformat-string code {}))

prints

(ns def)

(-> {}
  (assoc :a 1)
  (assoc :b 2))

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

3 participants