Fork me on GitHub
#clj-kondo
<
2020-04-29
>
gordon10:04:48

We're using (and loving) clj-kondo, but I was wondering if anybody has found a nice, automated, way for clj-kondo to play well with HugSQL? HugSQL defines functions at namespace load-time, and tickles the undeclared-var linter. We can declare the vars before invoking HugSQL, or we can configure clj-kondo to ignore those particular vars, but neither solution is particularly elegant, they both need manual updating if we add more HugSQL functions.

borkdude10:04:40

@gordonsyme_clojurians I use hugsql and I do use declare. Another way is to just turn the unresolved symbol linter off for that namespace. Another workaround: use a small namespace foo.db.hugsql in which you let hugsql create the functions. then you require that namespace from foo.db as [foo.db.hugsql :as queries] and voila, no more warnings. you just type queries/select-users and clj-kondo won't complain anymore

borkdude10:04:26

I just thought about that last way while typing, I think I'm going to try that myself as well

gordon10:04:36

Thanks, that's a neat idea!

mafcocinco12:04:33

We also use HugSQL. That is a neat idea! We currently use the declare approach (which was originally suggested to me by @borkdude). It works great and, though it requires some discipline to keep in sync with the corresponding file, does have the nice side benefit of providing a .clj file where a person could look to see what functions are available without having to look through the SQL.

mafcocinco12:04:51

Our namespacing is similar, which makes it very easy to navigate the code. Generally, our (Hug) .sql files are kept on a path project/sql/schema_name/table_name.sql and are then loaded by a .clj file located at project.queries.schema_name.table_name. Any namespace that needs to interact with the specified table includes the project.queries.* namespace and has all the functions they need. Has made it pretty simple (i.e. predictable) for devs to navigate the various HugSQL functions within a project.

plins19:04:13

hello, Im trying to work with slingshot/try+ and Id like to know If there is a macro in clojure like

(catch [:type error/not-found] {:keys [msg]}
  ...)
so I can use lint-as

borkdude19:04:23

I don't think there is. Probably the :unresolved-symbol config is what you need here

plins20:04:37

did this, the warning went away, but what happens then? everything inside the try+ block is ignored?

borkdude20:04:11

the false positives because of that macro are gone, at the cost of false negatives

borkdude20:04:04

slingshot/try+ seems like a library that is used quite a lot, so I'd be happy to get built-in support for that. feel free to post an issue about it

borkdude20:04:21

I don't personally use it

plins21:04:02

ok thanks Ill do that 🙂

borkdude21:04:00

yes, thank you

🎉 8