Fork me on GitHub
#clj-kondo
<
2022-02-25
>
borkdude10:02:28

@stefan.van.den.oord is working on a namespace linter that warns when the name of the ns does not match the filename. But for scripts (clojure and babashka) it is fine to use normal dashes in the name. So foo-bar.clj and (ns foo-bar) is fine for scripts that you invoke directly with bb foo-bar.clj, but not for files on the classpath. Any suggestions on how to deal with this? Maybe a heuristic that when there is no "src" or "test" in the parent segments, the file isn't on the classpath and can be assumed a script?

1
🎉 1
Stefan10:02:23

Would it make sense to have a different set of default linter configs for that type of use? In other words, invoking clj-kondo slightly differently so that it knows it is running in “scripting mode” and then have different defaults?

borkdude10:02:16

No, if you are using clj-kondo in your editor you don't invoke it yourself and that's the primary mode of usage as far as I'm concerned

borkdude10:02:53

People could just use #_:clj-kondo/ignore in this case or just adopt the convention to use underscores in their script file names perhaps.

borkdude10:02:36

Might be worth making a test case to see if the ignore annotation works correctly with this linter

👍 1
borkdude10:02:43

Checking for the presence of a shebang could also work

Stefan10:02:26

shebang is not always present in scripting mode I think.

cat some-text-file-containing-clojure.clj | bb

borkdude11:02:15

In your example using a namespace form is pretty unusual.

Stefan11:02:42

Example updated 🙂

borkdude11:02:42

You're right that a shebang isn't always present, but that would be a way for people to get rid of the warning

Stefan11:02:03

That feels a bit like magic to me…

borkdude11:02:17

But maybe we could let it be for now and just let people use the ignore annotation

borkdude11:02:26

So please add a test for that one

Stefan11:02:19

Yes good idea.

Noah Bogart14:02:39

i'm writing a hook. what's the best way to debug it?

Alex Miller (Clojure team)14:02:16

I read that as "writing a book" and laughed

😂 6
2
imre14:02:43

I was asking the same a while back, check out this thread https://clojurians.slack.com/archives/CHY97NXE2/p1644324979611669

👍 1
🙏 2
Noah Bogart15:02:01

a combination of --debug and with-in-str nailed it. thanks so much!

1
Noah Bogart17:02:16

to follow up, I have a macro that creates a private function and then binds the function to public atom, which allows for repl-based testing while keeping the in-code usage through the atom. is it possible to output the {:node node} in my :analyze-call hook that ignores the unused-private-var warning?

Noah Bogart17:02:35

oh wait, this is a clojure-lsp issue, i'll work from there. never mind, this is in fact a clj-kondo issue. any ideas on how to fix this?

borkdude18:02:27

@nbtheduke Just use the unused private var once in your hook, that will take care of the warning, e.g. (let [_ private-var])

1
Noah Bogart18:02:12

mind if i PM you about this? i don't want to share the code publicly but i'm unsure how to do that with the code i have written