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.
@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
I just thought about that last way while typing, I think I'm going to try that myself as well
Thanks, that's a neat idea!
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.
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.
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-asI don't think there is. Probably the :unresolved-symbol
config is what you need here
did this, the warning went away, but what happens then? everything inside the try+
block is ignored?
the false positives because of that macro are gone, at the cost of false negatives
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
I don't personally use it
ok thanks Ill do that 🙂
https://github.com/borkdude/clj-kondo/issues/874 hope its descriptive enough
yes, thank you