clj-kondo

https://github.com/clj-kondo/clj-kondo
verma 2021-02-11T21:37:51.128200Z

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)))

verma 2021-02-11T21:39:06.129500Z

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))]))

verma 2021-02-11T21:39:29.130100Z

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

verma 2021-02-11T21:40:28.131300Z

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

verma 2021-02-11T21:42:18.131700Z

here's the code for the hook: https://gist.github.com/verma/58a6c170189b5cf3dc9bf4103ce2e475

borkdude 2021-02-11T21:52:57.132400Z

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

verma 2021-02-11T21:53:53.132700Z

checking

verma 2021-02-11T21:56:38.133700Z

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

verma 2021-02-11T21:57:10.134300Z

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

verma 2021-02-11T21:58:00.134800Z

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

borkdude 2021-02-11T21:58:56.135300Z

what doesn't look right about it?

verma 2021-02-11T21:59:01.135400Z

hmm, never mind that looks ok

borkdude 2021-02-11T21:59:12.135900Z

are you re-defining defn perhaps in this namespace?

verma 2021-02-11T21:59:14.136100Z

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

verma 2021-02-11T21:59:44.136300Z

no I don't think so

borkdude 2021-02-11T22:00:35.136500Z

ah

verma 2021-02-11T22:00:56.136800Z

(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   

verma 2021-02-11T22:01:07.137300Z

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

borkdude 2021-02-11T22:01:20.137500Z

Can you perhaps print the incoming node too?

verma 2021-02-11T22:01:24.137700Z

also not sure why printing twice

verma 2021-02-11T22:01:33.137800Z

yeah one second

verma 2021-02-11T22:01:42.138Z

<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)))>

verma 2021-02-11T22:02:15.138200Z

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

borkdude 2021-02-11T22:02:34.138400Z

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

borkdude 2021-02-11T22:02:44.138600Z

or is it a work project?

borkdude 2021-02-11T22:02:59.138800Z

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

verma 2021-02-11T22:03:07.139Z

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

verma 2021-02-11T22:03:14.139200Z

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

borkdude 2021-02-11T22:03:23.139400Z

yes, please set it up completely

borkdude 2021-02-11T22:03:27.139600Z

this will save me time

verma 2021-02-11T22:03:53.139800Z

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

verma 2021-02-11T22:12:06.140Z

I am sorry @borkdude 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))

verma 2021-02-11T22:12:17.140200Z

please accept my apology for wasting your time

borkdude 2021-02-11T22:12:41.140400Z

Not a problem. Glad you found it.

verma 2021-02-11T22:13:18.140600Z

🙂 thank you!