Fork me on GitHub

oh, it's the function values, need to short-circuit on them. Should be easy to fix.


though experiment: • persist function schemas into edn/file (var->schema) • write a clj-kondo plugin/hook that looks from afile if a Var has a malli schema defined. If it has runs that validation (inputs & outputs) to it and reports. Static analysis with full malli :thinking_face: 🚀 parrot

Ben Sless10:08:00

separating type and code for functions seems like a footgun waiting to go off

☝️ 2
Ben Sless10:08:55

someone will change one and not the other


I think you could have some kind of development runtime hook that writes clj-kondo type config as you go. But if I understand correctly malli already has this


one issue is that statically visible values are not the runtime values, so validating on those has different behavior


yes,! re-writes the the clj-kondo config on any change to the function registry


could emit the new var->malli-schema file too at the same time.


(and! removes the file(s))


yes, that works with simple/demo cases. would need typedclojure to follow the types for real? and actual runtime to track the values for real?


I guess one could just add new keys to the clj-kondo config too? e.g. :malli/schema [:=> [:cat :int] :int]]


would be just one config file then, always up-to-date.


you mean type aliases?


						{1 {:args [:int]
				            :ret :int
				            :malli/schema [:=> [:cat int?] pos-int?]}}}}}}}}


… for the plugin to read from.


but when your plugin is called with the input types, it would have to do something similar to the clj-kondo "type" system right


so why not convert the schema to the clj-kondo type system immediately


it is converted already to clj-kondo type system. In top of that, using second round of malli-vqlidation, one could catch more, like integer min&max sizes, collection limits, closed maps, multis, sequences etc. The code would require access to: 1. function arguments 2. the :malli/schema value (from linter config).


and you would need to invoke malli itself as well right?


not sure if this is anyhow useful, but might be doable? At least emitting the malli-schema to the linter config would be a +1loc in malli.


in that case malli would have to be built into the clj-kondo or clojure-lsp binary, unless you run it on the JVM


what you could do, as it is now, is programmatically generate hooks for each var that has a malli spec


there you can have access to the arguments and do whatever you like, throw exceptions. The hooks already have access to the linter config

👍 4

and then you could write some validations like malli but in user space, just as a proof of concept


or you can fork clj-kondo and add malli to the type system and explore until you reach some interesting conclusions


I'm also open to clj-kondo type system improvements, there are a few low hanging fruits perhaps

👍 2

... also, if the config-file could be used as a.simple database, the tool could run Malli's check once for each var (gen-test) and mark :malli/check with the result (nil or error) - "function does not conform to it's schema, with arguments [0 -1], the result is -1, which is not a positive integer"

Noah Bogart15:08:50

is it possible to enable generative testing (`{::m/function-checker mg/function-checker}`) for all function schemas during test runs without adding a (when (= :test (:env app)) ...) to every schema manually?


there is an issue to allow setting default options. Before that, you could redefine the var where it's read / defined?


dirty, but works

Noah Bogart16:08:37

yeah, maybe i’ll try that


And please write an issue

👍 2

Question, say I want to try Malli but I don't have the fire power to rewrite all the specs...What would be the best "migration strategy" there? We instrument every function in dev mode and tests and we use specs for our domain model and http param validation at the moment. What I am worried about the former and the following - how can I instrument a function that has been partially covered with spec and partially with Malli?


create a spec->malli converter, PR that and enjoy the ride? :face_with_cowboy_hat:


Not sure if the intstrumentatons stack, could just work?