weavejester/cljfmt

Option for/better list formatting?

tonsky opened this issue · 5 comments

cljfmt fix - 
'(1 2 3 4
  5 6 7 8)

Expected:

'(1 2 3 4
  5 6 7 8)

Actual:

'(1 2 3 4
    5 6 7 8)

I understand this is because of how :require is formatted?

I’d love a way to change that in the config (as far as I can tell, :indents {#".*" [[:inner 0]]} option only applies to lists starting with symbol, right?) or just have a better default

cljfmt currently formats quoted lists as though they were quoted forms, and uses the Clojure Style Guide recommendations on function argument alignment.

We could add in an exception when the first element is not a symbol, keyword, or list, but that may cause confusion in cases where people write lists of symbols that are intended to be data. For example, suppose someone writes:

'(a b c d
  e f g h)

Is a a function with 7 arguments, or the first element in a list of characters?

I care more about lists with non-symbol first argument tbh:

#?(:clj 1
   :cljs 2)
   
((get-fun)
 fun)
 
(:require
 [lib :as lib])

The last examples you gave are all formatted that way in cljfmt.

Putting aside reader conditionals, which are formatted like maps, formatting for lists depends on whether there are arguments on the same line as the function. e.g.

((get-fun) arg1
           arg2)

((get-fun)
 arg1
 arg2)

Maybe it’s okay then. Thank you!

I just had:

(def clj-specials
  '(catch
    def
    do
     finally
     if
     let
     quote
     recur
     try))

and was told about this issue. I worked around it with:

(def clj-specials
  '(#__
    catch
    def
    do
    finally
    if
    let
    quote
    recur
    try))