Fork me on GitHub
#clj-kondo
<
2021-02-11
>
verma21:02:51

I am running into a slight issue with my own hook to parse one of the om.tools/defcomponentk macros. The macro usage looks like this:

(defcomponentk wow-component [[:data a b c d] [:state wow mate]]
  (display-name [_]
    "Lol")
  (component-did-mount [_])
  (render [_]
          (+ a b c d wow mate)))

verma21:02:06

I need all those vars a b c d wow mate be resolved, so I wrote one transformer and right before it returns it does a (prn (api/sexpr new-node)) and shows me this:

(defn wow-component [a b c d wow mate] (letfn [(_ [_] "Lol") (_ [_]) (_ [_] (+ a b c d wow mate))]))

verma21:02:29

I am not sure why, clj-kondo still reports a, b, c, d ... all unresolved 😢

verma21:02:28

basically I am turning the defcomponent into one defn and then wrapping the whole body in one letfn since that was the closest similar structure I could find

borkdude21:02:57

So the node is returned? What if you return just a token node, just for debugging? Then it should not report those locals

verma21:02:38

I tried returning (api/token-node '_) and it said: test.clj::: error: Unresolved symbol: _ which seems right. when I comment out the body and just generate this: (defn wow-component [a b c d wow mate]) .. it shows be this:

test.clj::: error: unsupported binding form a                                                                                                                                                                        │
test.clj::: error: unsupported binding form b                                                                                                                                                                        │
test.clj::: error: unsupported binding form c                                                                                                                                                                        │
test.clj::: error: unsupported binding form d                                                                                                                                                                        │
test.clj::: error: unsupported binding form wow                                                                                                                                                                      │
test.clj::: error: unsupported binding form mate                                                                                                                                                                     │
linting took 13ms, errors: 6, warnings: 0

verma21:02:10

wonder if there's something about those vars which is not visible when api/sexpr is run on it, printing raw one second

verma21:02:00

<list: (defn wow-component [a b c d wow mate])> ooof that doesn't look right 😕

borkdude21:02:56

what doesn't look right about it?

verma21:02:01

hmm, never mind that looks ok

borkdude21:02:12

are you re-defining defn perhaps in this namespace?

verma21:02:14

I was wondering if it would show me the types of the vector etc also

verma21:02:44

no I don't think so

verma22:02:56

(def wow-component (fn [a b c d wow mate]))                                                                                                                                                                          │
<list: (def wow-component (fn [a b c d wow mate]))>                                                                                                                                                                  │
test.clj::: error: unsupported binding form a                                                                                                                                                                        │
test.clj::: error: unsupported binding form b                                                                                                                                                                        │
test.clj::: error: unsupported binding form c                                                                                                                                                                        │
test.clj::: error: unsupported binding form d                                                                                                                                                                        │
test.clj::: error: unsupported binding form wow                                                                                                                                                                      │
test.clj::: error: unsupported binding form mate                                                                                                                                                                     │
test.clj::: error: unsupported binding form a                                                                                                                                                                        │
test.clj::: error: unsupported binding form b                                                                                                                                                                        │
test.clj::: error: unsupported binding form c                                                                                                                                                                        │
test.clj::: error: unsupported binding form d                                                                                                                                                                        │
test.clj::: error: unsupported binding form wow                                                                                                                                                                      │
test.clj::: error: unsupported binding form mate   

borkdude22:02:20

Can you perhaps print the incoming node too?

verma22:02:33

yeah one second

verma22:02:42

<list: (defcomponentk wow-component [[:data a b c d] [:state wow mate]] (display-name [_] "Lol") (component-did-mount [_]) (render [_] (+ a b c d wow mate)))>

verma22:02:15

One peculiar difference is that now each error is printing twice, instead of once

borkdude22:02:34

Maybe you can put this code up on Github? Then I'll have a look

borkdude22:02:44

or is it a work project?

borkdude22:02:59

In that case, maybe make a repro repo that I can run locally

verma22:02:07

I did, the hook code is on the gist I posted

verma22:02:14

but I can set it up so you can run it easily, one second

borkdude22:02:23

yes, please set it up completely

borkdude22:02:27

this will save me time

verma22:02:53

yeah definitely, thanks for your help, I'll ping you here when I have it ready to go

verma22:02:06

I am sorry @U04V15CAJ but I am an idiot 🙂 .. While I was prepping this for you I found the mistake, I was converting a vector-node to a vector using (api/sexpr) but then adding it back in, I wasn't mapping to tokens back into token-nodes, basically went from:

(api/vector-node flattened)
;; to this ->
            (api/vector-node (map api/token-node flattened))

verma22:02:17

please accept my apology for wasting your time

borkdude22:02:41

Not a problem. Glad you found it.

verma22:02:18

🙂 thank you!

verma22:02:07

I changed defn to (def (fn ..)) just to be sure.

verma22:02:24

also not sure why printing twice