Fork me on GitHub
#clj-kondo
<
2020-10-27
>
andrea.crotti16:10:10

if I have something declared with a macro like (defmymacro x 1) and then it's below in the same namespace, I can ignore easily the defmymacrolines, but how do I ignore the usages of these vars?

borkdude16:10:11

@andrea.crotti I think you can use {:lint-as {your-awesome-lib.defmymacro clojure.core/def} for this

andrea.crotti16:10:31

ah nice didn't think about that

andrea.crotti16:10:33

and also should Emacs with fly-clj-kondo read the .clj-kondo/config.edn file right?

andrea.crotti16:10:56

it looks sometimes that running from the cli and what I see in Emacs are out of sync

borkdude18:10:12

should not be the case, the same binary is invoked. you might want to restart emacs and see if that solved anything

hugod17:10:30

Is it possible to write tests for hooks? I don’t see how to define a project that makes clj-kondo.hooks-api available.

borkdude18:10:44

@hugod I usually test this by just writing examples and see if they work: https://github.com/clj-kondo/config/blob/master/resources/claypoole/src/example.clj you could also just run clj-kondo (binary or JVM), capture the output (as strings or EDN) and then write tests on that (using the JVM or babashka)

hugod18:10:30

I was hoping to run it in a project so I could also debug the hooks. clj-kondo seems to be silently ignoring my config and I’ve no idea why. I’m not sure if the config is somehow wrong, or there is an error in my hook, or…

borkdude18:10:59

clj-kondo prints a warning if it can't find the hook

borkdude18:10:10

you can stick a prn/println in the hook to force some output

borkdude18:10:50

if the hook doesn't return a map with :node then it continues to lint without a transformed node, but with the original node

hugod18:10:18

I don’t get output from either of those

borkdude18:10:23

this is by design, since hooks don't always transform nodes

borkdude18:10:34

then maybe your config is off.

borkdude18:10:02

post a small repro repo and I'll take a look

borkdude18:10:47

you can also post your config.edn, so I can see if there's something wrong

borkdude18:10:10

could also be that you're using an old version of clj-kondo. many things can be wrong without clj-kondo being able to print an error

hugod18:10:32

thanks for the offer - not sure I can post it as is. Using v2020.10.10. The config is valid edn at least 😉.

borkdude18:10:09

maybe post the hook config only if you're able to

borkdude18:10:41

there could very well be a typo somewhere

hugod20:10:36

looks like clj-kondo sometimes manages to resolve the symbols that are being hooked and sometimes it doesn’t. I’m trying to find a pattern to this. It seems to work when linting the whole class path. The symbols are used unqualified in code through a :use, which I guess is the root of the problem. Can’t change the code base in that respect though.

borkdude20:10:57

There is an issue about this: https://github.com/borkdude/clj-kondo/issues/1010 clj-kondo tries to do its best to resolve those vars, but this is at the very end of the linting, where the cache is consulted.

borkdude20:10:28

as clj-kondo doesn't recommend refer :all or :use I have marked this issue as low priority

borkdude20:10:45

but if there's enough relevant problems associated, I might give it more priority

hugod20:10:38

In our case we have a language embedded in clojure, so we have great chunks of code that import the language with :use.

borkdude20:10:06

@hugod Clj-kondo should work fine if you have only one :use at a time

borkdude20:10:45

Provided you have linted that other namespace as well. Else clj-kondo has no way of knowing what vars that other ns has

hugod20:10:28

unfortunately, we usually have several. Definitely better behaviour once the cache is built.

borkdude21:10:01

ok, then 1010 needs to be solved to support this

borkdude21:10:12

maybe you could make a small comment there explaining your use case

👍 3
jfntn18:10:17

👋 I’ve seen some mentions of orchestra.core/defn-spec in the github issues and I’ve tried adding {:lint-as {orchestra.core/defn-spec clj-kondo.lint-as/def-catch-call}} to my config.edn but I’m still getting unresolved-symbol errors for all the fn args. Is there a solution to this?

borkdude20:10:17

Can you give an example? Clj-kondo now supports hooks so this might be the better way to support that macro

jfntn22:10:25

Nice work on that api, def looks doable!

jfntn22:10:49

Usage looks something like this:

(defn-spec arities number?
  ([a number?]
   (inc a))
  ([a number?, b number?]
   (+ a b))
  ([a string?, b boolean?, c map?]
   0))
Where the predicates are specs

borkdude22:10:13

that looks quite doable then yes. there are other examples here: https://github.com/clj-kondo/config

borkdude22:10:22

you can PR your config there if you want, so others can profit

borkdude22:10:42

I also want to support picking up configs/hooks from library dependencies themselves in that config project

👍 3