clj-commons / clj-commons/formatter

Empty lines between forms

Open
#10 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
35
Forks
1
PR merge metrics
No merged PRs in 30d

Description

How many empty lines should go between forms? A few options here:

* Don't touch this at all, leave any newlines between forms alone
* One line between each form
* Two lines between each form

_Originally posted by @PEZ in https://github.com/clj-commons/formatter/issues/2#issuecomment-445526899_

***

**Between top level forms**
Some people suggest to use two lines. Having tried that, I have kind of started to like it. But I am not using it for all forms.

```clojure
(def foo :foo)
(def bar :bar)

(defn re-pos-first
"Find position of first match of `re` in `s`"
[re s]
(if-let [m (.match s re)]
(.-index m)
-1))

(defn split-into-lines
[s]
(clojure.string/split s #"\r?\n" -1))

(defn enclosing? [text]
(let [ast (cljify (paredit/parse text))
children (:children ast)]
(and (= 1 (count children))
(= "list" (:type (first children))))))
```

I think the pattern I follow might be that forms that are often one-liners get zero lines between them and otherwise I opt for two. Maybe the formatter could use these rules:

* No empty lines between one-liner forms
* X (whatever we agree on) empty newlines between multi-line forms, as well as between one-liner forms and multi-line forms.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the formatting policy described in this issue and compare the listed alternatives with the example Clojure forms. No implementation files or tests are named, so locate the formatter entry point and existing spacing tests before proceeding. Done means an agreed rule for empty lines between top-level forms, covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.