Fork me on GitHub
#clj-kondo
<
2023-01-30
>
bherrmann13:01:10

Howdy. I'm using "let-def" instead of "let" to debug some things. Using emacs/lsp/clj-kondo I get warnings (which I find visually hard to ignore) around my "let-def" ... I tried

$ cat ~/.clj-kondo/config.edn 
{:lint-as {myspace/let-def clojure.core/let } }
but I still get warnings. Does lsp use a different config location??

borkdude13:01:54

Can you try without clojure-lsp?

clj-kondo --lint your.clj

borkdude13:01:29

oh you have it in your home config? this is not the right location. It should be:

~/.config/clj-kondo/config.edn

bherrmann13:01:31

Humm.... I wonder if I'm out of date.

$ /home/linuxbrew/.linuxbrew/Cellar/clj-kondo/2022.11.02/bin/clj-kondo --lint migrate/migrate_bt_code.clj 
migrate/migrate_bt_code.clj:45:13: error: Unresolved symbol: cols
migrate/migrate_bt_code.clj:46:9: error: Unresolved symbol: nxt
migrate/migrate_bt_code.clj:47:9: error: Unresolved symbol: authorrity-id-bch
migrate/migrate_bt_code.clj:48:9: error: Unresolved symbol: authority-description-bch
migrate/migrate_bt_code.clj:49:9: error: Unresolved symbol: authority-id
...
those are the let-def bindings

borkdude13:01:07

can you make a fully standalone git repo with a repro? then I'll have a look in an hour or so

borkdude13:01:26

also insert the config in the in .clj-kondo/config.edn in the repo root

bherrmann13:01:22

https://github.com/bherrmann7/let-def-issue fyi, command line clj-kondo only reports 1 issue - yet emacs now shows 2... joy. but anyway, the single issue is in the repo.

borkdude14:01:18

move config.edn to .clj-kondo/config.edn

borkdude14:01:25

and then:

$ clj-kondo --lint m/my_boat.clj
linting took 26ms, errors: 0, warnings: 0

borkdude14:01:05

if you're using clojure-lsp, you might have to restart your session (once you put the config in the right place, I've seen two issues during this conversation!): lsp-workspace-restart

bherrmann20:01:17

Humm.....

$ clojure-lsp --version
clojure-lsp 2022.05.03-12.35.40
clj-kondo 2022.04.26-SNAPSHOT

bherrmann20:01:32

I think thats my problem.

borkdude21:01:52

upgrading wouldn't hurt, but after that it should work. let me know if you run into any other stuff

bherrmann02:01:58

~/let-def-issue$ clojure-lsp --version
clojure-lsp 2023.01.26-11.08.16
clj-kondo 2023.01.20
~/let-def-issue$ emacs m/my_boat.clj
# emacs shows 2 errors in file
~/let-def-issue$ clj-kondo --lint m/my_boat.clj
m/my_boat.clj:10:11: error: Unresolved symbol: puma
linting took 10ms, errors: 1, warnings: 0
~/let-def-issue$ rm -rf .clj-kondo/
~/let-def-issue$ clj-kondo --lint m/my_boat.clj
linting took 10ms, errors: 0, warnings: 0
~/let-def-issue$

seems like emacs/clojure-lsp is not using ~/.clj-kondo/config.edn

bherrmann03:01:52

fyi: CIDER 1.6.0 (Buenos Aires)

borkdude07:01:57

As I said earlier the home config should be in .config/clj-kondo

bherrmann16:01:57

Sorry, I somehow missed that I had the config.edn file in the wrong directory. FYI: It seems clj-kondo reads from it though.

$ strace clj-kondo --lint m/my_boat.clj 2>&1 |grep --color config.edn
stat("/home/bob.herrmann/.clj-kondo/config.edn", {st_mode=S_IFREG|0664, st_size=133, ...}) = 0
open("/home/bob.herrmann/.clj-kondo/config.edn", O_RDONLY|O_LARGEFILE) = 4
lstat("/home/bob.herrmann/.clj-kondo/config.edn", {st_mode=S_IFREG|0664, st_size=133, ...}) = 0
but then I if I move the config (as you suggest)
$ strace clj-kondo --lint m/my_boat.clj 2>&1 |grep --color config.edn
stat("/home/bob.herrmann/.config/clj-kondo/config.edn", {st_mode=S_IFREG|0664, st_size=133, ...}) = 0
open("/home/bob.herrmann/.config/clj-kondo/config.edn", O_RDONLY|O_LARGEFILE) = 4
It uses that also. And! emacs/clojure-lsp seemed to like the latter one! (like you said.) Woo Hoo!! THANKS 👍 🔥 👍 🔥

🎉 2
borkdude16:01:05

@U0502D2GL It reads that file because it's the first .clj-kondo/config.edn it comes across in a parent directory. If you would have that config in $project/.clj-kondo/config it wouldn't have searched higher up.

bherrmann19:01:31

Great, thanks. It is working great. And I'm very very happy. Seems irrational to be so excited about such a small thing, but man it kicks butt.

Daniel Jomphe21:01:37

After, what, 2 years of using clj-kondo, this is my first non-understood (potentially) false positive. Cheers for such a great, unobtrusive tool!!! With that said, here's what's puzzling me:

borkdude21:01:31

Can you post a snippet where I can reproduce this locally?

Daniel Jomphe21:01:41

Sure, thanks a lot!!

(defn foo
  ([^clojure.lang.Symbol var-sym]
   var-sym)
  ([^String a-ns
    ^String a-name
    & {:keys [debug?]}]       ; remove both this & keys ...
   (str a-ns a-name debug?))) ;         and `debug?`    ... and error goes away

(foo 'inc)

borkdude21:01:52

Interesting, yes, this looks like a bug

Daniel Jomphe21:01:20

Might have appeared around the time we switched to Clojure 1.11.

borkdude21:01:21

Just place a #_:clj-kondo/ignore before (foo 'inc) to get rid of it

borkdude21:01:36

(as a workaround, I'll fix it)

Daniel Jomphe21:01:56

Yes, but I use it in many areas 🙂 Thanks a lot Michiel!

borkdude22:01:10

You can put this in your config to repair the type inference:

{:linters {:type-mismatch
           {:namespaces
            {dude
             {foo
              {:arities {1 {:args [:symbol]}
                         :varargs {:args [:string :string {:op :rest :spec :any}]}}}}}}}}

☝️ 2
2
Daniel Jomphe22:01:37

Yes, this does it - thanks a lot for the workaround. I'll keep an eye on release notes in the future to know when to remove the workaround. 🙂

Daniel Jomphe22:01:50

Subscribed to issue and starred the repo, thanks a lot again!!

2
😆 2