Fork me on GitHub
#clj-kondo
<
2023-02-11
>
altaria22:02:19

For writing hooks: is it possible to get the lexical context of a macro?

(let [config {:a 1}]
  (my-macro :watch [{:keys [a]} config] ...)) ;; rewrites into (let [{:keys [a]} config] ...)
kondo still cannot resolve symbol a, I assume it's because it is not aware of the binding of config an level above

borkdude22:02:08

if you expand into (let [{:keys [a]} config] ...) then there should be no problem, but perhaps your expansion isn't quite right?

altaria22:02:11

Thanks! Now I know I am in the right direction. Lemme double check my expansion

borkdude22:02:55

It often helps to print the node before returning it so you can check it on the command line if it looks right

👍 2
altaria22:02:35

Looks like it is expanding into let, very weird...

borkdude22:02:06

Can I see the code?

altaria22:02:58

For sure, thanks! It's for linting clojureDart. f/widget is the culprit macro

(let [config {:width 50.0}]
    (f/widget
     :watch [{:keys [width]} config]
     (m/Container
      .width width)))

altaria22:02:53

This is what I get running clj-kondo --lint (printing the nodes)

[clj-kondo] Linting file: src/acme/main.cljd
:inherit ()
(let [{:keys [width]} config] (m/Container .width width)) {:node <list: (let [{:keys [width]} config] (m/Container .width width))>}
src/acme/main.cljd:14:22: error: Unresolved symbol: width
linting took 248ms, errors: 1, warnings: 0

borkdude22:02:08

I remember that someone else has also written some hooks for this: https://clojurians.slack.com/archives/CHY97NXE2/p1650903306070559

borkdude22:02:34

cc @UL05W6AEM - perhaps these hooks can be bundled with that flutter wrapper library

borkdude22:02:28

@U04AFSRJHNF Is that the same library you're referring to?

borkdude22:02:01

If so, then you can install those hooks with:

clj-kondo --lint $(clojure -Spath) --dependencies --copy-configs

altaria22:02:29

Yeah, it's the same library. However, I think there's still something wrong... Maybe it's the line numbers

altaria22:02:42

Did the install but still got the error

borkdude22:02:50

cool. Maybe @UL05W6AEM can help out as well. I'm going to sleep now, but I'll have a look later too

gratitude-thank-you 2
👀 2
altaria22:02:24

good night!

Dumch11:02:11

I haven't looked into it in about a half year; I'll see if my code is still in use and try to fix it.

Dumch12:02:19

Okay, here's the issue I see: There used to be flutter.alpha/widget, and I wrote the clj-kondo hook to support it. It's not working right now for two reasons: 1. It isn't referenced in clj-kondo/config. 2. Even if it will be referenced, it will not properly work because flutter.alpha2/widget is almost 80% diffrent.

Dumch17:02:34

I will add new hook to support these changes

Dumch18:02:04

@U04V15CAJ, can we add support for a :flds destructuring directly in clj-kondo (https://github.com/D00mch/clj-kondo/commit/26b5901b68d5897d9fcd888350913da8b8c2e9c2)?

borkdude19:02:37

I suppose it's a custom syntax for field destructuring. I know it's tempting, but it's unfortunate that ClojureDart makes up new syntax since this isn't in general good for tooling compatibility. In squint I also have field destructuring but I used metadata to indicate that it's JS destructuring (inspired by the js-interop library):

^:js {:keys [a b c]
This way clj-kondo doesn't have to change for experimental language features. Other tooling that might have problems with this is cursive cc @U2N9GDB1U @U3E46Q1DG

2
borkdude19:02:14

@UL05W6AEM thanks for creating that PR to ClojureDart