Fork me on GitHub
#clj-kondo
<
2022-04-12
>
andrewzhurov16:04:10

Is there an util function that takes an expression of a definition (e.g., (def a (+ 1 1)) and gives body (`[(+ 1 1)]`)?

borkdude16:04:20

in the context of clj-kondo, how would you use that?

andrewzhurov16:04:55

I'm thinking to enrich https://github.com/clj-kondo/clj-kondo/blob/9195cc0f0761a2b673816f5296a95380917ff05b/src/clj_kondo/impl/namespace.clj#L189! with body to have all :vars and their corresponding bodies for playing around with semantics of a program. It's not something that clj-kondo intents to do, but I found reg-var! that is almost what I want. 🙂 (I'd like to have all vars of a program with their vals to later on derive one big val without vars) (sounds crazy, yeah)

andrewzhurov16:04:59

So I thought, in order to derive body out of a def expr perhaps there is an utility function

andrewzhurov17:04:49

;; TLDR no worries, I've got it. 😄 seems there is no such function, I see analysis functions for different def exprs parse it one child at a time e.g., in https://github.com/clj-kondo/clj-kondo/blob/9195cc0f0761a2b673816f5296a95380917ff05b/src/clj_kondo/impl/analyzer.clj#L502 e.g., in https://github.com/clj-kondo/clj-kondo/blob/9195cc0f0761a2b673816f5296a95380917ff05b/src/clj_kondo/impl/analyzer.clj#L1035 I'm interested only in those atm and will tweak them to pass into reg-var! :body as well

rgm16:04:30

I'm just dipping my toes into hooks and I want to figure it out with the repl. Are there any tricks I should know about in turning my code into a rewrite-clj node to feed it in for playing around, or is there another/better way that people test hooks?

rgm16:04:45

I've got the (prn ,,,) working to give feedback from a command-line linter run, but was wondering if there's a good way to test them from eg. a (comment (my-hook ,,,)) block. Is making a fn rewrite-clj node -> rewrite-clj node all there is to it?

rgm17:04:57

hm just re-read https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md#debugging and I guess this'll do for now, since the linting run is so fast

rgm16:04:34

oh that does help, thank you. So far I'd been trying to thin down my hook code to just call a function, return a very obvious map eg. {:new-let-binding-vec [,,,]} and do only very obviously correct stuff in the hook. Then I can work on the function someplace else and paste it back in.

rgm16:04:46

(which is probably not a bad strategy for anything, tbh).

dviramontes20:04:11

is it possible to specify a list of source paths for clj-kondo to lint against ? (aka src, test, shared-src, etc) in the ./clj-kondo/config.edn ?

borkdude20:04:15

@dviramontes not in config.edn, these are arguments to either the CLI or JVM lib:

--lint src:test:shared-src

dviramontes20:04:33

nbd, thank you!