formatter icon indicating copy to clipboard operation
formatter copied to clipboard

Formatting let bindings

Open danielcompton opened this issue 6 years ago • 5 comments
trafficstars

Similar to #7 on formatting maps, how should let bindings be formatted? Should all of the init-forms (right hand side) be aligned, or have a ragged alignment?

(let [a nil
      very-long-symbol {}])

;; or

(let [a                nil
      very-long-symbol {}])

Should lines that are destructuring collections be handled differently? They can get very long and would cause large gaps in let bindings if they were included.

danielcompton avatar Dec 09 '18 01:12 danielcompton

I vote for aligning ”simple” let bindings and handle the destructuring ones differently. What that ”differently” means is another matter. What are some common patterns in use out there?

PEZ avatar Dec 09 '18 10:12 PEZ

As with #7 there is the issue of enforcing alignment might make adding bindings cause some diff tools to report more differences than really are there.

PEZ avatar Dec 09 '18 10:12 PEZ

I vote for aligning ”simple” let bindings and handle the destructuring ones differently. What that ”differently” means is another matter. What are some common patterns in use out there?

Cursive just puts one space between the binding and the init-form:

(let [subject-date (js/goog.date.DateTime.)
      a            nil
      {:keys [x y z ab]} {}]
...

danielcompton avatar Dec 09 '18 22:12 danielcompton

What I started to think about was rather how people format the destructurings, but maybe that is just following any rules for maps and vectors?

PEZ avatar Dec 10 '18 19:12 PEZ

Ah right, yes that's also another thing to consider, and would probably end up being treated the same.

danielcompton avatar Dec 10 '18 23:12 danielcompton