clj-kondo

https://github.com/clj-kondo/clj-kondo
Volodymyr Huzar 2021-03-10T11:25:50.254300Z

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/?>?

borkdude 2021-03-10T11:26:40.254700Z

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

borkdude 2021-03-10T11:28:06.255700Z

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 Huzar 2021-03-10T11:29:34.256800Z

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

borkdude 2021-03-10T11:29:40.257Z

yes

borkdude 2021-03-10T11:30:25.257800Z

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

Volodymyr Huzar 2021-03-10T11:36:06.258700Z

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 Huzar 2021-03-10T12:07:20.261500Z

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 😞

borkdude 2021-03-10T12:23:39.261900Z

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

Volodymyr Huzar 2021-03-10T12:40:46.264800Z

@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

borkdude 2021-03-10T12:41:31.265900Z

@vguzar Ah, for this we have:

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

borkdude 2021-03-10T12:41:55.266400Z

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 Huzar 2021-03-10T12:42:37.267Z

thanks, that could be a rescue let me try

Volodymyr Huzar 2021-03-10T15:29:34.268700Z

works perfectly, thank you one more time

borkdude 2021-03-10T15:29:51.268900Z

:thumbsup:

Volodymyr Huzar 2021-03-10T15:35:45.271300Z

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?

borkdude 2021-03-10T15:38:29.272500Z

@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.

borkdude 2021-03-10T15:39:06.273Z

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

borkdude 2021-03-10T15:39:47.273200Z

I will bump the priority of issue 916

Volodymyr Huzar 2021-03-10T15:40:19.273500Z

oh, thanks

Volodymyr Huzar 2021-03-10T16:19:34.276200Z

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]

borkdude 2021-03-10T16:20:44.276400Z

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

Volodymyr Huzar 2021-03-10T16:22:37.276600Z

cljs

borkdude 2021-03-10T16:24:39.276900Z

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

Volodymyr Huzar 2021-03-10T16:31:34.279300Z

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

borkdude 2021-03-10T16:38:01.280Z

Ah, I see:

(defn foo [^clj x])

(fn [^clj x])

#(do ^clj %) ;; only here

borkdude 2021-03-10T16:38:08.280300Z

That's probably a bug in clj-kondo

borkdude 2021-03-10T16:38:25.280600Z

Please post an issue

👍 1
Volodymyr Huzar 2021-03-10T16:56:52.281Z

Issue https://github.com/clj-kondo/clj-kondo/issues/1212 is here

2021-03-10T21:04:19.281700Z

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

2021-03-10T21:34:31.282400Z

Thanks