Fork me on GitHub
#clj-kondo
<
2020-03-11
>
didibus01:03:48

So, after talking to Alex Miller and Andy Fingerhut, it looks like putting return value type hints on the argvector and the var both work. But, the argvector should be favored in all cases.

didibus01:03:33

The argvector allows you to hint multi-arities which return different types. And it allows you to hint primitives.

didibus01:03:47

The var type hint can type hint multiple arities which return the same type all at ounce. And seems more intuitive to more people for some reason.

didibus01:03:32

So I don't know. I'm thinking a warning that recommends to type hint on the arg-vector instead of the var would be nice. But, in theory both are valid. So maybe make it an optional checker? I wouldn't mind either way. Personally, I would like it to be a default warn.

didibus01:03:18

Also, if you put it on both the var and the argvector, the argvector takes precedence.

didibus01:03:14

(defn ^String foo
  []
  "bar")
I'd make the above warn that type hints are recommended to be on argvector instead. And maybe this:
(defn ^String foo
  ^String []
  "bar")
Be a warn that there are two type hints defined for the same function.

didibus01:03:56

Where as this would not warn:

(defn foo
  ^String []
  "bar")
or
(defn foo
  (^String []
  "bar"))

serioga07:03:28

Well, I remember cases when the hint before var did not work. But unfortunately I cannot reproduce it in simple test case.

serioga07:03:35

Also contract for defn from “The Essential Reference” does not mention ret-typehint before name at all.

serioga07:03:33

In my file above the type hints before name also work

borkdude10:03:57

@didibus Might be good to extract all this information into an issue on Github

Twan10:03:53

Hi! I was wondering if there exists a proper solution to this behavior:

(ns example
  (:require
   [hiccup.form :refer :all]))

(defn something []
  (form-to [:post "/somewhere"]))
Results into:
./example.clj
  :kondo/refer-all
    3:24 use alias or :refer
The refer list is however empty. Is this a bug, or should I add a lint-as here?

Twan10:03:47

Ran with:

clj-kondo --lint ./example.clj --config '{:lint-as {hiccup.form/form-to clj-kondo.lint-as/def-catch-all}}'
./example.clj:3:24: warning: use alias or :refer

borkdude10:03:50

@twan clj-kondo will only list the referred vars if it knows about the required namespace. so if you will lint hiccup.form as well, it will do this.

Twan11:03:49

You mean like

(ns example
  (:require
   [hiccup.core]
   [hiccup.def]
   [hiccup.form :refer :all]))

(defn something []
  (form-to [:post "/somewhere"]))
?

Twan11:03:05

That doesn't seem to make any difference

borkdude12:03:35

No. Lint the source of hiccup. How else is clj-kondo supposed to know what is inside that namespace?

borkdude13:03:20

You can do so by executing clj-kondo --lint $(lein classpath) in your project if you have a .clj-kondo directory in $PROJECT_ROOT

4
borkdude10:03:22

I don't see how this relates to :lint-as

borkdude10:03:35

The problem here is that clj-kondo recommends not to use :refer :all but wants you to use :refer [form-to].

Twan11:03:34

Yes, I understand that clj-kondo wants me to do that, but it suggestion is empty (whereas it usually is filled with everything referred to)