greglook / cljstyle

A tool for formatting Clojure code
Eclipse Public License 1.0
293 stars 39 forks source link

Comment formatting #30

Closed greglook closed 3 years ago

greglook commented 4 years ago

So far cljstyle mostly avoids moving comments around or otherwise formatting them, but there are a few rules that come to mind as useful additions:

sogaiu commented 4 years ago

I don't know if this counts as comment formatting, but I end up with things that look like this:

(clojure.test/deftest test-at-line-425
  (clojure.test/is (= true (discard-with-form?
                             '(:discard
                                (:whitespace " ")
                                (:map
                                  (:keyword ":a") (:whitespace " ")
                                  (:number "1")))))))
;; XXX: iiuc, discard forms in parcera can have up to 2
;;      elements in them.  if there are two elements,
;;      the first is whitespace.
;;
;;      if the understanding above is false, the following
;;      code should be modified.
(defn undiscard
  [ast]
  (when (discard-with-form? ast)
    (->> (rest ast)
         (drop-while whitespace?)
         first)))

I'd like for there to be a line between the last line of the first deftest form and the first line of the comment. I tried a variety of configuration settings without much success.

FWIW, the following is what I had in .cljstyle to produce the output above:

{:indentation? true
 :insert-missing-whitespace? true
 :insert-padding-lines? true
 :line-break-functions? true
 :max-consecutive-blank-lines 0
 :padding-lines 1
 :remove-consecutive-blank-lines? true
 :remove-surrounding-whitespace? true
 :remove-trailing-whitespace? true
 :require-eof-newline? true}

The settings above were tuned a bit to try to have a single line between top-level forms -- and that seemed to be working.

Any ideas?