This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-01
Channels
- # announcements (3)
- # babashka (20)
- # beginners (77)
- # calva (27)
- # cider (5)
- # clara (3)
- # clj-kondo (9)
- # cljs-dev (4)
- # cljsrn (5)
- # clojure (26)
- # clojure-europe (32)
- # clojure-italy (5)
- # clojure-nl (3)
- # clojure-uk (5)
- # clojurescript (25)
- # clojureverse-ops (4)
- # core-async (49)
- # cursive (15)
- # data-science (1)
- # datahike (4)
- # datomic (3)
- # docker (1)
- # events (1)
- # helix (5)
- # holy-lambda (3)
- # introduce-yourself (1)
- # jobs (1)
- # kaocha (2)
- # lsp (15)
- # malli (42)
- # off-topic (18)
- # pathom (18)
- # pedestal (12)
- # polylith (7)
- # rdf (1)
- # re-frame (22)
- # reitit (2)
- # releases (1)
- # remote-jobs (1)
- # rewrite-clj (33)
- # shadow-cljs (85)
- # spacemacs (3)
- # vim (12)
- # xtdb (29)
hi! the doc says m/=>
can be placed both before or after a defn. when putting it before, clj-kondo complains about the symbol being unresolved. :unresolved-symbol {:exclude [plus]}
in clj-kondo's config.edn
silences the error. should that be the default behavior?
it seems to export the stuff that goes to .clj-kondo/configs/malli/config.edn
automatically
I don't think malli exports any macro config. Does it have macros that clj-kondo doesn't understand?
the only thing it seems to export for m/=>
is
{:linters
{:type-mismatch {:namespaces {brincando {plus {:arities {2 {:args [:int :int], :ret :int}}}}}}}}
but since the macro would still be out of order even if defined for clj-kondo, is there any other way to solve this?sorry! this is the working code
(m/=> plus [:=> [:cat [:int {:max 10}] :int] :int])
(defn plus [x y] (+ x y))
but I just noticed that if you "expand" that macro in clj-kondo to declare plus
, it solves the undeclared variable warning, right?I think you can just put the m/=>
expression after the defn
and then clj-kondo will understand that plus
is a var
yep, but you can also put m/=>
before the defn and it is supposed to work, and I'd like to have the option to put the function schema close to the top of the defn
In this case it's better to write a hook. Optimally malli itself would bundle this in the library and export it
alternatively you can use {:linters {:unresolved-symbol {:exclude [(malli.core/=>)]}}}
but that config could also be exported by malli so it would work for everyone. cc @ikitommi
so, definetely. so, whoever knows better what to put into malli repo so it would work, please do.
@UKW2FUL4D https://github.com/metosin/malli/pull/559. thing is, that if that is merged, clj-kondo will not warn on cases where you define the m/=>
, but not the actual function that it points to. Not good either.
@ikitommi That's a step in the right direction, but you can make it better using an exported macro hook
it would be better to export it as part of the malli library though, then people don't have to run malli first to get the better linting
a better solution / clj-kondo macro hook would be great, anyone? Just merged the initial fix, thanks @borkdude for the code to paste in 🙂
nice! what about a hook that interprets m/=>
as (fn [sym _schema] (clojure.core/declare %1))
? kondo doesn't seem to complain about
(def thing)
(declare thing)
so it works the other way around tooI would say:
(do (declare thing) schema)
so everything you use in the schema is still seen by clj-kondo.@ikitommi hmmm, apparently
doesn't seem to catch errors for instrumented functions doing m/=> before the defn:
(require '[malli.core :as m])
(require '[malli.dev :as dev])
(dev/start!)
(defn plus1 [x] (inc x))
(m/=> plus1 [:=> [:cat :int] [:int {:max 6}]])
(plus1 6)
;; 1. Unhandled clojure.lang.ExceptionInfo
;; :malli.core/invalid-output {:output [:int {:max 6}], :value 7,
;; :args [6], :schema [:=> [:cat :int] [:int {:max 6}]]}
(m/=> plus1' [:=> [:cat :int] [:int {:max 6}]])
(defn plus1' [x] (inc x))
(plus1' 6)
;; => 7
@UA2U3KW0L that’s not good. I guess (re-)calling (dev/start!)
after definitions would work.
so, that’s just dev-time annoyance, but then again, it’s supposed to be dev-time tooling. Ideas welcome
I would assume m/=>
with dev running, should put a var-watcher that takes care of that, but guess not :thinking_face:
it seems to put a watch on the function schema, so what seems to be happening is the watch fn is called, the function gets instrumented properly, but when you eval the defn again you lose the instrumentation
yep! as a quick test, I did
(defn start!
,,,
(let [watch (fn [_ _ old new]
(println "watched")
(future ;; <-
(Thread/sleep 500) ;; <-
(mi/instrument! ,,,))]
(add-watch @#'m/-function-schemas* ::watch watch))
(mi/instrument! ,,,)
,,,))
so, we should get an event when the var is redefined, e.g. via defn
. I guess that's doable?
add-watch supports this, apparently:
(def changes* (atom []))
(def a 1)
(add-watch #'a nil (fn [_ _ & old+new] (swap! changes* conj old+new)))
(def a 2)
(def a 3)
@changes* ;; => [(1 2) (2 3)]
just noticed I use clojurians through 2 different slack accounts
clojure.core/declare, maybe?
a better solution / clj-kondo macro hook would be great, anyone? Just merged the initial fix, thanks @borkdude for the code to paste in 🙂
@ikitommi hmmm, apparently
doesn't seem to catch errors for instrumented functions doing m/=> before the defn:
(require '[malli.core :as m])
(require '[malli.dev :as dev])
(dev/start!)
(defn plus1 [x] (inc x))
(m/=> plus1 [:=> [:cat :int] [:int {:max 6}]])
(plus1 6)
;; 1. Unhandled clojure.lang.ExceptionInfo
;; :malli.core/invalid-output {:output [:int {:max 6}], :value 7,
;; :args [6], :schema [:=> [:cat :int] [:int {:max 6}]]}
(m/=> plus1' [:=> [:cat :int] [:int {:max 6}]])
(defn plus1' [x] (inc x))
(plus1' 6)
;; => 7