This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-06
Channels
- # aleph (13)
- # announcements (1)
- # babashka (89)
- # beginners (23)
- # calva (14)
- # circleci (7)
- # clj-kondo (39)
- # clj-on-windows (1)
- # cljdoc (5)
- # cljsrn (29)
- # clojure (98)
- # clojure-art (3)
- # clojure-conj (5)
- # clojure-europe (14)
- # clojure-nl (1)
- # clojure-norway (9)
- # clojurescript (18)
- # clr (39)
- # code-art (3)
- # community-development (3)
- # cursive (3)
- # emacs (11)
- # events (1)
- # fulcro (12)
- # graalvm-mobile (16)
- # graphql (3)
- # gratitude (1)
- # honeysql (19)
- # java (7)
- # joyride (23)
- # lsp (22)
- # malli (2)
- # missionary (25)
- # off-topic (15)
- # polylith (15)
- # rdf (5)
- # reagent (9)
- # reitit (3)
- # scittle (3)
- # shadow-cljs (37)
- # slack-help (2)
- # sql (10)
I'm using clj-kondo to statically analyze projects for dewey. I'm interested in adding custom analyzers. It seems like there's no way to add additional analyzers. Is that right? I see that it's possible to add hooks and that hooks can emit findings, but it doesn't seem like there's a way to emit analyses? Maybe there's not much of a difference between "findings" and "analysis results"? As an example, I'm interested in extracting all the spec definitions within a project.
I think clojure.spec more runtime oriented than amenable to static analysis. I've tried to cross that bridge here a bit: https://github.com/clj-kondo/inspector
We could make the SCI environment pluggable so you can do anything you need in your hooks, e.g. spit out stuff to a database or whatever. But you could experiment with this in a fork to start, I think
I think it would be valuable just to have the keyword for each spec and the definition form
we do have those keywords for clojure.spec already, I think there's a defined-by clojure.spec.alpha key on them in the keywords analysis or so
and doc strings once there’s support
this issue might be related: https://github.com/clj-kondo/clj-kondo/issues/1268
I’m generally interested in custom analyzers. The spec defs is just an example
there is some custom analysis available, you can add :context
to something and this could be anything - I'd have to look this up how it works exactly
cool! so I would create a hook and return some data in a :context
key?
yes. you would add to the keyword some :context {:my-thing "blob"}
and if you then request analysis with {:content [:my-thing]}
or {:context true}
, the keyword will appear with that data in the analysis
this was more a way to add arbitrary properties to existing analysis, but I think we could also allow inserting whatever analysis you like to see
This reminds me of my wip experiment of switching to clj-kondo data analysis for MrAnderson, the library inliner tool.
I think kondo analysis data has got all I might need for namespace renames but I was less sure about import renames.
Nice to remember that I might use :context
if I need it.
Finally getting a chance to play with clj-kondo's hooks for static analysis. I just forked clj-kondo to add support for using functions as hooks to help with programmatic support, https://github.com/clj-kondo/clj-kondo/compare/master...phronmophobic:clj-kondo:master Usage
(defn my-def-hook [o]
(prn "hi")
o)
(defn analyze-project [paths]
(let [config {:cache false
:lint paths
:config {:analysis {:locals true
:keywords true
:arglists true
:protocol-impls true
:var-definitions {:meta true}
:namespace-definitions {:meta true}}
:hooks
{:analyze-call
{'clojure.core/def my-def-hook}}
:linters (default-linters-off)}}]
(clj-kondo/run! config)))
Is this something clj-kondo
would be interested in. Should I start a pull request?I'm not exactly sure what you're trying to do. JVM functions vs SCI interpreter functions? Maybe you can describe a problem instead of a solution?
Sure, dewey is a project that tries to collect information on all the clojure projects on github. As part of that, I run clj-kondo's static analysis to collect information, https://blog.phronemophobic.com/dewey-analysis.html. Currently, the analysis relies on the built in options that clj-kondo offers. I'd like to expand the analysis to include things like all of the spec definitions for every project.
Based off the previous answers in this thread, it seemed like the best way to do that was to write custom hooks to return extra context.
Sure, this seems like a small innocent change, so PR welcome. You may want to include a test so we don't accidentally break it later.
You may also be able to do this without this change and use the :context
option, to include extra information on the spec-ed keyword, which will end up in the analysis data
Right, collecting specs
is just an example.
Does it include the spec definition?
since clojure-lsp uses this for navigating to the definition and usages of a spec (by keyword). no. what would you do with the definition?
Specs are meant to be global. having a global of db specs makes sense to me
This is a related issue btw: https://github.com/clj-kondo/clj-kondo/issues/1268
Part of collecting this information is to find out how specs are being used so part of the answer will be easier to answer once I have the data.
PR welcome btw, I think it makes sense to be able to do your own thing for such purposes
Is there a way to write hooks for host interop (js or java)? One of the topics that comes up in #C053AK3F9 is figuring what parts of Java are worth learning. One way to approach that question is to figure which host interop clojure programs are currently using.
This is a good question.
This is the issue: https://github.com/clj-kondo/clj-kondo/issues/1603
I'm not sure if we want to re-use :analyze-call
for this or have another kind of hook
Awesome. I can also prototype some ideas locally.
Also, not sure if you saw this. Visualizations of all the clojure namespaces and their require
s. gray is just the edges and the dots are the namespaces.
That would be cool, but it’s this project, https://github.com/exoscale/clojure-kubernetes-client/tree/master/src/clojure_kubernetes_client/specs
Working on a more detailed write up
Just saw this! https://github.com/clj-kondo/clj-kondo/commit/d4bce65db2284c2c288e94795ebc9b1d713dad12 This is awesome. Going to try this in a dewey analysis soon!
Finally getting a chance to play with clj-kondo's hooks for static analysis. I just forked clj-kondo to add support for using functions as hooks to help with programmatic support, https://github.com/clj-kondo/clj-kondo/compare/master...phronmophobic:clj-kondo:master Usage
(defn my-def-hook [o]
(prn "hi")
o)
(defn analyze-project [paths]
(let [config {:cache false
:lint paths
:config {:analysis {:locals true
:keywords true
:arglists true
:protocol-impls true
:var-definitions {:meta true}
:namespace-definitions {:meta true}}
:hooks
{:analyze-call
{'clojure.core/def my-def-hook}}
:linters (default-linters-off)}}]
(clj-kondo/run! config)))
Is this something clj-kondo
would be interested in. Should I start a pull request?