clj-kondo

https://github.com/clj-kondo/clj-kondo
Adrian Smith 2020-06-04T21:45:07.346200Z

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

borkdude 2020-06-04T21:46:02.346600Z

@sfyire do you mean this?

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

Adrian Smith 2020-06-04T21:46:45.346900Z

ah I see, I misunderstood yeah I think so

borkdude 2020-06-04T21:48:48.347300Z

@sfyire How did you understand it initially?

Adrian Smith 2020-06-04T21:51:50.348700Z

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

borkdude 2020-06-04T21:53:18.349700Z

@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

borkdude 2020-06-04T21:56:45.351Z

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 Smith 2020-06-04T21:56:58.351100Z

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

Adrian Smith 2020-06-04T22:00:58.352900Z

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

Adrian Smith 2020-06-04T22:12:18.353100Z

What have I done wrong here?

Adrian Smith 2020-06-04T22:12:53.353400Z

My test code looks like this:

borkdude 2020-06-04T22:16:29.353800Z

:args should be a vector

Adrian Smith 2020-06-04T22:18:02.354Z

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

Adrian Smith 2020-06-04T22:21:08.354200Z

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

borkdude 2020-06-04T22:21:38.354400Z

always a good plan

Adrian Smith 2020-06-04T22:21:41.354600Z

just moved from 2020.01.13 -> 2020.05.09

borkdude 2020-06-04T22:22:10.354800Z

The type stuff is already from Autumn 2019

borkdude 2020-06-04T22:22:30.355Z

$ 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

borkdude 2020-06-04T22:22:44.355200Z

(ns foo)

(defn full-name [_])

(full-name {})

borkdude 2020-06-04T22:23:17.355500Z

works here

borkdude 2020-06-04T22:23:24.355700Z

I'm afk now

Adrian Smith 2020-06-04T22:23:36.355900Z

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

Adrian Smith 2020-06-04T22:40:38.356100Z

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