clj-kondo

https://github.com/clj-kondo/clj-kondo
ericdallo 2021-05-11T15:17:41.438800Z

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

ericdallo 2021-05-12T13:06:43.452900Z

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

borkdude 2021-05-12T14:19:38.453600Z

I will get to it, currently afk

1๐Ÿ‘
borkdude 2021-05-11T15:18:08.439200Z

yes

ericdallo 2021-05-11T15:18:26.439400Z

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

ericdallo 2021-05-11T15:18:37.439600Z

it uses the project one only

ericdallo 2021-05-11T15:18:41.439800Z

is that right?

borkdude 2021-05-11T15:19:01.440Z

I think it should merge it

borkdude 2021-05-11T15:19:13.440200Z

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

ericdallo 2021-05-11T15:19:43.440500Z

example: home

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

borkdude 2021-05-11T15:19:55.440700Z

yes, that should be the case

borkdude 2021-05-11T15:20:14.440900Z

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

ericdallo 2021-05-11T15:20:31.441100Z

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

:lint-as {c d}

borkdude 2021-05-11T15:20:52.441300Z

repro welcome

ericdallo 2021-05-11T15:20:59.441500Z

is there any easy way to test it via cli?

borkdude 2021-05-11T15:21:06.441700Z

no

ericdallo 2021-05-11T15:21:11.441900Z

alright

ericdallo 2021-05-11T15:43:38.442100Z

LMK if I'm doing anything wrong: https://github.com/clj-kondo/clj-kondo/issues/1279

borkdude 2021-05-11T15:44:16.442400Z

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

borkdude 2021-05-11T15:46:01.442600Z

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

ericdallo 2021-05-11T15:46:40.442800Z

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

borkdude 2021-05-11T15:47:11.443Z

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

borkdude 2021-05-11T15:48:30.443200Z

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

ericdallo 2021-05-11T15:56:46.443400Z

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

ericdallo 2021-05-11T15:57:06.443600Z

let me confirm if now it gets merged correctly

borkdude 2021-05-11T15:57:33.443800Z

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

borkdude 2021-05-11T15:57:43.444Z

but XDG_CONFIG_HOME overrides this

borkdude 2021-05-11T15:58:02.444200Z

like it should

ericdallo 2021-05-11T15:58:15.444400Z

for some reason the home one always worked :thinking_face:

ericdallo 2021-05-11T15:58:30.444600Z

does that support was dropped recently?

borkdude 2021-05-11T15:59:06.444800Z

no, it has always worked like this

1
borkdude 2021-05-11T16:00:24.445100Z

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

ericdallo 2021-05-11T16:01:08.445500Z

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

ericdallo 2021-05-11T16:01:17.445700Z

anyway, I'll update the config location

ericdallo 2021-05-11T16:01:20.445900Z

thanks for the help ๐Ÿ™‚

borkdude 2021-05-11T16:04:51.446600Z

(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))))

borkdude 2021-05-11T16:04:57.446800Z

that function is still the same today

ericdallo 2021-05-11T16:07:03.447Z

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

ericdallo 2021-05-11T16:07:22.447200Z

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

borkdude 2021-05-11T16:07:41.447400Z

yes

borkdude 2021-05-11T16:07:43.447600Z

it does

ericdallo 2021-05-11T16:07:57.447800Z

oh, so that makes sense now

ericdallo 2021-05-11T16:08:09.448Z

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

ericdallo 2021-05-11T16:08:20.448200Z

everything makes sense now hahah

ericdallo 2021-05-11T16:08:32.448400Z

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

ericdallo 2021-05-11T16:08:42.448600Z

the home config must be on XDG or .config

ericdallo 2021-05-11T16:53:01.448800Z

@borkdude 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

ericdallo 2021-05-11T16:53:05.449Z

does that makes sense for you?

ericdallo 2021-05-11T16:53:36.449200Z

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

ericdallo 2021-05-11T16:58:52.449500Z

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

borkdude 2021-05-11T17:13:29.449700Z

I was afk for dinner, let's see

borkdude 2021-05-11T17:14:35.449900Z

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

borkdude 2021-05-11T17:15:13.450100Z

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

borkdude 2021-05-11T17:15:30.450300Z

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

ericdallo 2021-05-11T17:44:14.450500Z

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

ericdallo 2021-05-11T17:44:23.450700Z

So it doesn't find the confif

borkdude 2021-05-11T17:45:33.450900Z

yes, this is because you introduced the local config later

ericdallo 2021-05-11T17:45:50.451100Z

I think this is the same issue @leoiacovini was having

borkdude 2021-05-11T17:45:51.451300Z

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

borkdude 2021-05-11T17:47:33.451500Z

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

borkdude 2021-05-11T17:48:10.451800Z

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

borkdude 2021-05-11T17:48:40.452Z

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

borkdude 2021-05-11T17:49:13.452200Z

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

1๐Ÿ‘
borkdude 2021-05-11T17:49:31.452400Z

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

ericdallo 2021-05-11T17:49:33.452600Z

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