Fork me on GitHub
#clj-kondo
<
2022-10-27
>
Roman Liutikov11:10:58

@borkdude Hey, thanks for the heads up on analysis stuff! How can I tell clj-kondo to produce full analysis AST? What I'm seeing right now is only var definitions w/o body AST

borkdude11:10:51

Hey! Yes, re-iterating my comment on Reddit: What you get from the analysis data is just data, no AST. But you can match this data on location on whatever AST structure you produce using rewrite-clj.

borkdude12:10:33

E.g. getting the fully qualified var name or whether something is a local, etc, you should be able to look up in the analysis data

Roman Liutikov12:10:47

Oh, I see, I thought there's something new I've missed from clj-kondo. This approach doesn't seem suitable for me. I find it more straightforward to have a full AST map at hand right away, as someone who's not familiar with clj-kondo internals.

borkdude12:10:13

Yes, I get that. But to produce such a structure, you can use the clj-kondo analysis. Else you would have to write your static analysis yourself

borkdude12:10:46

So while walking the raw rewrite-clj structure, you can look into the clj-kondo analysis if some symbol is a local or var, then add that data and produce your AST.

Roman Liutikov12:10:39

Hmmm, that makes sense. I can see var defs in analysis output, but not local vars. Is there a config switch for that or something?

Roman Liutikov12:10:14

nice! I thought :analysis true would include everything

borkdude12:10:51

locals and keywords is a lot of data, this is why it wasn't included by default

👍 1
Roman Liutikov12:10:24

ok, I'm seeing the data now. Still it means depending on clj-kondo would mean splitting the analyzer in two pieces and parsing inputs twice: to get vars data from clj-kondo and produce AST for everything else myself, which doesn't feel solid to me.

borkdude12:10:51

This approach is what several tools are doing, clojure-lsp being one of them. Works quite well. Yes, if you use a tool do to analysis, it becomes a dependency. Parsing the code twice isn't really a problem, it's only a small fraction of the total time taken.

borkdude12:10:27

You also benefit from clj-kondo hooks that people write for their custom macros

borkdude12:10:28

When clojure-lsp adopted clj-kondo we considering sharing the AST but it wasn't worth the trouble

Roman Liutikov12:10:35

Good point about macros!

Eric Dvorsak20:10:54

Is it feasible for clj-kondo to detect namespaces with mount/defstate that are not required before mount/start is called (I mean does it has enough context to do such checks)? that leads to some nasty NPEs in packaged jars