Fork me on GitHub
#clj-kondo
<
2022-09-18
>
borkdude12:09:12

ok, here's the new :unused-value linter. Please try it out locally if you can. https://github.com/clj-kondo/clj-kondo/blob/master/doc/linters.md#unused-value

🎉 3
Ben Sless16:09:06

should kondo highlight tag metadata as unresolved symbols? i.e. (a ^foo b), with a being a macro which abuses metadata 🙂

borkdude16:09:30

it will do that if it doesn't know what foo is - doesn't it?

Ben Sless17:09:37

It highlights foo currently as unrecognized symbol. • is there a way to ignore it for one specific macro if it appears as metadata? • should unrecognized symbols as tags be highlighted?

Ben Sless17:09:05

If so, why not highlight unrecognized-tag for ^{:tag "foo"}?

borkdude17:09:56

is there a way: not currently they are warned about as they are usually (99%+ of the time) referring to Java classes. except in macros where people (ab)use them differently ;)

borkdude17:09:17

if the names in those tags are a limited set, you could just suppress them in the unresolved symbol config

Ben Sless17:09:54

they aren't limited, I'm trying to make life slightly more convenient for myself with spec's cat and alt

Ben Sless17:09:25

(defmacro |
  [& ks]
  `(s/alt ~@(interleave (map (comp keyword name) ks) ks)))

borkdude17:09:36

and how does the usage look like?

Ben Sless17:09:50

for cat I want the default name to be either blank or taken as the name of a keyword reference, with the option to provide it by metadata:

(% #{:find} ^find (| ::find-rel ::find-coll ::find-tuple ::find-scalar))

Ben Sless17:09:12

it expands to

(s/cat :_ #{:find} :find (| ::find-rel ::find-coll ::find-tuple ::find-scalar))

borkdude17:09:39

why not use ^:find ?

Ben Sless17:09:44

and (| ::a ::b) expands to (alt :a ::a :b ::b)

Ben Sless17:09:00

because that's {:find true} in the metadata

Ben Sless17:09:18

so I need to play some other tricks, like using a fully qualified symbol and filtering on the namespace

Ben Sless17:09:41

which is what I ended up doing

Ben Sless17:09:11

but the code is ugly and ad-hoc

borkdude17:09:22

or maybe more explicit: ^`{:spec :find}`

borkdude17:09:55

in my experience with these kind of macros: I always regret these nifty tricks 6 months later

Ben Sless17:09:57

I'm trying to square this circle to end up with less typing, not more

Ben Sless17:09:24

for alt it's easy, for cat if I have to do lots of backflips I'd rather not

Ben Sless17:09:02

Trying to hit on a syntax which looks a bit more like bnf

borkdude17:09:45

You could try to write a kondo hook which removes the tags so kondo won't see then or just ignore all unresolved symbols in your macro with a config

sheluchin20:09:42

Would it be possible/helpful to have a linter to warn against returning a value where it would always be discarded? Like returning a literal value at the end of a doseq and other similar situations.

(doseq [x (get-all-x)]
  {:result (foo x)})

borkdude20:09:12

@alex.sheluchin There is a new linter on master called :unused-value which should warn if you use a pure function in doseq as the return value. But it doesn't work yet for a map literal. Perhaps you can file an issue. I can look into that, or if you want, you can do it yourself

sheluchin20:09:59

Yes, that new linter is what gave me this idea. I haven't turned it on just yet and didn't realize it would warn about situations like that. Thanks, @U04V15CAJ. I'll make an issue about the enhancement for literal returns.

sheluchin11:09:50

Looks like the var-info.edn list from Eastwood could also be used to implement https://github.com/clj-kondo/clj-kondo/issues/1757

sheluchin11:09:42

Nice, maybe I'll try to implement that if no one else gets around to it by then.