clj-kondo

https://github.com/clj-kondo/clj-kondo
2020-11-02T16:38:14.285900Z

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.

borkdude 2020-11-02T16:38:56.286300Z

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

borkdude 2020-11-02T16:39:51.286500Z

The latest version is 2020.10.10

2020-11-02T16:46:12.287Z

Using the version you patched to early load the cache

borkdude 2020-11-02T16:49:21.287900Z

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

2020-11-02T16:52:05.289Z

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

borkdude 2020-11-02T16:52:39.289500Z

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

borkdude 2020-11-02T16:52:44.289700Z

oh I see

borkdude 2020-11-02T16:53:10.290200Z

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

borkdude 2020-11-02T16:54:36.291800Z

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

2020-11-02T16:54:37.291900Z

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

borkdude 2020-11-02T16:55:13.292200Z

yeah, same problem

borkdude 2020-11-02T16:55:36.292600Z

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

2020-11-02T16:55:51.292800Z

ok, got it, thanks

2020-11-02T16:57:51.294Z

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

borkdude 2020-11-02T16:59:00.294900Z

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

borkdude 2020-11-02T16:59:52.295400Z

to avoid those warnings you could use underscored symbols

borkdude 2020-11-02T17:00:20.296Z

@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

borkdude 2020-11-02T17:00:52.296600Z

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

borkdude 2020-11-02T17:01:39.297400Z

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

borkdude 2020-11-02T17:03:46.297600Z

maybe that's more robust

2020-11-02T17:07:20.299700Z

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

borkdude 2020-11-02T17:07:42.300100Z

@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))

borkdude 2020-11-02T17:08:05.300600Z

and then automatically add that to all the generated nodes

borkdude 2020-11-02T17:09:00.301100Z

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

borkdude 2020-11-02T17:11:03.301300Z

https://github.com/borkdude/clj-kondo/issues/1059

👍 1
borkdude 2020-11-02T19:38:04.302Z

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

2020-11-02T21:46:41.302100Z

Thank you, again!