Fork me on GitHub
#clj-kondo
<
2023-05-18
>
pfeodrippe02:05:13

Hi, is there a way to add hooks for vars with some form metadata? E.g. let's say I want to analyze a string so it cannot contain whitespaces

(def ^:my-meta aaa
  "this-is-good")     ;; Valid string

(def ^:my-meta bbb
  "this-is bad")      ;; Invalid string, clj-kondo warns
, then we could do something like
{:hooks {:analyze-meta-var {:my-meta hooks.foo/weird-meta}}}
. Ofc, this could be more general than vars if wanted (anywhere where a form metadata is found?).

pfeodrippe02:05:30

I know that I could create some bogus function as a marker wrap the string with it, but wanted to rely on metadata instead, if possible

borkdude07:05:44

This use case hasn't come up before as far as I can remember. Perhaps you can use https://github.com/borkdude/grasp for now to write a manual check

pfeodrippe14:05:09

Michiel, so a “query” written in grasp could be easily ported to clj-kondo later? Or are you saying that there is a way to use grasp with clj-kondo?

borkdude14:05:17

not currently, but just as an extra check outside of clj-kondo

pfeodrippe14:05:29

Got it, thanks!

pfeodrippe01:05:37

Opened an issue at https://github.com/clj-kondo/clj-kondo/issues/2088 for this (with a wip branch and a video, no PR yet, will open a PR only if you want)

borkdude11:05:03

nice 6
2
🎉 8
👍 2
Thierry17:05:42

With :uninitialized-var being set to default :level :warning has made my github action using delaguardo clojure-lint-action fail on 31 counts of uninitialized-var . Is there any way around this?

Thierry17:05:28

found a workaround for now

Thierry17:05:37

:uninitialized-var {:level :off}

borkdude17:05:38

yes, either fix the uninitialized vars or disable the linter. I recommend fixing them though since uninitialized vars default to a truthy value while you might think they default to nil (in JVM Clojure) and this can lead to unexpected bugs

Thierry17:05:29

All uninitialized-vars in this project are :^dynamic and only used with binding. They are on purpose not initialized so they cannot be used with any pre entered value

borkdude17:05:52

I recommend initializing them to nil explicitly

Thierry17:05:05

good point, will do that and test

Thierry17:05:11

need to release tonight :melting_face:

borkdude17:05:14

no worries

1
Thierry18:05:25

was a quick fix thankfully, thanks!

👍 1
Thiago Carvalho Pinto14:05:10

About the :type-mismatch linter, is there a way to specify an argument as a map with strict keys? (i.e. a map containing only the required and/or the optional keys, but not containing extra keys)

borkdude14:05:51

currently not