Fork me on GitHub
#clj-kondo
<
2021-07-16
>
tvaughan14:07:14

I'm using clojure-lsp for the first time, and I've noticed it triggers something (clj-kondo, I assume) which writes out clj-kondo settings into the current project directory, namely .clj-kondo/com.wsscode/pathom/config.edn and .clj-kondo/com.wsscode/async/config.edn. This happens when I run clojure-lsp clean-ns and .lsp/sqlite.db does not exist. I already have settings for com.wsscode.pathom in .clj-kondo/config.edn. I wonder if this behavior is correct, and which of these duplicate settings takes precedent when running clj-kondo (which I do frequently on its own on the command-line and via emacs and flycheck.el)? Should I remove my settings and check-in those under com.wsscode? Is there a recommended best-practice? Or is this a clojure-lsp problem and better asked in #lsp?

borkdude14:07:39

@tvaughan This happens when you run clj-kondo with :copy-configs true. The copied config isn't actually activated until you hook it into your config.edn explicitly

tvaughan14:07:01

But I'm not using :copy-configs anywhere

ericdallo14:07:16

clojure-lsp uses it when calling clj-kondo

ericdallo14:07:38

I don't see why you would want to not use that flag

ericdallo14:07:07

So, clj-kondo/clojure-lsp doesn't change your config.edn

borkdude14:07:41

the clojure-lsp command line app should probably not use copy-configs, not sure

borkdude14:07:51

perhaps it should

tvaughan14:07:56

I'm not saying I don't want to. I'm ignorant of this setting. I'm simply confused and looking for clarification on how to handle these duplicate settings

borkdude14:07:13

you can just remove the copied configs

ericdallo14:07:32

Oh, I got it, it didn't change the .clj-kondo/config.edn but the .clj-kondo/com.wsscode/pathom/config.edn

ericdallo14:07:04

yeah, that is expected indeed to make clj-kondo understand pathom macros in your code

tvaughan14:07:18

If removing the copied configs is the right choice, how do I prevent this from happening for other people on the team?

ericdallo14:07:40

also, you probably don't want to add that folder to git

borkdude14:07:56

well, you do if you end up using that config

tvaughan14:07:07

I do want to share .clj-kondo/config.edn

tvaughan14:07:17

As well as the hooks

ericdallo14:07:35

IMO, you want to version only .clj-kondo/config.edn

borkdude14:07:37

the clojure-lsp CLI should probably accept some setting for this

borkdude14:07:50

@UKFSJSM38 no, you also want to version hook code

ericdallo14:07:53

the other folder could be updated in future versions of the hook if it changes

borkdude14:07:14

you should check that stuff into git so your team mates are using the same hook code

borkdude14:07:45

and don't have to run this stuff from the command line themselves

borkdude14:07:56

but it's a choice everyone can make for them selves. I'm in favor of checking it into git

ericdallo15:07:14

yeah, it works too indeed

ericdallo15:07:59

TLDR commit the copied hooks is probably the best solution for your team

tvaughan15:07:11

In our case it's important that the team shares the same settings and hooks

👍 2
lread13:07:14

Ah... this might solve a mystery for me, I noticed that during dev of rewrite-clj, I will sometimes see rewrite-clj's configs copied under rewrite-clj's .clj-kondo dir. I'm using Calva these days so it is probably lsp -> clj-kondo with :copy-configs doing this...

yes 2
borkdude14:07:07

so it doesn't hurt necessarily, but those configs are coming from the libraries themselves, so they are likely better than what you have figured out on your own :)

☝️ 2
tvaughan14:07:22

Yes and no. They cover a couple of things I don't have in my settings, but I've also added a hook which is better

borkdude14:07:59

ah nice. perhaps you can contribute the improvements back to the lib?

tvaughan14:07:11

I could although I didn't write the hook. Someone shared it on slack and I played beta tester. Been working well for me since

tvaughan15:07:07

Bah, yeah that's correct, but it's for fulcro not pathom :man-facepalming:

Adam Helins15:07:10

(wasn't me, sorry)

tvaughan15:07:35

(ns hooks.fulcro
  ""
  {:author "Adam Helins"}
  (:require
   [clj-kondo.hooks-api :as hook]))

(defn defmutation
  [{:keys [node]}]
  (let [[_call
         sym
         & arg+] (:children node)
        docstring (first arg+)
        [[param+
          & fn-like+]
         docstring-2] (if (hook/string-node? docstring)
                        [(rest arg+)
                         docstring]
                        [arg+
                         nil])]
    {:node (hook/list-node (concat [(hook/token-node 'defn)
                                    sym]
                                   (when docstring-2
                                     [docstring-2])
                                   [param+
                                    (hook/vector-node (map #(let [[_sym
                                                                   arg+
                                                                   & body] (:children %)]
                                                              (hook/list-node (list* (hook/token-node 'fn)
                                                                                     arg+
                                                                                     body)))
                                                           fn-like+))]))}))

Adam Helins07:07:02

Oh yeah, sorry it seems I didn't see your OP, I thought it was about something else. How can I help you? I haven't done any Fulcro in a while but at that time it was working quite well, at least I didn't have any obvious issue.

tvaughan12:07:09

Likewise, it’s working well for me too. I think the only issue now is if this hook should be submitted to fulcro or clj-kondo (no clue how this works)

borkdude12:07:45

Preferably to fulcro itself

borkdude12:07:56

as that's where it will probably get the most attention and care in the future

borkdude12:07:50

Perhaps @U066U8JQJ can also help you as he has done this before for certain libraries and I think he is involved in fulcro as well...?

tvaughan12:07:04

Thanks @borkdude. @UCFG3SDFV I’d be happy to make the submission on your behalf if that’s ok with you. Which license would you like to use?

Adam Helins14:07:07

@tvaughan Perfectly fine, it's not much so feel free to rewrite what you want and use any license, I'll trust your judgement 🙂

Adam Helins14:07:19

I didn't PR it because I wasn't sure it was good enough beyond my own workflow and then went to work on something else, haven't been involved with Fulcro since then

wilkerlucio22:07:53

I hadn't create any hooks yet, but Pathom 3 and some libs export the kondo config, the main issue I had when I tried to do that was because I forgot to add resources to the source paths, with that correct it's been working fine

ericdallo14:07:48

@borkdude I didn't know clj-kondo was changing the config.edn for those cases

ericdallo14:07:56

IMO this is a good feature though 🙂

borkdude14:07:18

it is not changing the config.edn

👍 2