Fork me on GitHub
#clj-kondo
<
2021-03-05
>
Eccentric J18:03:59

Hey there, trying to read the docs on unresolved-symbol but the link seems to be dead. https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md#unrecognized-macros

Eccentric J18:03:15

Is there an updated page with that info?

Eccentric J18:03:21

Can make a PR to fix it

Eccentric J18:03:28

Thanks, will create a pr for that momentarily. So if I am understanding it right in my ~/.clj-kondo/config.edn I can put the following?

{ :linters {:unresolved-symbol {my-app.utils/current-file [ns-resolve]}}}

Eccentric J18:03:40

Oops I see my mistake, forgot the exclude part

borkdude18:03:39

Thanks for the upcoming PR! Yes, that's right

Eccentric J18:03:12

:linters
 {:unused-import
  {:exclude [(my-app.utils [dbg!])]}}
Is there something similar for unused-import? Got a cljs file importing a cljc macro.

borkdude18:03:51

unused-import is for classes

Eccentric J18:03:54

I see the unused-referred-var now, that makes sense sorry about that!

borkdude19:03:00

Can you provide an example? It's unlikely that you will need a config for a referred thing that you actually are using

Eccentric J19:03:01

(ns my-app.utils
  (:require-macros
   [my-app.utils :refer [dbg!]])
  (:require
   [cljs.analyzer]))

borkdude19:03:22

Is this .cljs file?

borkdude19:03:45

Ah you want the dgb! macro available, yes this makes a lot of sense for the config. I do something similar with timbre

Eccentric J19:03:08

Cool, looks like the example is for that too

Eccentric J19:03:11

I seem to be running into trouble with the unresolved-symbol exclusion though:

borkdude19:03:44

@jayzawrotny If that is a .cljc file then you should use reader conditionals

borkdude19:03:54

e.g. *file* is not a thing in CLJS

Eccentric J19:03:59

{:lint-as {kitchen-async.promise/-> clojure.core/->
           kitchen-async.promise/let clojure.core/let}
 :skip-comments true
 :linters
 {:unresolved-symbol {:exclude [(my-app.utils/current-file [ns-resolve])
                                (my-app.utils/dbg! [*file*])]}
  :unused-referred-var {:exclude {my-app.utils [dbg!]}}}}

Eccentric J19:03:25

I recall having trouble with that using reader conditionals but I’ll try again

borkdude19:03:53

why have it as a .cljc file at all if it only contains clojure code?

Eccentric J19:03:01

My understanding was that macros have to be in cljc to be used within cljs?

Eccentric J19:03:21

Though I suppose for this branch I can remove the conditional

borkdude19:03:42

no that's not the case, you can put your macros in .clj

Eccentric J19:03:58

Well it’s intended to work in both clj and cljs

Eccentric J19:03:13

The current-file function runs in cljs

borkdude19:03:15

yes, but macros are always executed in clojure

Eccentric J19:03:28

Ok, I can change it to clj then.

borkdude19:03:44

Your current-file function runs during macro-expansion in the JVM

borkdude19:03:59

(unless you use self-hosted clojurescript, but even then you can use .clj for macros)

borkdude19:03:24

Clj-kondo assumes code in .cljc files to be valid for both Clojure and ClojureScript outside conditionals. E.g. future is unresolved for ClojureScript, hence you write #?(:clj (future :foo) :cljs :foo)

borkdude19:03:39

The key point: > First of all - ClojureScript macros are written in Clojure and run during the ClojureScript compilation on the JVM.

borkdude19:03:21

He is not suggesting you need .cljc, he only writes that you cannot use reader conditionals to achieve a certain goal

Eccentric J19:03:06

I think that’s where I got stuck. Thanks very much!

Eccentric J19:03:16

Lints clean now too 🎉

🎉 1
Eccentric J19:03:45

btw do you have a sponsorship thing setup for one-off payments? I kind of have an unwritten rule where if I am wasting maintainers time and it turns out to be on me for not understanding or reading the docs: I donate.

borkdude19:03:34

haha, don't worry

Eccentric J19:03:14

I insist! At least a cup of coffee or a beer. Venmo? Paypal?

borkdude19:03:23

If you want to buy me a cup of coffee: https://ko-fi.com/borkdude

borkdude19:03:03

Thanks a lot. I'll be thinking of your beautiful CGI scripts during my coffee tomorrow ;)