Fork me on GitHub
#clj-kondo
<
2021-05-11
>
ericdallo15:05:41

Does clj-kondo merge home config with a project specific one? ๐Ÿงต

ericdallo15:05:26

I noticed if I have a home config with a custom :lint-as and add a project config that has also a :lint-as but both lint-as are different, clj-kondo doesn't merge it

ericdallo15:05:37

it uses the project one only

ericdallo15:05:41

is that right?

borkdude15:05:01

I think it should merge it

borkdude15:05:13

the project is merged in later, so the project config wins from the global config

ericdallo15:05:43

example: home

:lint-as {a b}
project
:lint-as {c d}
I would expect a final config of
:lint-as {a b
          c d}

borkdude15:05:55

yes, that should be the case

borkdude15:05:14

you can verify this if you call run! and then inspect the :config key in the result

ericdallo15:05:31

hum, I will try to make a minimal repro, but it seems to me the final result is:

:lint-as {c d}

borkdude15:05:52

repro welcome

ericdallo15:05:59

is there any easy way to test it via cli?

borkdude15:05:16

oh btw, there is also a clj-kondo.core/merge-configs function, you could test this

borkdude15:05:01

user=> (clj-kondo/merge-configs '{:lint-as {a b}} '{:lint-as {c d}})
{:lint-as {a b, c d}}

ericdallo15:05:40

Oh, nice, so why is not working for my case?

borkdude15:05:11

If you remove the project config, does it still use the home one - is your home config used at all?

borkdude15:05:30

you should put your config in ~/.config/clj-kondo or XDG_CONFIG_HOME/clj-kondo

ericdallo15:05:46

yeah, for some reason, clj-kondo is not detecting the home config, only if I move it to xdg-config one

ericdallo15:05:06

let me confirm if now it gets merged correctly

borkdude15:05:33

the config should be in ~/.config/clj-kondo, not in ~/.clj-kondo

borkdude15:05:43

but XDG_CONFIG_HOME overrides this

borkdude15:05:02

like it should

ericdallo15:05:15

for some reason the home one always worked :thinking_face:

ericdallo15:05:30

does that support was dropped recently?

borkdude15:05:06

no, it has always worked like this

thinking-face 3
borkdude16:05:24

it was implemented in issue 992, you can still find the commits

ericdallo16:05:08

the merge works fine now ๐Ÿ™‚ That's crazy, in nubank we always used the config on ~/.clj-kondo/config.edn and it always worked

ericdallo16:05:17

anyway, I'll update the config location

ericdallo16:05:20

thanks for the help ๐Ÿ™‚

borkdude16:05:51

(defn home-config []
  (let [home-dir  (if-let [xdg-config-home (System/getenv "XDG_CONFIG_HOME")]
                    (io/file xdg-config-home "clj-kondo")
                    (io/file (System/getProperty "user.home") ".config" "clj-kondo"))]
    (when (.exists home-dir)
      (read-config-from-dir home-dir))))

borkdude16:05:57

that function is still the same today

ericdallo16:05:03

yeah, it makes sense, I still don't understand how that was/is working for a lot of people

ericdallo16:05:22

maybe clj-kondo is checking recursively until / for a config?

ericdallo16:05:57

oh, so that makes sense now

ericdallo16:05:09

it was indeed using the home one when there is no project one

ericdallo16:05:20

everything makes sense now hahah

ericdallo16:05:32

because it was not considering as a home config bug a project config

ericdallo16:05:42

the home config must be on XDG or .config

ericdallo16:05:01

@U04V15CAJ I think I found a bug with a copy-configs, sorry for bother you again ๐Ÿ˜… โ€ข I have a .config/clj-kondo config with :config-paths ["nubank/state-flow"] โ€ข if the project doesn't contains a .clj-kondo dir, everything works, since clj-kondo copy the lib config to the global clj-kondo location and the config-paths works. โ€ข if the project has a .clj-kondo dir, clj-kondo will copy the lib config to the project clj-kondo, but the :config-paths from the global one will not work and the project will not have the lib config configured correctly

ericdallo16:05:05

does that makes sense for you?

ericdallo16:05:36

maybe copying the config for both places (global and project) would work?

ericdallo16:05:52

I confirmed that adding :config-paths ["nubank/state-flow"] to the project clj-kondo config works, so I think that's the issue, clj-kondo should check for config-paths on both configs and if finds, it should check for the folders on both config dirs as well

borkdude17:05:29

I was afk for dinner, let's see

borkdude17:05:35

yes, this makes sense. you should add :config-paths to the clj-kondo directory that is relative to the copied configs

borkdude17:05:13

I think you should just re-import your configs once again, if you decide that your project is going to have a .clj-kondo config

borkdude17:05:30

I don't expect this occurs very often in the lifecycle of a project (just one time)

ericdallo17:05:14

Yes, my point is that clj-kondo is copying the config to the project one but the config with the config-paths is on the global one

ericdallo17:05:23

So it doesn't find the confif

borkdude17:05:33

yes, this is because you introduced the local config later

ericdallo17:05:50

I think this is the same issue @U95713QV7 was having

borkdude17:05:51

which should not happen that frequently in the lifecycle of a project

borkdude17:05:33

where is this issue filed in the issue tracker? I have not heard about it before

borkdude17:05:10

but in my opinion this is just how it works, I don't think clj-kondo has to look in multiple places. it tells you that you should add a config dir to your local config if you copy the configs

borkdude17:05:40

if you don't agree with how that works, you can move your config to the global config as well, manually

borkdude17:05:13

perhaps I am missing something, but I'm kind of tired today and perhaps explaining it crystal clear in an issue helps

๐Ÿ‘ 3
borkdude17:05:31

and I can look it at some other day with fresh eyes

ericdallo17:05:33

the issue was in some other thread ๐Ÿ˜… My point is just that we'd like to avoid manual moves or something like that to work well will everyone that use the project, I'll try to simulate a local repro to make sure we are talking about the same thing

ericdallo13:05:43

Related to this โ˜๏ธ I created this issue: https://github.com/clj-kondo/clj-kondo/issues/1281

borkdude14:05:38

I will get to it, currently afk

๐Ÿ‘ 2