clj-kondo

https://github.com/clj-kondo/clj-kondo
2021-06-01T10:58:07.112500Z

I see a warning thrown for completely normal spec

echo '(ns user (:require [foo.common :as common] [clojure.spec.alpha :as s])) (s/def ::x (s/keys :req-un [::common/x]))' | clj-kondo --lint -
<stdin>:1:21: warning: namespace foo.common is required but never used
linting took 21ms, errors: 0, warnings: 1
I think it happens because s/def expands to something like that:
... :req-specs '[:foo.common/x] ...

borkdude 2021-06-01T10:58:26.112800Z

this is a bug introduced by a new feature which has already been fixed on master

borkdude 2021-06-01T10:58:41.113200Z

I can make a new release since this is annoying

2021-06-01T10:58:54.113700Z

not really

borkdude 2021-06-01T10:58:58.113900Z

but maybe I'll wait a day in case there are any other regressions

2021-06-01T10:59:14.114200Z

I can wait until next release ) thanks!

borkdude 2021-06-01T10:59:30.114600Z

if there will be a third person reporting this, I'll make a release ;)

borkdude 2021-06-01T10:59:42.115Z

you were the second

2021-06-01T10:59:44.115100Z

)) reasonable enough

wilkerlucio 2021-06-01T12:58:41.115400Z

@borkdude third person here

😅 1
borkdude 2021-06-01T12:59:36.115600Z

releasing

🙌 1
borkdude 2021-06-01T13:11:09.116Z

done

wilkerlucio 2021-06-01T13:16:41.116400Z

confirmed the lint runs good in the latest version 👍

🎉 1
2021-06-01T16:08:25.118400Z

Hey, I'm playing around with hooks in another project and it seems like they're just not getting run at all. As far as I can tell the only difference is that I've got them directly in the .clj-kondo directory rather than inside an exports section. I'm using the binary release on the AUR from today. Is there anything I have to do to make sure it actually tries to run it?

borkdude 2021-06-01T16:10:09.119200Z

@suskeyhose It depends on your config. What do you have in {:hooks {:analyze-call ...}}

2021-06-01T16:14:46.119500Z

{:hooks {:analyze-call {noah.transformer/deftransformer hooks.noah/deftransformer}}}

2021-06-01T16:15:06.119900Z

then in that directory there's a hooks directory with the noah.clj file in it which has a deftransformer function

2021-06-01T16:15:49.120700Z

(this is working on adding hooks to the noah library, which is a clojure wrapper for kafka streams)

borkdude 2021-06-01T16:15:54.120900Z

do you have a file in a directory noah/transformer.clj in the local .clj-kondo dir?

borkdude 2021-06-01T16:16:20.121400Z

sorry, my bad, hooks/noah.clj

2021-06-01T16:16:26.121600Z

Yeah

2021-06-01T16:16:36.121900Z

it's where the hook function is

borkdude 2021-06-01T16:16:53.122300Z

can you make some deliberate typos in this file to see if it crashes or something

borkdude 2021-06-01T16:17:01.122500Z

or add some printlns

borkdude 2021-06-01T16:17:10.122900Z

and call it from the command line

2021-06-01T16:17:10.123Z

I have a println at the top of it before I do any code

borkdude 2021-06-01T16:17:24.123300Z

stick the println inside your function

2021-06-01T16:17:34.123500Z

Yup, that's where it is

2021-06-01T16:17:45.123800Z

(defn deftransformer
  [{:keys [node]}]
  (println "Being run!")
  (let [[name & more] (rest (:children node))
        [_docstring store-names & more]
        (if (api/string-node? (first more))
          more
...

borkdude 2021-06-01T16:18:42.124700Z

do you have a ns form at the top?

2021-06-01T16:18:47.125Z

Yup

2021-06-01T16:19:16.125900Z

I was observing similar behavior when I was working on farolero, except I could fix it by swapping the key in the analyze-call map for one that used a . rather than a fully-qualified symbol, like farolero.core.restart-case instead of farolero.core/restart-case, but this doesn't fix the issue here.

borkdude 2021-06-01T16:19:41.126600Z

well, you're welcome to make a small repro

2021-06-01T16:19:45.126700Z

The difference between this one and that one was that in that one I was doing --copy-config on every call to get it out of the resources directory

2021-06-01T16:19:51.126900Z

Alright, I'll try for it

2021-06-01T16:20:52.127400Z

Honestly since everything that I'm actually working on is OSS I can just extract it from the containing repo and it should work the same

borkdude 2021-06-01T16:22:18.127600Z

sure

2021-06-01T16:33:40.127900Z

Dang it, I move it over to a small reproduction case and it runs.

2021-06-01T16:34:32.128400Z

At least this gives me a chance to debug the hook and make it work right, then I can try and figure out why it wasn't being run in the bigger project.

borkdude 2021-06-01T16:34:44.128600Z

:thumbsup:

2021-06-01T16:46:24.129200Z

What am I supposed to use for a map node in the resulting code?

borkdude 2021-06-01T16:47:10.129600Z

often just (token-node nil) works

2021-06-01T16:47:33.130Z

Hmm. Alright.

borkdude 2021-06-01T16:48:43.131100Z

So far I haven't seen a single case where hooks should actually create a map. In the future this might be possible, but the API doesn't allow it right now because the API in rewrite-clj around this wasn't very stable yet

2021-06-01T16:50:50.131300Z

Fair enough.

2021-06-01T17:23:11.132Z

Is there any way that I can suppress unused-symbols for particular symbols in sections of code produced by a hook?

2021-06-01T17:36:09.134Z

Like there's some code that's got an unhygenic macro, so there's some let blocks that have symbols that may or may not be used in the body, and I don't want it to emit warnings either way.

2021-06-01T17:45:25.138100Z

Oh btw, one place you'll need a map node is if someone wants to emit a with-bindings call. Sure, technically you could also emit a bindings call, but it'll technically be incorrect because if you emit bindings then ordering matters and previously-seen bindings will be assumed to be used in later ones, making certain classes of lints that pay attention to the values attached to bindings impossible.

2021-06-01T17:48:11.138800Z

(I figured out why it didn't run in the bigger project, I accidentally called it config.clj rather than config.edn)

2021-06-01T18:01:47.139600Z

Okay, looks like I can emit a comment node in order to ignore the unused binding warning on the unhygenic macro

2021-06-01T18:07:50.140Z

Only issue is that I can't import the namespace which exposes comment nodes

2021-06-01T18:09:58.140300Z

@borkdude do you have any suggestions for this?

borkdude 2021-06-01T19:56:56.140900Z

@suskeyhose > Is there any way that I can suppress unused-symbols for particular symbols in sections of code produced by a hook? Yes, you can start the symbol names with underscore, (gensym "_")

borkdude 2021-06-01T19:58:10.141500Z

or you can just emit code that uses them

2021-06-01T20:00:40.142Z

That doesn't exactly work for making hooks for unhygenic macros though.

borkdude 2021-06-01T20:02:36.142700Z

oh you said unhygienic :) well, I guess you can generate:

(let [x ..] x ...)
?

2021-06-01T20:03:19.143Z

Oh.

2021-06-01T20:03:23.143200Z

Why didn't I think of that

2021-06-01T20:03:44.143500Z

Thanks!

borkdude 2021-06-01T20:11:01.144200Z

why do you want to generate something with with-bindings btw? afaik clj-kondo doesn't really have any special linting around this

borkdude 2021-06-01T20:11:45.144800Z

the generated code doesn't really have to reflect the original macro, as long as the input nodes are used in a way that makes sense for linting

2021-06-01T20:28:20.146200Z

I actually don't have anything in particular about with-bindings that I want to generate, I was just pointing out that certain classes of linters (which you may or may not ever want to implement) would be impossible to represent atm because we lack a concept of unordered bindings, which with-bindings has.

borkdude 2021-06-01T20:29:47.146900Z

True. Eventually we will get it, but afaik there is no reason to specifically emit this for any reason

borkdude 2021-06-01T20:30:17.147300Z

unless there is some linter checking that "with-bindings must be used because this and that"

2021-06-01T20:31:49.148100Z

Fair enough.