greglook / cljstyle

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

Make everything inner, but keep multi-arity alignment #85

Open wilkerlucio opened 2 years ago

wilkerlucio commented 2 years ago

Hello, in my configurations of cljstyle I would like for most things to use [[:ident 0]] format, so the basics would start like:

{:rules
 {:indentation
  {:indents
   {#".*" [[:inner 0]]}}}}

The issue I have is after doing this, a multi-arity fn starts to get indent in a weird way:

; before changing config, this is the indentation:
(defn multi-arity
  ([] (multi-arity {}))
  ([arg]
   ; here, body aligns with args
   (do-stuff)))

; after the config it turns into this:
(defn multi-arity
  ([] (multi-arity {}))
  ([arg]
    ; after the change cljstyle adds one more space here
    (do-stuff)))

Is there a way to keep the wildcard but still use a single space in the case of multi-arity fn?

eneroth commented 2 years ago

Hi Wilker,

I'm experimenting with this config, which seems to achieve what you're looking for:

{:rules
 {:whitespace  {:remove-surrounding? true
                :remove-trailing?    true
                :insert-missing?     true}
  :indentation {:indents {#"^:?require$" [[:inner 0]]
                          #"^:?import$"  [[:inner 0]]
                          #"^:?use$"     [[:inner 0]]
                          #"^[^ \[]"     [[:inner 0]]
                          or             [[:block 0]]
                          and            [[:block 0]]
                          do             [[:block 0]]}}
  :vars        {:enabled? false}
  :namespaces  {:enabled? false}}}