Fork me on GitHub
Adrian Smith21:06:07

hey how does the missing map keys feature work in clj-kondo? What's an example that would make clj-kondo flag this?


@sfyire do you mean this?

$ clj-kondo --lint - <<< '{:a}'
<stdin>:1:2: error: missing value for key :a

Adrian Smith21:06:45

ah I see, I misunderstood yeah I think so


@sfyire How did you understand it initially?

Adrian Smith21:06:50

I thought it was some kind of key checking, not sure how that would have worked


@sfyire clj-kondo also has something like that, although you should configure it yourself:

{:op :keys, :req {:a :string} :opt {:b :int}}


I use it in one place in clj-kondo where I must make a map with 5 keys, of which I always forget at least one. clj-kondo reminds me what additional keys I should provide

Adrian Smith21:06:58

that's quite cool I didn't realise that was possible

Adrian Smith22:06:58

I'm going to try and see if I can get that working on an example function

Adrian Smith22:06:18

What have I done wrong here?

Adrian Smith22:06:53

My test code looks like this:


:args should be a vector

Adrian Smith22:06:02

yeah I've put that back in, was just reading some more docs but no dice so far

Adrian Smith22:06:08

ah what I should try is updating in case my version is old


always a good plan

Adrian Smith22:06:41

just moved from 2020.01.13 -> 2020.05.09


The type stuff is already from Autumn 2019


$ clj-kondo --lint /tmp/foo.clj --config '{:linters
                        {:level :warning
                          {full-name {:arities {1 {:args [{:op :keys
                                                           :req {:first-name :string
                                                                 :last-name :string}}]}}}}}}}}'
/tmp/foo.clj:5:12: warning: Missing required key: :first-name
/tmp/foo.clj:5:12: warning: Missing required key: :last-name
linting took 43ms, errors: 0, warnings: 2


(ns foo)

(defn full-name [_])

(full-name {})


I'm afk now

Adrian Smith22:06:36

ah cool I'll try that out locally thank you for your help

Adrian Smith22:06:38

ah it helps if I update the jar file the lsp plugin in cursive is pointed to