clj-kondo

https://github.com/clj-kondo/clj-kondo
richiardiandrea 2021-03-05T01:12:01.156100Z

ah good point, I would was thinking more of used but undefined like a (s/keys :req-un [::where]) that does not have corresponding (s/def ::where map?)

2021-03-05T18:40:59.157200Z

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

2021-03-05T18:41:15.157500Z

Is there an updated page with that info?

2021-03-05T18:41:21.157700Z

Can make a PR to fix it

borkdude 2021-03-05T18:42:23.158Z

@jayzawrotny The link should probably go here: https://github.com/clj-kondo/clj-kondo/blob/master/doc/linters.md

2021-03-05T18:46:28.159100Z

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]}}}

2021-03-05T18:47:40.159500Z

Oops I see my mistake, forgot the exclude part

borkdude 2021-03-05T18:55:39.159800Z

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

2021-03-05T18:58:12.160700Z

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

borkdude 2021-03-05T18:58:51.161300Z

unused-import is for classes

2021-03-05T18:59:01.161700Z

My apologies

2021-03-05T18:59:54.162700Z

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

borkdude 2021-03-05T19:00:00.162900Z

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

borkdude 2021-03-05T19:00:08.163200Z

No worries

2021-03-05T19:01:01.163900Z

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

borkdude 2021-03-05T19:01:22.164400Z

Is this .cljs file?

2021-03-05T19:01:26.164700Z

Correct

borkdude 2021-03-05T19:01:45.165200Z

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

2021-03-05T19:02:08.165600Z

Cool, looks like the example is for that too

2021-03-05T19:06:11.166100Z

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

2021-03-05T19:06:14.166200Z

borkdude 2021-03-05T19:06:44.167400Z

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

borkdude 2021-03-05T19:06:54.167800Z

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

2021-03-05T19:06:59.167900Z

{: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!]}}}}

2021-03-05T19:07:25.168500Z

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

borkdude 2021-03-05T19:07:53.168900Z

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

2021-03-05T19:10:01.169400Z

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

2021-03-05T19:11:21.169800Z

Though I suppose for this branch I can remove the conditional

borkdude 2021-03-05T19:11:42.170100Z

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

2021-03-05T19:11:58.170400Z

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

2021-03-05T19:12:13.170900Z

The current-file function runs in cljs

borkdude 2021-03-05T19:12:15.171Z

yes, but macros are always executed in clojure

2021-03-05T19:12:28.171300Z

Ok, I can change it to clj then.

borkdude 2021-03-05T19:12:44.171800Z

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

borkdude 2021-03-05T19:12:59.172200Z

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

borkdude 2021-03-05T19:14:24.173400Z

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)

borkdude 2021-03-05T19:22:39.174700Z

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

borkdude 2021-03-05T19:23:21.175500Z

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

2021-03-05T19:23:56.175900Z

Oh!

2021-03-05T19:24:06.176200Z

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

2021-03-05T19:24:16.176500Z

Lints clean now too 🎉

🎉 1
2021-03-05T19:25:45.177700Z

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.

borkdude 2021-03-05T19:26:34.177900Z

haha, don't worry

2021-03-05T19:28:14.178700Z

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

borkdude 2021-03-05T19:28:23.179Z

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

borkdude 2021-03-05T19:31:03.179700Z

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

2021-03-05T19:32:02.179900Z

Excellent!