clj-kondo

https://github.com/clj-kondo/clj-kondo
martinklepsch 2020-07-23T10:29:11.204200Z

@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?

borkdude 2020-07-23T10:30:43.205200Z

@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?

borkdude 2020-07-25T13:48:03.233Z

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

borkdude 2020-07-23T10:32:20.206Z

PR welcome for the reference config

martinklepsch 2020-07-23T10:48:20.207800Z

@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 "clojure.core$vec@104a1
ea78"]][:children (<token: state> <token: r>)]]>

WANTED <vector: [r]> 

martinklepsch 2020-07-23T10:48:53.208400Z

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

borkdude 2020-07-23T10:49:38.208700Z

@martinklepsch what is a?

martinklepsch 2020-07-23T10:49:53.209Z

<vector: [state r]>

borkdude 2020-07-23T10:50:04.209400Z

you probably need (rest (:children a))

borkdude 2020-07-23T10:50:29.209800Z

See the hooks docs, they explain this

martinklepsch 2020-07-23T10:51:48.211400Z

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

martinklepsch 2020-07-23T10:51:52.211600Z

anyways, this seems to work

borkdude 2020-07-23T10:51:56.211900Z

np

martinklepsch 2020-07-23T10:52:08.212300Z

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

martinklepsch 2020-07-23T10:52:13.212500Z

:thinking_face:

borkdude 2020-07-23T10:52:27.213Z

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

borkdude 2020-07-23T10:52:42.213200Z

for the implicit arg right

borkdude 2020-07-23T10:52:57.213500Z

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

borkdude 2020-07-23T10:53:27.214Z

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

martinklepsch 2020-07-23T10:54:30.214400Z

cool, will do!

robert-stuttaford 2020-07-23T13:06:26.214900Z

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

borkdude 2020-07-23T13:44:19.215200Z

@martinklepsch Any luck with that?

martinklepsch 2020-07-23T13:45:02.215800Z

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

borkdude 2020-07-23T13:52:28.216300Z

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

borkdude 2020-07-23T13:53:12.217100Z

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