clj-kondo

https://github.com/clj-kondo/clj-kondo
2020-10-27T16:51:10.213200Z

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?

borkdude 2020-10-27T16:53:11.213800Z

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

2020-10-27T16:54:31.213900Z

ah nice didn't think about that

2020-10-27T16:57:33.214800Z

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

2020-10-27T16:57:56.215400Z

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

2020-10-27T17:31:30.216600Z

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

borkdude 2020-10-27T18:01:44.217600Z

@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)

borkdude 2020-10-27T18:02:12.217900Z

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

2020-10-27T18:07:30.218400Z

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…

borkdude 2020-10-27T18:07:59.218600Z

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

borkdude 2020-10-27T18:08:10.218800Z

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

borkdude 2020-10-27T18:08:50.219Z

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

2020-10-27T18:09:18.219300Z

I don’t get output from either of those

borkdude 2020-10-27T18:09:23.219500Z

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

borkdude 2020-10-27T18:09:34.219800Z

then maybe your config is off.

borkdude 2020-10-27T18:10:02.220Z

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

borkdude 2020-10-27T18:10:47.220200Z

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

borkdude 2020-10-27T18:11:10.220400Z

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

2020-10-27T18:16:32.220700Z

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

borkdude 2020-10-27T18:17:09.220900Z

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

borkdude 2020-10-27T18:20:41.221100Z

there could very well be a typo somewhere

jfntn 2020-10-27T18:56:17.223100Z

👋 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?

2020-10-27T20:30:36.223200Z

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.

borkdude 2020-10-27T20:46:52.223400Z

Ah right!

borkdude 2020-10-27T20:47:57.223600Z

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.

borkdude 2020-10-27T20:48:28.224Z

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

borkdude 2020-10-27T20:48:45.224200Z

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

borkdude 2020-10-27T20:50:17.224400Z

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

2020-10-27T20:57:38.225Z

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

borkdude 2020-10-27T20:58:06.225200Z

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

borkdude 2020-10-27T20:58:45.225400Z

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

2020-10-27T20:59:28.225600Z

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

borkdude 2020-10-27T21:00:01.225800Z

ok, then 1010 needs to be solved to support this

borkdude 2020-10-27T21:00:12.226Z

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

👍 1
jfntn 2020-10-27T22:09:25.226300Z

Nice work on that api, def looks doable!

jfntn 2020-10-27T22:09:49.226500Z

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

borkdude 2020-10-27T22:10:13.226700Z

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

borkdude 2020-10-27T22:10:22.227Z

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

borkdude 2020-10-27T22:10:42.227300Z

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

👍 1