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

Report mismatch between specified and given arguments in datalog queries #900

Open
tatut opened this issue May 28, 2020 · 7 comments
Open

Comments

@tatut
Copy link

tatut commented May 28, 2020

Is your feature request related to a problem? Please describe.
For example a datomic query can mistakenly omit the :in definitions
from a query, causing the query to return too many results.

(d/q '[:find ?e :where [?e :item/owner ?user]] db user)

The missing :in $ ?user defaults to :in $ which doesn't match the given
argument counts (2, db and user).

Describe the solution you'd like
clj-kondo could report something like "query expects 1 argument, but 2 are given" when we can see that the argument counts have a mismatch.

Describe alternatives you've considered
Alternative is to create a wrapper macro to catch this at compile time.

@borkdude
Copy link
Member

@tatut Linting datalog is handled by https://github.com/lambdaforge/datalog-parser. So if you could also post this over there, or link to this issue from other there, the maintainers of that library can maybe pick it up.

@tatut
Copy link
Author

tatut commented May 28, 2020

It looks like the datalog-parser doesn't actually check the d/q function call, but just sees the [:find ...] query part. So this might be something that is on the edge of kondo and datalog-parser.

@borkdude
Copy link
Member

The maintainers also wrote the integration in clj-kondo of that library, so still good to bring it up there I think. Or ping them here. @whilo

@borkdude borkdude added the enhancement New feature or request label May 28, 2020
@borkdude borkdude added this to Needs triage in clj-kondo via automation May 28, 2020
@borkdude
Copy link
Member

Maybe the call to datalog/parse could receive some options, e.g. the number of inputs or the remaining argument nodes, so it can be accounted for during the parsing and validation.

https://github.com/borkdude/clj-kondo/blob/1527e03c39f885fa8d1cd4fdfab23bcce1935078/src/clj_kondo/impl/analyzer/datalog.clj#L20

@whilo
Copy link
Contributor

whilo commented May 29, 2020

@tatut That is a very reasonable suggestion and a nice example of integration of static analysis on the boundaries between different languages. The only thing necessary for this is to match the sources parsed (count (:qin parsed-query)) to the argument count you are passing to q. If you have time to go ahead please feel free to do so, otherwise I will have a look into this in the next weeks. This will require no changes to the datalog-parser, only to datalog.clj in clj-kondo.

@borkdude borkdude moved this from Needs triage to Medium priority (new / enhance) in clj-kondo Jul 27, 2020
@stale
Copy link

stale bot commented Dec 3, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the expired expired - might be closed due to too little activity label Dec 3, 2021
@borkdude borkdude added PR welcome and removed expired expired - might be closed due to too little activity labels Dec 3, 2021
@stale
Copy link

stale bot commented Jun 2, 2022

This issue has been automatically marked as expired because it has not had recent activity. To prevent it from being closed, please leave a message. Additionally, consider giving the original message a thumbs up if this issue is important to you, so it will appear higher in this list. Thank you for your contributions!

@stale stale bot added the expired expired - might be closed due to too little activity label Jun 2, 2022
@borkdude borkdude added the pinned label Jun 2, 2022
@stale stale bot removed the expired expired - might be closed due to too little activity label Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
clj-kondo
  
Medium priority (new / enhance)
Development

No branches or pull requests

3 participants