Fork me on GitHub
#clj-kondo
<
2022-01-21
>
serioga11:01:46

Hallo Michiel. Do we have somewhere a linter idea for the (:refer-clojure :exclude [something]) if there is no something in the namespace and :exclude is redundant?

borkdude11:01:03

no, but I think that is a good idea, maybe :unused-refer-exclude or so

serioga11:01:04

It is very good idea, otherwise I have redundant excludes after refactoring 🙂

serioga11:01:13

Should I file a ticket?

borkdude11:01:21

yes, please 🙏

borkdude11:01:17

maybe :redundant-refer-exclude is a better name indeed, since you don't really "use" them

Giorgio Valoti12:01:52

👋 Hello folks. I’m trying to confirm this behaviour with clj-kondo. This should be a reproducible example:

(defn- my-private-fn [])

  (defmacro my-with-redefs
    [bindings & body]
    `(clojure.core/with-redefs ~bindings (f#)
       ~@body))

  #_{:clj-kondo/ignore [:private-call]}
  (my-with-redefs [my-private-fn (constantly :ok)]
                  (+ 1 2))
In other words, I would like clj-kondo to ignore the usage of my-private-fn but it doesn’t, presumably because of macro machinery?

borkdude12:01:59

I don't see the error in this specific example, but I do when I refer to the private var from another ns. Is that what you mean?

borkdude12:01:06

(ns foo)
(defn- my-private-fn [])

(defmacro my-with-redefs
  [bindings & body]
  `(clojure.core/with-redefs ~bindings (f#)
     ~@body))

(ns bar (:require foo))

#_{:clj-kondo/ignore [:private-call]}
(foo/my-with-redefs [foo/my-private-fn (constantly :ok)]
                (+ 1 2))

borkdude12:01:57

I don't know why the error isn't gone with the annotation, I think that's a bug. Please file an issue. But you can ignore the warning by writing:

(foo/my-with-redefs [#'foo/my-private-fn (constantly :ok)]
                (+ 1 2))

Giorgio Valoti15:01:55

Yes, the fn was in another namespace

Giorgio Valoti15:01:17

Thanks @borkdude I’ll file an issue asap 🙂

Michaël Salihi13:01:26

Hello guys! I wonder to know what's the best solution to avoid shadowed var in a let destructuring form? Currently I destructuring a JS object which contains key that shadowed clojure.core/key:

(map #(j/let [^:js {:keys [x y height width color data key]} %
              ...]

Michaël Salihi13:01:25

Of course, I can do something like:

(map #(j/let [^:js {:keys [x y height width color data] :as bar} %
              current-key (:key bar)
              ...]

borkdude13:01:25

@admin055 You can avoid it with explicit named keys destructuring:

{my-other-key :key
:keys [x y z]
}

borkdude13:01:22

but your method of course works too

Michaël Salihi13:01:02

Perfect, I forgot the syntax, this is what I was trying to do. Thanks @borkdude!

👍 1
serioga15:01:39

btw, Clojure Extras does not lint my code with built-in clj-kondo anymore. It was installed from the file firstly (and worked), then disabled (because too annoying), then enabled after installing from marketplace (and upgraded twice) — and it does not lint anymore. Removed then installed again — no changes. simple_smile

brcosta16:01:02

Hi, would you mind opening an issue here? https://github.com/brcosta/clj-extras-plugin. It’d help if you can add the versions (intellij, cursive, extras) so that I can also test it here). Thanks 🙂

borkdude15:01:16

@serioga please report in #clj-extras-plugin

👍 1
borkdude15:01:22

and maybe tag @brcosta there

Karol Wójcik23:01:18

Got a very bizzare issue cc @borkdude. Here is a minimal reproduction. 1. Define file core.clj

(require '[malli.core])
(require '[malli.experimental])
(require '[potemkin :as pot])

(pot/import-vars [malli.core [form schema =>]
                  malli.experimental [defn]])
2. Run.
clj-kondo --lint core.clj
3. Result:
core.clj:6:1: warning: redefined var #'user/
linting took 7ms, errors: 0, warnings: 1
clj-kondo v2022.01.15

1
borkdude09:01:39

I will take a look

borkdude09:01:19

This works for me:

(ns foo (:refer-clojure :exclude [defn]))

(require '[malli.core])
(require '[malli.experimental])
(require '[potemkin :as pot])

(pot/import-vars [malli.core form schema =>]
                 [malli.experimental defn])

borkdude09:01:47

you shouldn't nest the imported vars in a separate vector I think

borkdude09:01:58

nonetheless, the error message could be better here, feel free to post an issue about this

Karol Wójcik11:01:17

Thank you for correcting me! My bad! 🙂