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?I just recently asked this: https://clojurians.slack.com/archives/C03S1KBA2/p1741753071524969 😛
Yeah personally I like it, I can put docstrings on keywords that way which is really good. I can change the keyword quickly since I can change 1 var and call clj-reload. Renaming vars is easier than keywords with editor/lsp support. An undefined var doesn't eval, and is caught by kondo anyways, so it helps with typos. Downsides I can see right now would be my little malli issue here which isn't bad and destructuring maps is a bit more verbose.
I think it would be possible to not let clj-kondo give a warning about this because foo is a var and thus could contain anything. Feel free to file an issue
I am not sure this is an issue with Clj-kondo. It would need to eval the var somehow to get at the keyword. It defeats the purpose of static analysis... I was wondering, I can generate a config that provides a map of var-name -> keyword. I am wondering if I could make a hook using that map that switches the var for the keyword just before linting the types.
> It defeats the purpose of static analysis... yes, you would effectively disable clj-kondo's static analysis. that it's now reported as a missing key I consider a bug
you could of course write a hook, but you could also just write the keyword
Ok there may be something I don't understand. I use the functionality which generates a type checking file with something to the effect of:
{bar {:arities {1 {:args [{:op :keys,
:req {::foo :string}}],
:ret :any}}}}
I don't think this is bug for the linter to report that it doesn't see the required keyword. It can't. I like using vars holding keywords instead of the keywords directly. It allows for putting docstrings on them and it prevents me from mistyping keyword. Misspelling a var doesn't compile... I'll try to do something with hooks. Thanks!> I don't think this is bug for the linter to report that it doesn't see the required keyword. The point is that the variable might hold the required key, so the linter should err on the side of caution
Oh ok. I can open an issue with the example I provided if you want.
only if it's important to you :)
I'll get around it, I was wondering if someone already did something like that, it's not really idiomatic clojure.