Fork me on GitHub
#clj-kondo
<
2020-11-21
>
ikitommi09:11:47

there is no way to declare a “vector of maps” with clj-kondo type system? seems that the collections have just type :vector.

ikitommi09:11:01

would be happy to emit {:op :vector :elements {:op :keys, :req {:id :int}} for clj-kondo

borkdude09:11:59

currently not supported

borkdude09:11:16

it's not a higher order type system

borkdude09:11:49

the likelihood of catching these types of errors with static analysis is also rather small I'd say

borkdude09:11:15

because clj-kondo can only look at the literal forms

didibus18:11:34

Hum, I thought it used type hints as well no? Wouldn't it catch:

(def ^String foo (get-foo-from-config))

(+ 10 foo)

borkdude18:11:46

It could catch that, but currently it doesn't look at var types, only function return values.

borkdude18:11:35

but the example ikitommi was referring to was a vector of maps

borkdude18:11:43

and clj-kondo only cares about the outer type

didibus18:11:28

Ah I see. Ya, I know no support for generic types yet. I was more commenting to the literal comment. So I guess it looks at literal and function return types for now? Which is slightly more than just literals 😛

didibus18:11:53

But I assumed it was looking at Var and local binding types as well.

borkdude18:11:17

yes, it does. this gives a warning:

(defn foo ^String []) (inc (foo))

ikitommi09:11:21

true that, most likely not declared as literal, right

ikitommi10:11:30

I believe “maybe string” is :nilable/string, is there a way to say “maybe map”?

borkdude10:11:30

does :nilable/map work? :)

borkdude10:11:47

else #{nil :map} will also work

ikitommi10:11:15

oh, I was thinking about a :keys thing. but #{nil {:op :keys, :req {:id :int}}} is ok?

borkdude10:11:04

it seems that if it can be nil, then all keys are optional is the same?

borkdude10:11:17

oh, op keys assumes it is a map and not nil, I see

borkdude11:11:59

If someone is looking for some OSS issues to work on, here's a list: https://gist.github.com/borkdude/18af5d96c6465ce64144f03636fda3dc

dominicm21:11:08

I find the "feature" template a little awkward for suggesting new lints for clj-kondo. I don't know how to phrase a "problem statement" in the way it seems to suggest. Nor do I have an idea for what to put in for alternatives.

borkdude22:11:54

Well, it would be nice if a linting rule solves a particular problem, else it's pretty useless right? ;)

borkdude22:11:00

But feel free to discuss new rules here first, then we can always decide if this should become an issue or not

borkdude22:11:50

Ah I see you already posted them. One of them was already implemented. Nice :)