Fork me on GitHub
#malli
<
2022-03-04
>
ingesol12:03:38

Hi! I’m trying to get malli 0.8.4 to generate clj-kondo config for my browser CLJS project, trying this code

(ns mynamespace
(:require-macros [malli.dev.cljs :as dev]))

(defn test-fn
  "return y when x is larger than 5"
  {:malli/schema [:=>
                  [:cat :int :keyword]
                  [:maybe :keyword]]}
  [x y]
  (when (< 5 x)
    y))

(dev/start! nil)

(test-fn 1 2)
Instrumenting seems to work and I’m getting the expected validation error in my browser console, but I’m seeing no clj-kondo config being generated for my function schema, only seeing this in .clj-kondo/metosin/malli-types:
{:linters {:unresolved-symbol {:exclude [(malli.core/=>)]}}}

dvingo16:03:29

it looks like cljs support broke during a refactor of how function schemas are stored (there is now a map for :clj and one for :cljs) so the kondo data is looking up :clj even in :cljs code: https://github.com/metosin/malli/blob/002d5cbc724e83f07f126d66b19df022859f1cbf/src/malli/clj_kondo.cljc#L179 https://github.com/metosin/malli/blob/master/src/malli/core.cljc#L2385 I should have some time over the next few days to send a pr to address this

ingesol17:03:51

Right, that’s what I suspected too, since the CLJS support was pretty fresh. Thank you so much for looking into it!

Martynas Maciulevičius16:03:25

Hey. Is there a way to generate a value from a predefined list of values? Or maybe it's possible to "remember" previously generated values so that they would be able to be reused to produce random connections (as in DB sense)?

ikitommi16:03:45

maybe:

(mg/sample [:any {:gen/elements [1 2 3]}])
; => (1 1 3 2 1 1 2 1 1 1)

mafcocinco16:03:47

Simple newbie question: For malli.generator/generate is there a way to force malli to generate all fields, including optional?

ikitommi16:03:15

at the moment, no. But would be 1-2 extra lines of code: • new option :mg/generate-optional-values • read it here https://github.com/metosin/malli/blob/master/src/malli/generator.cljc#L90 - if true always, if false never, default to nil (current) • add a test • document int README

👍 1