Fork me on GitHub
#clj-kondo
<
2021-03-10
>
Volodymyr Huzar11:03:50

I have one more question related to clj-kondo lint-as for plumbing.core I have tried to apply this configuration

:lint-as {plumbing.core/defnk clojure.core/defn
          plumbing.core/letk clojure.core/let}
and as result I get syntax linter error “error: unsupported binding form :events” for
(defnk init [[:events on-select-fn :as events] path]
and “error: unsupported binding form :results” for
(letk [[[:results {result nil} {nextCursorMark nil}]] results]
@borkdude is it expected or it is a bug similar to what was solved yesterday for plumbing.core/?>?

borkdude11:03:40

This is expected since :events is indeed not a valid binding form in defn

borkdude11:03:06

If you want to have proper support for these macros you will have to write a hook. https://github.com/borkdude/clj-kondo/blob/master/doc/hooks.md You can contribute it to https://github.com/clj-kondo/config for sharing the hook with others. The other way is to simply ignore unresolved bindings in these macros.

Volodymyr Huzar11:03:34

by ignore do you mean configure somehow clj-kondo to ignore them?

borkdude11:03:25

:unresolved-symbol {:exclude [(plumbing.core/defnk)]}

Volodymyr Huzar11:03:06

thanks, it is actually what we are doing right now. I’ll try to look on hooks for the better solution to fix the problem

Volodymyr Huzar12:03:20

Actually :unresolved-symbol {:exclude [(plumbing.core/defnk)]} generates new unresolved-symbol errors for declarations inside (defnk fn []) So probably only hooks are the rescue when plubming.core is used 😞

borkdude12:03:39

@vguzar Can you give me a repro of this? I think you should always be able to suppress warnings using config

Volodymyr Huzar12:03:46

@borkdude sorry I have wrongly described the error. When :unresolved-symbol {:exclude [(plumbing.core/defnk)]} is used everything that is declared using defnk of letk became unresolved symbol. For example for all usages of declared request-async

(defnk request-async [{method :get} {headers nil} url {payload nil}])
you’ll get error: Unresolved symbol: request-async

borkdude12:03:31

@vguzar Ah, for this we have:

{:lint-as {plumbing.core/defnk clj-kondo.lint-as/def-catch-all}}

borkdude12:03:55

lint-as def-catch-all will use the first symbol as the var name and won't warn about anything else in that defn-like macro

Volodymyr Huzar12:03:37

thanks, that could be a rescue let me try

Volodymyr Huzar15:03:34

works perfectly, thank you one more time

Volodymyr Huzar15:03:45

sorry for bothering but one error related to `

:unresolved-symbol
which is bothering me and I cannot understand. For this code
(defn set-channels [search {:keys [channel static-channels]
                            :or {channel (:channel search)}}]
clj-kondo complains with error: Unresolved symbol: search The syntax seems to be ok and code is working as it should, any ideas what is wrong here?

borkdude15:03:29

@vguzar There is an issue about this here: https://github.com/clj-kondo/clj-kondo/issues/916 and https://github.com/clj-kondo/clj-kondo/issues/782 I think this should be supported but was considered not supported in Clojure at one point, but this viewpoint has changed.

borkdude15:03:06

For now it's probably best to use a let binding

borkdude15:03:47

I will bump the priority of issue 916

Volodymyr Huzar16:03:34

Another issue with :unresolved-symbol related to anonymous methods #() and metadata. In this case

#(let [status (.getStatus ^clj %)])
I got an error error: Unresolved symbol: clj Didn’t get the same for regular function definition (fn [^clj xhr]

borkdude16:03:44

@vguzar Is this .cljc code or only .cljs?

borkdude16:03:39

what does ^clj mean in the context of .cljs code?

Volodymyr Huzar16:03:34

actually it is a good a question 🙂 I would try to get an answer. Could it influence the fix for linter. I see it used in many places in regular fn but linter is complaining only about anonymous function

borkdude16:03:01

Ah, I see:

(defn foo [^clj x])

(fn [^clj x])

#(do ^clj %) ;; only here

borkdude16:03:08

That's probably a bug in clj-kondo

borkdude16:03:25

Please post an issue

👍 3
jaide21:03:19

Anyone have an example of a .clj-kondow/config.edn configured for reagent macros to share?