Fork me on GitHub
#clj-kondo
<
2019-07-09
>
borkdude06:07:05

@lee I think you’re the first clj-kondo user that uses :default, it’s currently not recognized. I’ll make a fix, thanks

borkdude06:07:51

If you include :cljs in the last example it’ll probably work

sogaiu07:07:28

fwiw, it's nice to use :default because of the potential for clojure clr support

borkdude07:07:14

yes, it should be supported

sogaiu07:07:57

good to hear 🙂

borkdude08:07:28

@lee which OS are you using?

lread11:07:11

I got that :default idea from our very own @sogaiu. I am not handling clojure-clr yet, but it is a step in that direction.

lread11:07:47

I am on macOS, and thanks! You are speedy!

lread11:07:17

BTW your clj-kondo logo is pretty awesome. It tells the story and spirit of the tool in smile inducing way.

borkdude11:07:29

I think I recommended :default to you too in the rewrite-clj channel 🙂

borkdude11:07:52

thanks, it was the result of a nice interaction with nikitonsky on twitter

lread11:07:47

well, my continued thanks to you both simple_smile

borkdude11:07:24

or maybe I recommended it to someone else, but I vaguely remember this for the same reason as sogaiu mentions: if more targets are added, you're already future proof

lread11:07:05

yeah it’s a good tip!

lread13:07:40

just tried snapshot build you provided, works like a charm, thank you!

borkdude13:07:33

thanks for reporting and testing

lread13:07:48

rewrite-clj has maybe uncovered another clj-kondo issue. In a macro, a variable only referenced with quote unquote is reported as unused. For example, clj-kondo gives an unused binding warning for new-meta for the following:

(defmacro import-fn
  "Given a function in another namespace, defines a function with the
   same name in the current namespace.  Argument lists, doc-strings,
   and original line-numbers are preserved."
  [src-sym target-name target-meta]
  (let [vr (resolve-sym src-sym)
        m (meta vr)
        m (resolve-fn-location m)
        new-meta (dissoc target-meta :name)
        protocol (:protocol m)]
    (when (:macro m)
      (throw (ex-info "potemkin clj cannot import-fn on a macro" {:symbol src-sym})))
    `(do
       (def ~(with-meta target-name (if protocol {:protocol protocol} {})) (deref ~vr))
       (alter-meta! (var ~target-name) merge '~new-meta)
       ~vr)))

borkdude13:07:56

would '~new-meta be the same as (quote ~new-meta)?

borkdude13:07:11

might work as a workaround, nevertheless, it's a false positive

lread14:07:11

yes, that work-around does the trick.

lread14:07:55

do you want a git issue for this one?

borkdude14:07:35

right now clj-kondo doesn't analyze everything that follows a literal quote for usages, but in backticks this apparently doesn't hold

lread14:07:32

I have another one for you. When including a macro like so in a cljc source:

(ns forborkdude
  #?(:cljs (:require-macros [forborkdude :refer [my-macro]])))

#?(:clj
   (defmacro my-macro[x]
     `(str "hello there, " ~x)))

(my-macro "borkdude")
clj-kondo reports my-macro as an unresolved symbol.

borkdude14:07:40

@lee what's the reason you're only defining it for :clj?

borkdude14:07:52

your lib doesn't support self-hosted CLJS?

borkdude14:07:16

nonetheless, it's a false positive that kondo should support

lread14:07:31

self-hosted CLJS is on my todo list… still need to learn details on how macros work there.

borkdude14:07:16

for self-hosted you'll need to remove the :clj conditional and then it should just work, unless you're using JVM specific things

lread14:07:04

well that’s cool.

lread14:07:02

i can git issue this one too if you’d like

borkdude14:07:51

yes please!

borkdude15:07:36

thank you ❤️

lread15:07:48

and thank you too for all your help and a linter that sparks joy

lread18:07:34

thanks, that fixed the issue.

lread19:07:54

ok, no more clj-kondo warnings under my src tree, time to move on to test!

lread19:07:50

rewrite-clj tests make heavy use of the clojure.test.are macro. Does clj-kondo want to do any linting on these? Contrived silly example:

(deftest t-for-borkdude
  (are [?a ?b]
      (is (= ?a (dec ?b)))
    1 2
    10 11
    14 15))
Currently clj-kondo informs me that ?a and ?b are unresolved symbols.

lread19:07:27

ah… it is missing the cljs.test variant.

lread19:07:16

If I add the following to my .clj-kondo/config.edn my cljc files no longer produce warnings:

{:linters
 {:unresolved-symbol
  {:exclude [(cljs.test/are)
             (cljs.test/is [thrown-with-msg?])]}}}

lread19:07:28

I’ll git issue this one.

borkdude19:07:12

@lee Not yet, thanks for the git

lread20:07:26

I frankly don’t much about them yet, but rewrite-clj uses defspec in some tests. I don’t think clj-kondo handles these puppies yet?

borkdude20:07:21

what's defspec?

lread20:07:47

hmmm… I assumed it was a common thingy. I’ll get back to you.

lread20:07:33

I’ve not learned about test.check yet.

borkdude20:07:38

you can use :lint-as for this to treat it as clojure.core/def

lread20:07:52

thanks I shall try that!

borkdude20:07:36

{:lint-as {foo.bar/defspec clojure.core/def}}

lread21:07:18

that worked, thank you!

borkdude21:07:02

Updated docs for the snap package manager. You might want to try it: https://github.com/borkdude/clj-kondo/blob/master/doc/install.md#snap-linux (cc @jr0cket)

👍 4