Fork me on GitHub
#clj-kondo
<
2022-03-11
>
Jakub18:03:31

According to docs ^:replace is supposed to also apply to inner parts when merging configs, but it does not seem to work for me. Should both examples result in {:linters {:b 2}} or something else?

(clj-kondo.impl.config/merge-config! {:linters {:a 1}} ^:replace {:linters {:b 2}})
;; => {:linters {:b 2}}

(clj-kondo.impl.config/merge-config! {:linters {:a 1}} {:linters ^:replace {:b 2}})
;; => {:linters {:a 1, :b 2}}

borkdude18:03:36

There might be a bug, PR welcome to fix it

👍 1
borkdude19:03:13

@kloud Looking at the code, it seems ^:replace was ever only support to replace top level configs

Jakub19:03:39

There are hints in the https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md that it should work for nested options: > The ^:replace metadata hint can be used to replace parts or all of the configuration instead of merging with previous ones. The home dir config is implicitly part of :config-paths. To opt out of merging with home dir config use :config-paths ^:replace [] in your project config.

borkdude19:03:15

True. And it does work for this particular case

Jakub19:03:34

I see, I inferred that it might work for other options 🙂

borkdude19:03:38

I guess it should not hurt performance too much if we check for meta on the deep-merge function, but it might be good to double check this on large merges

Jakub19:03:57

Would it make sense to have separate functions? add a new one for config merging and keep the old one for the analyzer for perf reasons?

borkdude19:03:10

I'm not sure if that distinction makes sense

borkdude19:03:02

since this merge with replace can happen anywhere

borkdude19:03:18

(if we decide to support that)

borkdude19:03:45

I think checking meta should be fast and then getting the replace key if there is meta should also be fast, so the overhead should not be gigantic

borkdude19:03:52

but it's worth checking that

Jakub19:03:33

Another option could be also a shallow merge of top-level keys. In my case I just need to override :linters but keep the inferred paths to keep hooks working.

borkdude19:03:04

I'm open to both options

Jakub19:03:09

I will give it a try

borkdude20:03:08

I didn't realize you were that Jakub btw, good to "see" you again :)

Jakub20:03:35

no conferences.. long time no see indeed 🙂

Jakub20:03:42

are you coming to clojured in June?

Jakub20:03:00

cool, see you there

borkdude20:03:26

We were discussing liz in #babashka-sci-dev recently, maybe it's fun for you to read it back

borkdude20:03:36

See you there!

borkdude20:03:46

Still in Prague btw?

Jakub20:03:59

yup, still in Prague :flag-cz:

metal 1
borkdude19:03:23

Maybe that was intentional, not sure