Fork me on GitHub
#clj-kondo
<
2022-05-28
>
john05:05:17

Is it possible for kondo to auto-import configs from libraries that have kondo configs?

seancorfield05:05:23

I thought it did that automatically...?

john05:05:17

I thought it was going to, a few months ago. I might just be exporting wrong.

john05:05:36

I've added the "resources" folder to my deps.edn :path vector, per the docs. Here's my project https://github.com/johnmn3/dispacio

john05:05:44

nevermind, I just had to restart vscode

1
john06:05:22

I guess the last issue I have is that my defmethod lint-as thing is not taking effect on subsequent instances of the defined methods:

john06:05:37

Is the only to handle that with hooks?

seancorfield06:05:18

:lint-as should work I think... That's how I do it in Expectations.

john06:05:40

Here's my config.edn: https://github.com/johnmn3/dispacio/blob/master/resources/clj-kondo.exports/net.clojars.john/dispacio/config.edn I'm a little scared to bite off implementing a hook. I tried making one that wrapped the body in a do and added a (declare the-thing-name) at the top of the do form, but I couldn't get it to work

seancorfield06:05:29

Hmm, according to the docs, your path is correct. No idea, sorry.

john06:05:35

hmm, maybe you can't have a :lint-as and a :linters config for the same symbol

john06:05:37

hmm, not sure. Thanks for checking @U04V70XH6

borkdude06:05:19

I think using a hook is a better option here than linting as + repressing unresolved symbols

borkdude06:05:50

I'll try locally when I'm at the keyboard

🙏 1
borkdude08:05:31

@U050PJ2EU Made a pull request which fixes the above issues. You can execute clj-kondo --lint .clj-kondo/test.clj to see that it works, with the newest clj-kondo.

👀 1
john14:05:37

@U04V15CAJ There might be an issue with the paths

john14:05:08

dispacio/dispacio?

john14:05:21

going to try to remove one level of dispacio

borkdude14:05:36

No, this is correct

borkdude14:05:46

You just have to use the newest clj-kondo, released yesterday

borkdude14:05:30

In the newest clj-kondo, the .clj_kondo extension is supported

borkdude14:05:33

for hook code

borkdude14:05:42

to not confuse it with application code

borkdude14:05:50

and I used that

john14:05:05

Okay. So that'll flow in from clojure-lsp at some point?

borkdude14:05:08

Perhaps @UKFSJSM38 can tell you how to use the master version of clojure-lsp

borkdude14:05:41

Yes. You can try with the clj-kondo vscode extension now if you want btw and disable linting in clojure-lsp

borkdude14:05:54

temporarily

ericdallo14:05:45

I just pushed to master the bump of clj-kondo on clojure-lsp, if you want you can use a nightly build on #clojure-lsp-builds

lread16:05:01

Am giving the clojure-lsp nightly a whirl on macOS doom emacs.

lread16:05:54

@UKFSJSM38 I guess I should be viewing the new .clj_kondo files in clojure-mode?

ericdallo17:05:16

Probably missing changing that on clojure-mode, right @U04V15CAJ?

ericdallo17:05:55

We should open a PR there and on other projects to consider that as a clojure file like clojure-lsp itself 😂

lread17:05:09

When I do switch to clojure-mode for a .clj_kondo file, I do get an odd finding for that file:

lread17:05:50

This could entirely me just being emacs-naive and not doing some more setup/config?

ericdallo17:05:20

IIRC that can't parse comes from kondo, probably we need to consider .clj_kondo files as clj ones as well there

lread17:05:31

But the .clj-kondo hook files are being picked up and used for linting. And the enhanced macroexpand hook behaviour seems to be pinpointing errors at their location.

ericdallo17:05:36

Do you repro that if you use latest kondo and lint manually that file via CLI?

lread17:05:13

Good question… Here’s the hook source:

(ns etaoin.impl.util)

(defmacro defmethods
  "Declares multimethods in batch. For each dispatch value from
  dispatch-vals, creates a new method."
  [multifn dispatch-vals & fn-tail]
  `(doseq [dispatch-val# ~dispatch-vals]
     (defmethod ~multifn dispatch-val# ~@fn-tail)))

;; essence only for linting
(defmacro with-tmp-file [prefix suffix bind & body]
  `(let [~bind "somepath"]
     ~@body))
And here’s me linting from the cmdline:
❯ clj-kondo --version
clj-kondo v2022.05.29
❯ clj-kondo --lint .clj-kondo/hooks/etaoin/impl/util.clj_kondo 
.clj-kondo/hooks/etaoin/impl/util.clj_kondo:11:26: warning: unused binding prefix
.clj-kondo/hooks/etaoin/impl/util.clj_kondo:11:33: warning: unused binding suffix
linting took 12ms, errors: 0, warnings: 2

lread17:05:57

So, the answer is: no.

borkdude17:05:48

Perhaps clojure-lsp is passing a wrong --lang clj_kondo or so

ericdallo17:05:21

Hum, probably, I will take a look soon

lread17:05:44

Yup, I think borkdude is onto something there:

❯ clj-kondo --lint .clj-kondo/hooks/etaoin/impl/util.clj_kondo --lang clj_kondo
.clj-kondo/hooks/etaoin/impl/util.clj_kondo:0:0: error: Can't parse .clj-kondo/hooks/etaoin/impl/util.clj_kondo, No matching clause: :clj_kondo
linting took 6ms, errors: 1, warnings: 0

lread17:05:17

Maybe lsp is passing in --lang :unknown ?

borkdude17:05:34

Not pass any --lang ... probably, unless you know what you're doing ;)

borkdude18:05:13

lang defaults to clj if you don't pass anything and the extension is unknown

lread18:05:51

And my example above shows that I will leave in lint warnings without clj-kondo/lsp help. I am totally dependent.

ericdallo18:05:01

I'll change to not pass lang

lread18:05:43

@U04V15CAJ does it make sense to lint hooks code? I guess so, but would like a borkpinion.

lread18:05:15

Maybe call hooks more so than macroexpand hooks?

borkdude18:05:05

I think it makes sense to lint it while developing those

👍 1
borkdude18:05:55

@UKFSJSM38 It depends how you are calling clj-kondo. If you pass just stdin text without a filename, then clj-kondo cannot guess the language, so you can give a hint --lang cljs or so

borkdude18:05:21

But if you just pass the filename with the extension, then clj-kondo will derive the language from that

👍 1
ericdallo20:05:12

Just pushed the fix on clojure-lsp

lread23:05:29

Just gave it a go @UKFSJSM38, my .clj-kondo files are no longer producing lint warnings!

🎉 2