@borkdude Ok almost got it. The only issue is that I'm receiving unsupported binding form input, another warning:
(ns hooks.rum.defc
(:require
[clj-kondo.hooks-api :as api]))
(defn defcs
[{:keys [node]}]
(let [args (rest (:children node))
component-name (first args)
args (next args)
[fn-args body] (loop [args* args
mixins []]
(if (seq args*)
(let [arg (first args*)]
(if (vector? (api/sexpr arg))
(let [fn-args (api/sexpr arg)
fn-args-without-state (vec (rest fn-args))]
[(with-meta (api/vector-node fn-args-without-state) (meta arg))
(concat mixins (rest args*))])
(recur (rest args*)
(conj mixins arg))))
[nil nil]))
new-node (when fn-args
(with-meta (api/list-node [(api/token-node 'defn)
component-name
fn-args
(api/list-node
(list*
(api/token-node 'let)
(api/vector-node
[(api/token-node 'state) (api/token-node {})])
body))])
(meta node)))]
{:node new-node}))
demo.cljs
(ns demo
(:require
[rum.core :as rum]))
(rum/defcs SomeComponent <
{:did-mount (fn [state] state)}
[state input another]
(let [x "Hello"]
nil))
(rum/defc SomeComponent1 <
{:did-mount (fn [state] state)}
[input]
input)
(SomeComponent "hello")
Any ideas how to fix it?"Can you print the sexpr using (println (api/sexpr new-node))
and show what it makes?
(defn SomeComponent [input another] (let [state {}] < {:did-mount (fn [state] state)} (let [x Hello] nil)))
Can you post the raw output without editing it?
Maybe use prn
instead of println
to preserve the string
(defn SomeComponent [input another] (let [state {}] < {:did-mount (fn [state] state)} (let [x "Hello"] nil)))
Btw, I did get the correct linting with your code
Are you use your config.edn is edited properly?
I now have this:
{:hooks {:analyze-call {rum.core/defc hooks.rum.defc/defc
rum.core/defcs hooks.rum.defc/defcs}}
:lint-as {;; rum.core/defcs rum.core/defc
rum.core/defcc rum.core/defc}}
So, all looking OK here
Config:
{:hooks {:analyze-call {rum.core/defc hooks.rum.defc/defc
rum.core/defcs hooks.rum.defc/defcs}}
:lint-as {rum.core/defcc rum.core/defc
view.core/FOR clojure.core/for
view.core/KEEP clojure.core/keep}
:linters {:missing-else-branch {:level :off}}}
I'm afk for a few hours now.
Maybe wrong version of clj-kondo: clj-kondo v2020.07.29
that's the latest
afk
Ok 🙂 I'm getting that errors only if I run clj-kondo --lint demo.cljs
Then maybe in that case it doesn't pick up on your config
You should run it from the directory that has .clj-kondo in it
I'm doing it 🙂
I'm back now. So, I'm getting good results with your code. What I've done is add it in libraries/rum/.clj-kondo/hooks/rum/defc.clj and added the entry in config.edn. Then I made the screenshots
@borkdude can you please use command clj-kondo --lint demo.cljs and check whether no errors are reported?
Now you're sounding like me, I say this all the time to people. Yes, I'll try it after dinner :)
1👍1❤️haha 😄 Thank you very much! I'm just wrapping my head around why in flycheck buffer those errors are not visible whereas in terminal I can spot them. I think those are internal errors of clj-kondo.
all i have to add at this point is: 👏👏👏👏👏👏👏👏👏👏
@karol.wojcik Works correctly here: src/example.cljs:25:9: warning: unused binding x src/example.cljs:28:1: error: demo/SomeComponent is called with 1 arg but expects 2
When I put that code in src/example.cljs that is
When linted separately, I do see different errors... hmm
Ah I see:
src/example.cljs::: error: unsupported binding form x
src/example.cljs::: error: unsupported binding form input
src/example.cljs::: error: unsupported binding form another
I'll start debugging, brb
OK fixed it. The mistake that was in your hook code is that you inserted sexprs back into the node instead of proper nodes. I took the liberty to just start from scratch and adapt the existing defc one, in this commit: https://github.com/borkdude/clj-kondo/commit/9f004622d0c69a6baf93bb63243306a7098f0941
1❤️If that code isn't sufficient yet, feel free to make another PR
Also I renamed libraries
to examples
to fix the illusion that clj-kondo will pick up on those automatically, it won't, you have to copy the code yourself
one other detail: when introducing a let, you can get warnings about a nested let. you can prevent this by using let*
, this should probably go into the docs
I'm pretty happy that this can be fixed in user-land code, so I don't have to publish a new release for each tweak :)
1❤️Thank you very much @borkdude !
@martinklepsch @robert-stuttaford fwiw, there is a new commit on clj-kondo master which (hopefully) fixes the hook example for rum/defcs
Thanks for the ping, will try & report back :)
stupendous!