Fork me on GitHub
#clj-kondo
<
2023-08-21
>
Nick McAvoy21:08:06

I'm seeing a false positive with a java import in the clj reader conditional of a babashka file. It's showing unused. (See thread.)

Nick McAvoy21:08:20

Here's asdf.cljc

(ns asdf
  (:import
   (java.math BigDecimal)))

#?(:clj
   (do
     (defn ->decimal
       (^BigDecimal
        [value]
        (if (string? value)
          (BigDecimal. ^String value)
          (bigdec value))))))

Nick McAvoy21:08:38

> clj-kondo --lint /tmp/asdf/asdf.cljc 
/tmp/asdf/asdf.cljc:3:15: warning: Unused import BigDecimal
linting took 11ms, errors: 0, warnings: 1

Nick McAvoy21:08:49

> clj-kondo --version
clj-kondo v2023.07.13

Nick McAvoy21:08:12

I'm happy to file an issue, just configure this one away, or whatever you recommend.

borkdude21:08:34

This is because the :import is not in a :clj reader conditional. It won't work in CLJS anyway

Noah Bogart21:08:11

But also, babashka files use the clj branch of the bb branch isnโ€™t encountered first

Nick McAvoy21:08:56

Yes, we have this in our source code here:

#?(:clj ;; bb will load :clj code if no :bb implementation is defined. The following code is compatible with clj and bb, but not cljs.
We've got bb and clj in our stack, but not cljs, so cljs incompatibility is not a problem for us.

๐Ÿ‘ 2
borkdude21:08:47

Alright, you can put this in your config.edn: {:cljc {:features [:clj]}}

borkdude21:08:16

then clj-kondo will only lint the :clj branches and won't complain about anything related to other stuff

borkdude21:08:42

in your above repro, the :clj branch will still be executed by bb as well btw.

borkdude21:08:10

(but you already knew this, I got this from your latest reaction)

๐Ÿ‘ 2
Nick McAvoy21:08:56

I'll try that, thank you!

๐Ÿ‘ 2
Nick McAvoy21:08:51

Yup, the warnings disappeared. Thanks again!

๐Ÿ‘ 4