greglook / cljstyle

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

cond does not stair-step pairs with nothing above or below it #2

Closed aengelberg closed 5 years ago

aengelberg commented 6 years ago

The cond "stair-step" behavior was originally added to add clarity to the predicates and the results, but if a cond is written with blank lines in between pairs, that added clarity is unnecessary. My proposed change to the cond rule would suppress that behavior for a pair if there is nothing interesting directly above or below it.

With the new rule, the following bodies are now both considered valid:

(cond
  (or (even? x) (> x 5))
    (call-foo x)
  (odd? x)
    (call-bar x)
  :else
    (call-baz x))
(cond
  (or (even? x) (> x 5))
  (call-foo x)

  (odd? x)
  (call-bar x)

  :else
  (call-baz x))
greglook commented 6 years ago

My initial reaction is a preference against allowing this. The point of style rules is to limit the number of valid ways to format a given form, so opening that up seems counter to that goal. Even in the blank-line-separated case, I think the extra indent on the clause expressions helps distinguish them from the conditions.

I'll think about this one some more.

aengelberg commented 6 years ago

I'll admit that I'm somewhat biased here due to my developer workflow. Emacs' clojure-mode has its own indenting engine implemented in Emacs Lisp. It is configurable with cljfmt-esque rules, but it isn't easily extensible, thus it doesn't support the new :cond rule and likely never will. So this is my way of leaving open at least one way for Emacs users to write conds in a way that their editor and linter will both approve of.

aengelberg commented 6 years ago

I'll also point out that my proposed implementation of the cond rule would still only allow one way to write any given form. It just makes a different assertion about what's "correct" depending on the spacing in between the pairs.

aengelberg commented 5 years ago

Closing this as it is obviated by amperity/cljfmt#1.