metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.44k stars 204 forks source link

Fix #836 clj-kondo linter generation when using pred :fn's #987

Closed juszczakn closed 5 months ago

juszczakn commented 6 months ago

Trying to fix #836 . When using a predicate fn schema inside of a function schema, it would output a the type as :fn, such that clj-kondo checked that the arg provided is a fn and not of type any.

Ex:

(defn times [x y z] (* x y z))
(m/=> times [:=> [:cat int? [:fn #(int? %)] int?] [:fn #(int? %)]])

(times 1 2 3)
;; clj-kondo warns that `2` should be a function, not an integer.
juszczakn commented 6 months ago

Ok, I updated the PR to follow the IT test standard.

I'm not sure why the workflow is failing for cljs? I don't really understand the error message and I don't have any cljs experience at all, so I'm kinda lost there.

ERROR in (check-test) (Error:NaN:NaN)
Uncaught exception, not in assertion.
expected: nil
  actual: #error {:message ":malli.generator/no-generator", :data {:type :malli.generator/no-generator, :message :malli.generator/no-generator, :data {:options {:malli.core/function-checker #object[malli$generator$function_checker], :malli.generator/original-generator-schema #object[malli.core.t_malli$core24556]}, :schema #object[malli.core.t_malli$core24462]}}}
ikitommi commented 5 months ago

instrumentation tests were testing all registered function schemas using generative testing. I added a namespace-filter that it only tests functions from that namespace. See https://github.com/metosin/malli/pull/987/commits/2caabf1f2aafb79a32808eb0f1fb99ea8810e1ff.

the schema [:=> [:cat int? [:fn #(int? %)] int?] [:fn #(int? %)] can be tested with generative testing as the :fn doesn't generate anything. In real life, if you need :fn that can generate values, you could mark it to use :int generator:

[:=> [:cat int? [:fn {:gen/schema :int} #(int? %)] int?] [:fn {:gen/schema :int} #(int? %)]

ikitommi commented 5 months ago

Thanks!!