Fork me on GitHub
#clj-kondo
<
2022-07-29
>
rayat19:07:38

Hi! Custom hooks question > (I'm like addicted to these now lol) Haven't seen anything in the docs about this, but is there some kind of support for "multiple" hooks per function? Specifically, I'm thinking of the following: 1. I, with @borkdude’s help of course, introduced a couple hooks for #helix (`defnc/$/d/*`), that have since been released and thus introduced into our work codebase (as we use helix) 2. At the same time, we have some business-logic / org-specific things we want to lint for those same functions, that wouldn't make sense for upstream contribution a. (eg a linter warning against using a business-logic-specific fn that doesn't work well in helix components but works great otherwise) 3. I could turn off clojure-lsp's auto copying of library hooks, and then introduce the desired new org-specific linters inline into our own hook(s) for helix, but then I'd lose automatically getting any upstream changes when helix (and its hooks) update (at which point clojure-lsp would copy over the changed hooks) Any thoughts or prior art on this? 1. I'm wondering, if it doesn't already exist, if some way to override or "cascade" (in the sense of like, CSS or something) hooks might work. ◦ Not sure how one might navigate the fact that the "order" of apply hooks matters a lot, as one hook's output might utterly invalidate subsequent ones' input expectations. 2. Or is it just worth it instead to introduce some degree of configurability into the #helix hooks such that they can - to start with - accept some collection of no-no symbols to warn against usage?

borkdude20:07:05

@rayatrahman9 Currently there can be only one hook for a function/macro. I'm considering multiple hooks, but if one hook transforms the call, then the other hooks won't get to see the input at all, so it's tricky. You could just configure your own hooks, then the imported hooks should be ignored

☝️ 1
rayat21:07:18

1. Yeah, tricky indeed. I'll simply say then that I'm very curious what you, in particular, are able to come up with for multiple hooks, should you choose to continue to consider it at all 2. Will try. It will mean still that upstream changes will not be auto copied, but since the upstream library's author is my manager anyways, I don't think it'll be too hard to keep track haha

borkdude21:07:35

What I mean with using it as a library: you could define your own hook, do your own things - don't know if you're only doing some linting or also transformation

borkdude21:07:50

But if you don't do transformation, you can then pass the node to the imported hook function

rayat21:07:11

Ah yes, missed the import suggestion, very cool! That might be a "decent" first step in "multiple" hooks. ie, pre or post hooks with heavy warnings/caveat/"proceed at your own risk" if they transform (too much, or at all), vs just linting with them.

borkdude21:07:17

This is something you can do today, it doesn't need any changes

borkdude20:07:05

Potentially your own hooks could call the imported hooks as a library

deep_thinking 1