Fork me on GitHub
#clj-kondo
<
2020-07-08
>
dominicm13:07:31

Random thought (rooted in how many of these I have due to react) that I wanted to get some basic feedback on before opening an issue: linting unused arguments when calling a function which destructures in it's arglist.

dominicm13:07:09

(defn foo [{:keys [a b]}])

...

(foo {:c 10})
For react, this is a lot of code because of props.

dominicm13:07:28

Obviously it only works for literal maps, but I still think it's pretty useful for that?

borkdude14:07:30

What do you mean with unused arguments?

borkdude14:07:42

Something else than clj-kondo already does apparently?

dominicm14:07:41

*unused parameters that should be

dominicm14:07:00

So in the above example you'd lint :c is not a used key

borkdude14:07:25

I don't think Clojure works that way in most cases: data is passing through all the time which is not used in one place but maybe down the line

dominicm14:07:22

It would be specifically for arglists destructuring where :as is not used.

borkdude14:07:58

I think in most cases Clojure doesn't care about extra keys, except maybe in edges of systems

dominicm14:07:37

Wouldn't be an error, for sure. It's for when something is removed from use I guess.

dominicm14:07:10

Hmm, which would be a breaking change I guess. Only in internal use is it not. So perhaps not a good choice. But then again, arglists are warned about.

dominicm14:07:36

The change that got me here was removing a keyword arg from a component, and then replacing uses of that arg with a different one.

borkdude15:07:45

clj-kondo does have an option to check for required keys

dominicm16:07:16

I don't see that in the list of optional linters, could you point me the right way?

borkdude18:07:19

@dominicm it's part of the type stuff: https://github.com/borkdude/clj-kondo/blob/master/doc/types.md so you explicitly have to state the required and optional keys for a function's argument

borkdude18:07:41

I use it in one place in clj-kondo where I need to construct a map with 5 keys of which I always forget one