Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[analysis] Add defined-by on missing var definitions #1219

Merged

Conversation

ericdallo
Copy link
Member

Fixes #1216

This should add the :defined-by with the full-qualified-symbol for all var-definitions.

@ericdallo
Copy link
Member Author

@borkdude I don't know if that is going to work with hook var-defintions like state-flow/defflow, could you point me to the function that should reg-var! that?

@borkdude
Copy link
Member

@ericdallo So you wrote a hook for state-flow/defflow but after expansion it's linted as normal clojure.core/defn right? Is that the problem? Btw, some tests are failing.

@ericdallo
Copy link
Member Author

Fixed tests, sorry for that!

@borkdude yes, and I just realized that the hook is using a def node, so I imagine that its defined-by will be def, right?

how can we make that work? is there anything we can add to the hook to tell clj-kondo to use a different defined-by?

@ericdallo
Copy link
Member Author

BTW, I think this PR should solve clojure-lsp/clojure-lsp#340 as well :)

@borkdude
Copy link
Member

borkdude commented Mar 17, 2021

@ericdallo We could return an extra value in the hook response, {:node ... :defined-by ...} but a more general name is maybe better...

@ericdallo
Copy link
Member Author

@borkdude it makes sense, any tips how to implement that?
I checked that here we could get the defined-by informed by user via the transformed local and I suppose we should pass to analyze-expression** and pass to some reg-var somewhere?

@borkdude
Copy link
Member

@ericdallo We can maybe put it on the ctx argument here:

(analyze-expression** ctx node)))

@ericdallo
Copy link
Member Author

ericdallo commented Mar 17, 2021

That analyze-expression** is used by a lot of places and the places that reg-var!, call it before calling the analyze-expression** function, so I think maybe we should reg-var! before calling the analyze-expression** here?
I'm kind of lost on that code :p

@borkdude
Copy link
Member

@ericdallo My suggestion was to pass the :defined-by ... value as part of the ctx, so (assoc ctx :defined-by defined-by) and then pick up on it again in analyze-call if it's available. Not sure if that is the right approach, but worth a try. Since defs are usually not nested, this may work.

@ericdallo
Copy link
Member Author

@borkdude just tested your suggestion with the hook and it worked like a charm :)
I changed the hook to:

...
{:node (with-meta new-node (meta node))
 :defined-by 'state-flow.cljtest/defflow}

And clojure-lsp got it correctly!

@borkdude
Copy link
Member

@ericdallo Cool! Maybe add a test for it and then we can merge?

@ericdallo
Copy link
Member Author

ericdallo commented Mar 18, 2021

Sure, should I create a test for the stateflow macro?

@borkdude
Copy link
Member

Just capturing the behavior that hooks can return that :defined-by key.

@ericdallo
Copy link
Member Author

ericdallo commented Mar 18, 2021

Done @borkdude, but the tests are passing local but not on the CI, it seems related with a wrong config-dir here, but I'm passing it just like other tests

@ericdallo ericdallo force-pushed the add-defined-by-on-var-definitions branch from e74c8f0 to 83f04b2 Compare March 18, 2021 13:58
@ericdallo
Copy link
Member Author

Finally fixed @borkdude! IMO we are good to go

@borkdude borkdude merged commit 374094a into clj-kondo:master Mar 18, 2021
@ericdallo ericdallo deleted the add-defined-by-on-var-definitions branch March 18, 2021 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[analysis] missing defined-by on most var-definition bucket analysis
2 participants