This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-11
Channels
- # announcements (21)
- # aws (2)
- # babashka (20)
- # beginners (47)
- # bristol-clojurians (2)
- # calva (63)
- # cider (24)
- # clj-kondo (22)
- # cljs-dev (3)
- # cljsrn (6)
- # clojars (3)
- # clojure (147)
- # clojure-europe (21)
- # clojure-france (2)
- # clojure-italy (3)
- # clojure-losangeles (1)
- # clojure-nl (3)
- # clojure-spec (2)
- # clojure-uk (70)
- # clojurescript (37)
- # core-logic (6)
- # cursive (4)
- # data-science (2)
- # datomic (99)
- # events (1)
- # figwheel-main (20)
- # fulcro (26)
- # graalvm (6)
- # graphql (5)
- # kaocha (8)
- # leiningen (20)
- # meander (22)
- # nrepl (4)
- # off-topic (27)
- # pathom (5)
- # pedestal (3)
- # re-frame (20)
- # reagent (4)
- # shadow-cljs (43)
- # spacemacs (11)
- # tools-deps (55)
- # tree-sitter (6)
- # vim (8)
- # xtdb (18)
- # yada (14)
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.
The argvector allows you to hint multi-arities which return different types. And it allows you to hint primitives.
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.
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.
Also, if you put it on both the var and the argvector, the argvector takes precedence.
(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.Where as this would not warn:
(defn foo
^String []
"bar")
or
(defn foo
(^String []
"bar"))
Well, I remember cases when the hint before var did not work. But unfortunately I cannot reproduce it in simple test case.
Also contract for defn
from “The Essential Reference” does not mention ret-typehint before name at all.
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?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
@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.
You mean like
(ns example
(:require
[hiccup.core]
[hiccup.def]
[hiccup.form :refer :all]))
(defn something []
(form-to [:post "/somewhere"]))
?No. Lint the source of hiccup. How else is clj-kondo supposed to know what is inside that namespace?
You can do so by executing clj-kondo --lint $(lein classpath)
in your project if you have a .clj-kondo
directory in $PROJECT_ROOT