Fork me on GitHub
#clj-kondo
<
2020-07-23
>
martinklepsch10:07:11

@borkdude finally got around to set up the Rum hook but there’s something to still figure out, with defcs and defcc there’s an implicit first argument. Since that is not passed at callsites, clj-kondo will say the function is called with the wrong arity. Would be happy to try to adapt the hook to support that. Do you think that’d require custom hooks or can it be made to work with the same lint-as approach?

borkdude10:07:43

@martinklepsch If the arities are different, then the hooks probably need to be slightly different as well. I wasn't aware of that detail, sorry. I know @robert-stuttaford is also using the hook. Hasn't he ran into this yet? Maybe he doesn't use defcs?

robert-stuttaford13:07:26

yes, we also have this, just haven't gotten round to doing the good opensource citizen thing and writing it up 😞

borkdude13:07:03

A PR fixing the reference config is welcome from either of you

borkdude10:07:20

PR welcome for the reference config

martinklepsch10:07:20

@borkdude I think I’m close. Ttrying to construct a modified argvec using this (api/vector-node (rest a)) but somehow not quite doing what I expect:

INPUT <vector: [state r]> 

OUTPUT <vector: [[:format-string "[%s]"][:wrap-length 2][:seq-fn #object[clojure.core$vec 0x3ac6c820 "[email protected]
ea78"]][:children (<token: state> <token: r>)]]>

WANTED <vector: [r]> 

martinklepsch10:07:53

Also worth noting, printing the args vector node seems to omit spaces so the <vector: [state r]> above is actually printed as <vector: [stater]>

martinklepsch10:07:53

<vector: [state r]>

borkdude10:07:04

you probably need (rest (:children a))

borkdude10:07:29

See the hooks docs, they explain this

martinklepsch10:07:48

I found out about vector-node reading this but don’t know much about rewrite-clj so missed the :children bit

martinklepsch10:07:52

anyways, this seems to work

martinklepsch10:07:08

now the issue however is that the first arg isn’t known inside the function

martinklepsch10:07:13

:thinking_face:

borkdude10:07:27

you can fix this by introducing an artificial let binding with that name, bound to e.g. nil

borkdude10:07:42

for the implicit arg right

borkdude10:07:57

(let [state nil] ... body ...)

borkdude10:07:27

take a look at the hook for slingshot, it also uses this approach I think

martinklepsch10:07:30

cool, will do!

borkdude13:07:19

@martinklepsch Any luck with that?

martinklepsch13:07:02

got sidetracked by some other stuff after realizing that it’s not just a static token but could also have different names or be a destructuring form

borkdude13:07:28

in that case you should use the first element of the binding vector and then put that in the artificial let binding

borkdude13:07:12

(defn foo [stuff ...] body) => (defn foo [...] (let [stuff nil] body))