clj-kondo

imre 2025-01-26T22:23:57.418569Z

Is there a way to check whether a symbol is bound to at the location :analyze-call is triggered?

imre 2025-01-27T10:42:17.010759Z

Correction: would foo be flagged with Unresolved symbol or Unresolved var

imre 2025-01-27T10:51:31.119559Z

I'm starting to think this info isn't available in analyze-call

borkdude 2025-01-27T10:54:45.408549Z

api/resolve only checks for vars (or classes) at the moment (I just checked this)

borkdude 2025-01-27T10:54:58.658979Z

so it won't resolve locals

borkdude 2025-01-27T10:55:11.275999Z

it could be fixed though

imre 2025-01-27T11:00:08.833579Z

to me it looks like api/resolve will always return some namespace even if the input is garbage

imre 2025-01-27T11:00:37.675659Z

(prn (api/resolve {:name 'foo :call false}))
  (prn (api/resolve {:name 'foo :call true}))
will print
{:ns clojure.test, :name foo}
{:ns clojure.test, :name foo}

borkdude 2025-01-27T11:01:24.743739Z

hmm, probably a bug too :) please file an issue :) this function is too optimistic ;)

borkdude 2025-01-27T11:01:40.882239Z

it does resolve vars to the correct namespace when they are in the ns form (by alias or refer)

imre 2025-01-27T11:02:33.048519Z

yep, if I give it a valid var name, it does the correct thing

imre 2025-01-27T11:02:43.515029Z

I'll create an issue

imre 2025-01-27T11:08:45.180319Z

what does the :call flag control btw?

borkdude 2025-01-27T11:10:06.224019Z

I think it has to do with calls to special forms or macros, you can find this in the implementation of resolve-name

imre 2025-01-27T11:10:59.173969Z

checking, thanks

imre 2025-01-27T11:18:51.374399Z

https://github.com/clj-kondo/clj-kondo/issues/2472

🙏 1
imre 2025-01-26T22:25:29.519229Z

For example in (mymacro foo) , if mymacro is set to be analyzed by a custom hook, can I check in the hook whether foo can be resolved?

borkdude 2025-01-26T22:29:35.455669Z

you can use hooks-api/resolve https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md

❤️ 1
imre 2025-01-26T22:31:29.620889Z

Thank you!

imre 2025-01-26T22:50:53.603719Z

hmm. (api/resolve {:name foo}) always seems to return name and ns whether or not foo is bound in that scope or not. I must be doing something wrong

borkdude 2025-01-26T22:55:43.634269Z

with resolve do you mean resolve to a var or check whether it's a local?

imre 2025-01-26T22:59:29.957089Z

yeah whether foo means anything in that scope

imre 2025-01-26T22:59:52.020619Z

I mean

imre 2025-01-26T22:59:54.901249Z

either

borkdude 2025-01-26T23:00:30.832349Z

I'll be back tomorrow

imre 2025-01-26T23:00:39.187249Z

yeah me too 😄

imre 2025-01-26T23:01:03.523669Z

I didn't expect to find you here this time 😅 thanks for the help

imre 2025-01-26T23:03:26.687869Z

I suppose what I'm looking for is: Given (mymacro foo) , I'm looking for a way to decide whether if the hook analyzing mymacro would replace the call with (prn foo), would foo be flagged with Unresolved symbol or not.