clj-kondo

https://github.com/clj-kondo/clj-kondo
ikitommi 2020-11-21T09:37:47.488500Z

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

ikitommi 2020-11-21T09:39:01.489600Z

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

borkdude 2020-11-21T09:39:59.489800Z

currently not supported

borkdude 2020-11-21T09:40:16.490100Z

it's not a higher order type system

borkdude 2020-11-21T09:40:49.490600Z

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

borkdude 2020-11-21T09:41:15.491300Z

because clj-kondo can only look at the literal forms

2020-11-30T18:22:34.037400Z

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

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

(+ 10 foo)

borkdude 2020-11-30T18:29:46.037800Z

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

borkdude 2020-11-30T18:30:35.038Z

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

borkdude 2020-11-30T18:30:43.038200Z

and clj-kondo only cares about the outer type

2020-11-30T18:32:28.038400Z

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 😛

2020-11-30T18:32:53.038600Z

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

borkdude 2020-11-30T18:34:17.038800Z

yes, it does. this gives a warning:

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

ikitommi 2020-11-21T09:41:21.491500Z

true that, most likely not declared as literal, right

ikitommi 2020-11-21T10:13:30.492100Z

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

borkdude 2020-11-21T10:14:30.492400Z

does :nilable/map work? :)

borkdude 2020-11-21T10:15:47.492700Z

else #{nil :map} will also work

ikitommi 2020-11-21T10:21:15.493700Z

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

borkdude 2020-11-21T10:22:04.494300Z

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

borkdude 2020-11-21T10:22:17.494600Z

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

borkdude 2020-11-21T11:23:59.494900Z

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

dominicm 2020-11-21T21:59:08.497300Z

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.

borkdude 2020-11-21T22:01:54.497800Z

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

borkdude 2020-11-21T22:03:00.498300Z

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

borkdude 2020-11-21T22:08:50.498900Z

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