clj-kondo

2025-03-15T10:03:34.752929Z

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?

2025-03-17T08:44:42.066969Z

I just recently asked this: https://clojurians.slack.com/archives/C03S1KBA2/p1741753071524969 😛

2025-03-17T12:49:33.923039Z

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.

👍 1
borkdude 2025-03-15T10:08:57.688119Z

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

2025-03-15T10:17:14.385419Z

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.

borkdude 2025-03-15T10:18:36.048689Z

> 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

borkdude 2025-03-15T10:19:07.127199Z

you could of course write a hook, but you could also just write the keyword

2025-03-15T10:32:07.936349Z

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!

borkdude 2025-03-15T10:33:19.586289Z

> 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

2025-03-15T10:34:09.960349Z

Oh ok. I can open an issue with the example I provided if you want.

borkdude 2025-03-15T10:34:56.892279Z

only if it's important to you :)

2025-03-15T10:35:55.437919Z

I'll get around it, I was wondering if someone already did something like that, it's not really idiomatic clojure.