Fork me on GitHub
#clj-kondo
<
2023-01-10
>
Jakub Holý (HolyJak)08:01:02

Hello! What is the recommended way of dealing with libs that generate their fns from some data / other ns, such as https://github.com/expez/superstring/blob/master/src/superstring/core.clj#L35-L36 ?

borkdude09:01:24

It seems that defalias is similar to def so you can use:

{:lint-as {foobar/defalias clojure.core/def}}

borkdude09:01:22

it seems that (alias-ns clojure.string) is the same as (:require [clojure.string :refer :all]) - why invent a new syntax for this

borkdude09:01:33

ah yeah, I see, they are creating vars in their namespace to re-export clojure.string

borkdude09:01:19

there's not much that you can do about this in clj-kondo, except that you can :exclude some vars in the unresolved var linter

Jakub Holý (HolyJak)09:01:31

I though that perhaps there was a way to tell Kondo that superstring.core/join etc. exists and is the same as clojure.core/string etc. Ok, we will just exclude this lint check for the ns then.

borkdude09:01:57

I think you might just as well use clojure.string directly ;)

wilkerlucio12:01:47

one way is to have an explicit declare for all the things being generated, Fulcro uses this approach for the DOM namespace: https://github.com/fulcrologic/fulcro/blob/main/src/main/com/fulcrologic/fulcro/dom.cljs#L17-L30

borkdude12:01:31

another way to "fix" this is to use clj-easy/stub https://github.com/clj-easy/stub which can generate stub namespaces with vars detected at runtime. Then you need to add this to your "lint" path so clj-kondo will pick up on those stubs

borkdude12:01:53

but the declare approach is the most robust I'd say

wilkerlucio12:01:42

what I like about declare is that it will work with any tool (like LSP, but also Cursive)

borkdude12:01:23

yes, that's what I mean with "robust" :)

🙂 2
borkdude12:01:46

perhaps the super-string maintainers can be convinced to add it

Jakub Holý (HolyJak)10:01:02

awesome, thanks! I will talk to the maintainer

Jakub Holý (HolyJak)22:01:07

FYI superstring has a new release with the declare s. Thanks for the tip!

🎉 6