greglook / cljstyle

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

Doc improvement suggestion - the `:inner` rule examples #82

Open masmatsum opened 2 years ago

masmatsum commented 2 years ago

Hi, I think that the current examples in the doc is not very good for us (cljstyle newbies) to understand the rule.

1. [:inner 1] examples

Current examples and problem

{foo [[:inner 1]]}

Current example

(foo bar
  baz
  (bang
    quz
    qoz))

seems wrong, since this is actually formatted as below:

;; === :indents {foo [[:inner 1]]} ===
(foo bar
     baz
     (bang
       quz
       qoz))

Also, when :list-indent is default value (2), cljstyle formats the bang form the same as above, even in the absence of the rule foo [[:inner 1]].

Compare these 2 formatted codes:

;; === :indentation {:list-indent 2, :indents {}} ===
(foo bar
     baz
     (bang
       quz
       qoz))
;; === :indentation {:list-indent 2, :indents {foo [[:inner 1]]}} ===
(foo bar
     baz
     (bang
       quz
       qoz))

The indentations of these 2 codes are completely same. So I think this example is not very good to understand [:inner 1].

Suggestion

I suggest a slightly different example:

;; === :indentation {:list-indent 2, :indents {}} ===
(foo bar
     baz
     (bang quz
           qoz))
;; === :indentation {:list-indent 2, :indents {foo [[:inner 1]]}} ===
(foo bar
     baz
     (bang quz
       qoz))

Here, the bang forms are differently indented, so this is easy to understand the effect of [:inner 1].

2. [:inner 0] examples

Current examples and problem

{foo [[:inner 0]]}

Current example

(foo bar
  baz
  bang)

is okay, but it is a little difficult to understand what 0 (:inner's parameter) means.

Suggestion

The suggested example above can also be used to explain {foo [[:inner 0]]}.

;; === :indentation {:list-indent 2, :indents {foo [[:inner 0]]}} ===
(foo bar
  baz
  (bang quz
        qoz))

This helps us understand the difference between {foo [[:inner 0]]} and {foo [[:inner 1]]}. Please consider it.

Environment