Skip to content

Commit e80c37b

Browse files
authored
Merge pull request #1217 from metosin/clj-kondo-changes
Don't automatically remove files with each `emit!`
2 parents b4ca7c2 + 288bc78 commit e80c37b

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Malli is in well matured [alpha](README.md#alpha).
1818

1919
* Performance improvements in `malli.transform/transformer` [#1220](https://github.com/metosin/malli/pull/1220)
2020
* `malli.clj-kondo/emit!` saves to `.clj-kondo/imports` now as recommended by clj-kondo. [#1216](https://github.com/metosin/malli/pull/1216)
21+
* `malli.clj-kondo/emit!` no longer deletes anything automatically. Use `malli.clj-kondo/clean!` to clean up.
2122

2223
## 0.19.1 (2025-06-09)
2324
* Technical release

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3310,13 +3310,22 @@ Generating `clj-kondo` configuration from current namespace:
33103310
; :ret :int}}}}}}}}
33113311
```
33123312

3313-
Emitting confing into `./.clj-kondo/configs/malli/config.edn`:
3313+
Emitting config into `./.clj-kondo/imports/metosin/malli-types-clj/config.edn`:
33143314

33153315
<!-- :test-doc-blocks/skip -->
33163316
```clojure
33173317
(mc/emit!)
33183318
```
33193319

3320+
Removing the generated configurations. Note that this removes also
3321+
from locations where old versions of malli used to store the
3322+
configuration file:
3323+
3324+
<!-- :test-doc-blocks/skip -->
3325+
```clojure
3326+
(mc/clean!)
3327+
```
3328+
33203329
In action:
33213330

33223331
![malli](docs/img/clj-kondo.png)

src/malli/clj_kondo.cljc

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,32 @@
145145

146146
(defn -transform [?schema options] (m/walk ?schema -walk options))
147147

148+
#?(:clj
149+
(defn -file-in-kondo-dir [options & paths]
150+
(apply io/file (into (get options :clj-kondo-dir-path []) paths))))
151+
152+
(defn -types-dir-name
153+
"Creates a directory name such as `malli-types-cljs` or `malli-types-clj`."
154+
[key]
155+
(str "malli-types-" (name key)))
156+
157+
(defn -config-file-path [key options]
158+
(-file-in-kondo-dir options ".clj-kondo" "imports" "metosin" (-types-dir-name key) "config.edn"))
159+
148160
;;
149161
;; public api
150162
;;
151163

164+
(defn clean!
165+
"Cleans existing configurations from .clj-kondo directory"
166+
([options]
167+
(clean! :clj options))
168+
([key options]
169+
(.delete (-config-file-path key options))
170+
;; These are remnants from old locations where malli used to store the configuration files
171+
(.delete (-file-in-kondo-dir options ".clj-kondo" "metosin" (-types-dir-name key) "config.edn"))
172+
(.delete (-file-in-kondo-dir options ".clj-kondo" "configs" "malli" "config.edn"))))
173+
152174
(defn transform
153175
([?schema]
154176
(transform ?schema nil))
@@ -164,17 +186,7 @@
164186
([config key]
165187
(save! config key nil))
166188
([config key options]
167-
(let [cfg-file (apply io/file (conj
168-
(get options :clj-kondo-dir-path [])
169-
;; Creates a file like malli-types-cljs or malli-types-clj.
170-
".clj-kondo" "imports" "metosin" (str "malli-types-" (name key)) "config.edn"))]
171-
;; delete the old files if they exist (does not throw)
172-
(.delete (apply io/file (conj
173-
(get options :clj-kondo-dir-path [])
174-
".clj-kondo" "metosin" (str "malli-types-" (name key)) "config.edn")))
175-
(.delete (apply io/file (conj
176-
(get options :clj-kondo-dir-path [])
177-
".clj-kondo" "configs" "malli" "config.edn")))
189+
(let [cfg-file (-config-file-path key options)]
178190
(io/make-parents cfg-file)
179191
(spit cfg-file (with-out-str (fipp/pprint config {:width 120})))
180192
config))))

0 commit comments

Comments
 (0)