Fork me on GitHub
#clj-kondo
<
2020-06-04
>
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?

borkdude21:06:02

@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

borkdude21:06:48

@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

borkdude21:06:18

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

{:op :keys, :req {:a :string} :opt {:b :int}}
https://github.com/borkdude/clj-kondo/blob/master/doc/types.md

borkdude21:06:45

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:

borkdude22:06:29

: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

borkdude22:06:38

always a good plan

Adrian Smith22:06:41

just moved from 2020.01.13 -> 2020.05.09

borkdude22:06:10

The type stuff is already from Autumn 2019

borkdude22:06:30

$ clj-kondo --lint /tmp/foo.clj --config '{:linters
                       {:type-mismatch
                        {:level :warning
                         :namespaces
                         {foo
                          {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

borkdude22:06:44

(ns foo)

(defn full-name [_])

(full-name {})

borkdude22:06:24

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