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 defmymacro
lines, but how do I ignore the usages of these vars?
@andrea.crotti I think you can use {:lint-as {your-awesome-lib.defmymacro clojure.core/def}
for this
ah nice didn't think about that
and also should Emacs with fly-clj-kondo read the .clj-kondo/config.edn file right?
it looks sometimes that running from the cli and what I see in Emacs are out of sync
Is it possible to write tests for hooks? I don’t see how to define a project that makes clj-kondo.hooks-api
available.
@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)
should not be the case, the same binary is invoked. you might want to restart emacs and see if that solved anything
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…
clj-kondo prints a warning if it can't find the hook
you can stick a prn/println in the hook to force some output
if the hook doesn't return a map with :node
then it continues to lint without a transformed node, but with the original node
I don’t get output from either of those
this is by design, since hooks don't always transform nodes
then maybe your config is off.
post a small repro repo and I'll take a look
you can also post your config.edn, so I can see if there's something wrong
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
thanks for the offer - not sure I can post it as is. Using v2020.10.10. The config is valid edn at least 😉.
maybe post the hook config only if you're able to
there could very well be a typo somewhere
👋 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?
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.
Ah right!
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.
as clj-kondo doesn't recommend refer :all or :use I have marked this issue as low priority
but if there's enough relevant problems associated, I might give it more priority
Can you give an example? Clj-kondo now supports hooks so this might be the better way to support that macro
See https://github.com/borkdude/clj-kondo/blob/master/doc/hooks.md
In our case we have a language embedded in clojure, so we have great chunks of code that import the language with :use
.
@hugod Clj-kondo should work fine if you have only one :use at a time
Provided you have linted that other namespace as well. Else clj-kondo has no way of knowing what vars that other ns has
unfortunately, we usually have several. Definitely better behaviour once the cache is built.
ok, then 1010 needs to be solved to support this
maybe you could make a small comment there explaining your use case
Nice work on that api, def looks doable!
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 specsthat looks quite doable then yes. there are other examples here: https://github.com/clj-kondo/config
you can PR your config there if you want, so others can profit
I also want to support picking up configs/hooks from library dependencies themselves in that config project