Skip to content

Commit a6c2100

Browse files
authored
Merge pull request #259 from or/refactor-cljfmt-options
Move cljfmt default options into cljfmt.core
2 parents f9113eb + 50ee262 commit a6c2100

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

cljfmt/src/cljfmt/core.cljc

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -400,26 +400,37 @@
400400
(defn remove-multiple-non-indenting-spaces [form]
401401
(transform form edit-all non-indenting-whitespace? replace-with-one-space))
402402

403+
(def default-options
404+
{:indentation? true
405+
:insert-missing-whitespace? true
406+
:remove-consecutive-blank-lines? true
407+
:remove-multiple-non-indenting-spaces? false
408+
:remove-surrounding-whitespace? true
409+
:remove-trailing-whitespace? true
410+
:split-keypairs-over-multiple-lines? false
411+
:indents default-indents
412+
:alias-map {}})
413+
403414
(defn reformat-form
404415
([form]
405416
(reformat-form form {}))
406417
([form opts]
407-
(-> form
408-
(cond-> (:split-keypairs-over-multiple-lines? opts false)
409-
(split-keypairs-over-multiple-lines))
410-
(cond-> (:remove-consecutive-blank-lines? opts true)
411-
remove-consecutive-blank-lines)
412-
(cond-> (:remove-surrounding-whitespace? opts true)
413-
remove-surrounding-whitespace)
414-
(cond-> (:insert-missing-whitespace? opts true)
415-
insert-missing-whitespace)
416-
(cond-> (:remove-multiple-non-indenting-spaces? opts false)
417-
remove-multiple-non-indenting-spaces)
418-
(cond-> (:indentation? opts true)
419-
(reindent (:indents opts default-indents)
420-
(:alias-map opts {})))
421-
(cond-> (:remove-trailing-whitespace? opts true)
422-
remove-trailing-whitespace))))
418+
(let [opts (merge default-options opts)]
419+
(-> form
420+
(cond-> (:split-keypairs-over-multiple-lines? opts)
421+
(split-keypairs-over-multiple-lines))
422+
(cond-> (:remove-consecutive-blank-lines? opts)
423+
remove-consecutive-blank-lines)
424+
(cond-> (:remove-surrounding-whitespace? opts)
425+
remove-surrounding-whitespace)
426+
(cond-> (:insert-missing-whitespace? opts)
427+
insert-missing-whitespace)
428+
(cond-> (:remove-multiple-non-indenting-spaces? opts)
429+
remove-multiple-non-indenting-spaces)
430+
(cond-> (:indentation? opts)
431+
(reindent (:indents opts) (:alias-map opts)))
432+
(cond-> (:remove-trailing-whitespace? opts)
433+
remove-trailing-whitespace)))))
423434

424435
#?(:clj
425436
(defn- ns-require-form? [zloc]

cljfmt/src/cljfmt/main.clj

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,7 @@
149149
(def default-options
150150
{:project-root "."
151151
:file-pattern #"\.clj[csx]?$"
152-
:ansi? true
153-
:indentation? true
154-
:insert-missing-whitespace? true
155-
:remove-multiple-non-indenting-spaces? false
156-
:remove-surrounding-whitespace? true
157-
:remove-trailing-whitespace? true
158-
:remove-consecutive-blank-lines? true
159-
:split-keypairs-over-multiple-lines? false
160-
:indents cljfmt/default-indents
161-
:alias-map {}})
152+
:ansi? true})
162153

163154
(defn merge-default-options [options]
164155
(-> (merge default-options options)
@@ -182,25 +173,25 @@
182173
:default (:ansi? default-options)
183174
:id :ansi?]
184175
[nil "--[no-]indentation"
185-
:default (:indentation? default-options)
176+
:default (:indentation? cljfmt/default-options)
186177
:id :indentation?]
187178
[nil "--[no-]remove-multiple-non-indenting-spaces"
188-
:default (:remove-multiple-non-indenting-spaces? default-options)
179+
:default (:remove-multiple-non-indenting-spaces? cljfmt/default-options)
189180
:id :remove-multiple-non-indenting-spaces?]
190181
[nil "--[no-]remove-surrounding-whitespace"
191-
:default (:remove-surrounding-whitespace? default-options)
182+
:default (:remove-surrounding-whitespace? cljfmt/default-options)
192183
:id :remove-surrounding-whitespace?]
193184
[nil "--[no-]remove-trailing-whitespace"
194-
:default (:remove-trailing-whitespace? default-options)
185+
:default (:remove-trailing-whitespace? cljfmt/default-options)
195186
:id :remove-trailing-whitespace?]
196187
[nil "--[no-]insert-missing-whitespace"
197-
:default (:insert-missing-whitespace? default-options)
188+
:default (:insert-missing-whitespace? cljfmt/default-options)
198189
:id :insert-missing-whitespace?]
199190
[nil "--[no-]remove-consecutive-blank-lines"
200-
:default (:remove-consecutive-blank-lines? default-options)
191+
:default (:remove-consecutive-blank-lines? cljfmt/default-options)
201192
:id :remove-consecutive-blank-lines?]
202193
[nil "--[no-]split-keypairs-over-multiple-lines"
203-
:default (:split-keypairs-over-multiple-lines? default-options)
194+
:default (:split-keypairs-over-multiple-lines? cljfmt/default-options)
204195
:id :split-keypairs-over-multiple-lines?]])
205196

206197
(defn- file-exists? [path]

0 commit comments

Comments
 (0)