weavejester / cljfmt

A tool for formatting Clojure code
Eclipse Public License 1.0
1.11k stars 120 forks source link

Docstring/comment after defn name changes indentation of the body #241

Open holyjak opened 3 years ago

holyjak commented 3 years ago

Hello! I have a mystery. With :indents ^:replace {#"^\w" [[:inner 0]]} this is aligned as I want:

      (defn X
        ([args] 
         (doit)))

but if I put any line (normally I would have there a docstring) after the X, it changes and the body of the fn is indented by 1 space too many:

      (defn X
        ;; comment
        ([args]
          (doit)))
or commented 2 years ago

I haven't tried it with the Leiningen plugin, but I can't reproduce it with tests:

    (is (reformats-to?
         ["(defn X"
          "([args]"
          "(doit)))"]
         ["(defn X"
          "  ([args]"
          "   (doit)))"]
         {:indents {#"^\w" [[:inner 0]]}}))
    (is (reformats-to?
         ["(defn X"
          "  ;; comment"
          "([args]"
          "(doit)))"]
         ["(defn X"
          "  ;; comment"
          "  ([args]"
          "   (doit)))"]
         {:indents {#"^\w" [[:inner 0]]}}))

Both of those pass. Strange.

@holyjak: is this still an issue for you?