Fork me on GitHub
#clj-kondo
<
2020-11-02
>
hugod16:11:14

In a hook, is it possible to set :clj-kondo/ignore on the rewritten forms? e.g. if we rewrite something as a let we don’t want clj-kondo to complain about a redundant let in the body.

borkdude16:11:56

@hugod In the newest clj-kondo, clj-kondo should already not complain about this anymore. Which version are you using?

borkdude16:11:51

The latest version is 2020.10.10

hugod16:11:12

Using the version you patched to early load the cache

borkdude16:11:21

@hugod The current behavior should be: if any of the two nested let nodes doesn't have location metadata, there is no warning.

hugod16:11:05

The replacement node (the let) that is being generated has the input node’s meta set on it - is that not the intended pattern?

borkdude16:11:39

if that's the outer node returned, then that's probably good. but you are generating another let inside of that?

borkdude16:11:10

if the user then uses your node inside their let, it will warn. in this case, it's maybe better to leave out the location metadata

borkdude16:11:36

you can put an ignore on that probably, but this will disable linting for all the inside nodes as well

hugod16:11:37

Almotst - the generated let contains the body of the macro expression, which happens to be a let

borkdude16:11:13

yeah, same problem

borkdude16:11:36

when generating a let, it's probably better to not attach location metadata, as to not trigger the redundant let linter

hugod16:11:51

ok, got it, thanks

hugod16:11:51

What does omitting the metadata do to reported line numbers if the let binding contains a lint error/warning?

borkdude16:11:00

the let itself probably doesn't have warnings, if it's generated syntactically correct. when you will have unused bindings, the location of the binding symbols is used instead

borkdude16:11:52

to avoid those warnings you could use underscored symbols

borkdude17:11:20

@hugod another approach is to use let* which also will never trigger a warning, but this is kind of undocumented behavior. I was hoping the location metadata rule was sufficient

borkdude17:11:52

if that turns out not to be the case, we could make this explicit using some bespoke metadata

borkdude17:11:39

or we could always add metadata on the generated nodes, so clj-kondo has a different way to know that the node was generated using the API

borkdude17:11:46

maybe that's more robust

hugod17:11:20

Not adding metadata should work for now, but it might be nice not to have to think about this as a hook writer.

borkdude17:11:42

@hugod The check to suppress a warning is this: https://github.com/borkdude/clj-kondo/blob/b8a9bac8748999b0ea96db70c2a3cb4d1d3c27fd/src/clj_kondo/impl/analyzer.clj#L574 We could make that (:clj-kondo.impl/generated (meta node))

borkdude17:11:05

and then automatically add that to all the generated nodes

borkdude17:11:00

ok, I'll change this to make that more robust

borkdude19:11:04

@hugod I now pushed this change, so you can re-add your location metadata and you should not get a warning with latest master

hugod21:11:41

Thank you, again!