malli 2025-03-14

re-posting here because Sketch stands on the shoulders of Malli 💪

👍 4

Hi, I have a question about malli's dev tools an clj-kondo integration. I tend not to use keywords for my map keys but vars containing keywords. My problem with this way of doing things is that clj-kondo will generate missing required key errors. A quick example would be:

(def foo ::foo)

(=> bar [:-> [:map [foo :string]] :any])
(defn bar [x])

(bar {foo :a-value}) ; missing required key
Is it possible to configure something such that clj-kondo understands that foo is ::foo and the required key is not missing?

Since you have clj-kondo, do you really need the (def foo ::foo) trick? I assume it's meant to prevent typos in keywords.

It prevents typos in keyword which are sometimes hard to debug. Naming is hard so I can change my mind and change the keyword in one place instead of going all over the code. I use clj-reload and it works well. It allows me to put docstrings on keywords which I really like. The downsides would be my little issue here and de-structuring maps isn't as clean.

➕ 2

we started doing that at work as well and have been happy with the tradeoffs.

Right now I work around this by disabling the writing of type checking files when calling !. I don't get lsp warnings anymore but I retain the instrumentation behavior which is good enough for now. Later I might look at generating a cache of {var-name :keyword} and a hook that replaces the var names with the keywords during clj-kondo analysis before it type checks an instrumented function.

Hi, perhaps that question may be best asked in #clj-kondo?

Yes I can try there also, since it is at the intersection of clj-kondo and malli I thought I should ask there first 🙂

👍 1

In a perfect world you'd be able to add (=> foo [:= ::foo]) and clj-kondo would use this assumption to check the final line. clj-kondo doesn't support enumeration types.