cursive

borkdude 2025-12-17T13:56:34.917419Z

can someone check if cursive complains about this:

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

(defn def [])
when you remove :exclude [def]? Basically :exclude [def] is a no-op since def is a special form and can't be overridden in call sites

imre 2025-12-17T14:03:55.606629Z

I'm not seeing any error reported at defn def with or without the exclusion

borkdude 2025-12-17T14:04:36.414439Z

good to know

imre 2025-12-17T14:22:44.697109Z

@cfleming fyi

borkdude 2025-12-17T14:39:20.493419Z

to be clear: it shouldn't warn, so the status quo is good

imre 2025-12-17T15:12:05.804239Z

I might be missing something. If def can't be overwritten, then I'd consider the code above worthy of a warning

imre 2025-12-17T15:14:26.680469Z

As in "hey, this code doesn't do what you might expect it to do"

borkdude 2025-12-17T15:19:35.101259Z

that's what I'm going to do in clj-kondo now, but without the exclude it shouldn't warn that def is overwritten

imre 2025-12-17T15:21:07.681049Z

without the exclude it shouldn't warn - but you won't ever be able to call the def function no? - without an explicit namespace prefix, I suppose

borkdude 2025-12-17T15:21:39.978109Z

true. one example of this is clojure.spec.alpha/def

imre 2025-12-17T15:22:50.867309Z

defining a function/macro called def IMO isn't great practice and I'd surely flag that in a code review

borkdude 2025-12-17T15:23:09.791119Z

ok, make a JIRA I guess? ;)

imre 2025-12-17T15:24:03.298899Z

I suppose this could apply to all names "shadowing" any special form

imre 2025-12-17T15:25:58.333199Z

lo and behold https://github.com/clj-kondo/clj-kondo/issues/639

borkdude 2025-12-17T15:28:26.020379Z

that's a somewhat different but related issue

imre 2025-12-17T15:29:03.062239Z

description says "We should also warn on using special form names as var names"

borkdude 2025-12-17T15:29:14.838869Z

also, it already works so it seems I can close the issue.

borkdude 2025-12-17T15:29:42.030539Z

yeah we could warn on that

imre 2025-12-17T15:30:07.043549Z

let me record a new one specific to this conversation and link to this

borkdude 2025-12-17T15:30:36.150019Z

what are you going to record?

borkdude 2025-12-17T15:30:59.403979Z

I'm asking to prevent creating a duplicate one ;)

imre 2025-12-17T15:31:19.305559Z

makes sense

imre 2025-12-17T15:32:14.508949Z

I'll just add a comment then, saying that it would be lovely to have a warning every time a special form is "attempted to be shadowed" - not just var names, locals too

borkdude 2025-12-17T15:32:56.349679Z

ok, I think I'll close this issue so you can make a new one

imre 2025-12-17T15:33:06.667379Z

🙂

borkdude 2025-12-17T15:33:08.557739Z

not sure if I have a test for this

borkdude 2025-12-17T15:33:11.827109Z

let me check

borkdude 2025-12-17T15:34:49.171619Z

I found this one:

(deftest special-form-test
  (is (empty?
       (lint! "(defn new [] :foo)
               (new js/Date 2022 1 1 1 1)"
              "--lang" "cljs"))))

borkdude 2025-12-17T15:41:20.362999Z

ok, I added another test for 639

borkdude 2025-12-17T15:41:24.909709Z

and closed it

imre 2025-12-17T15:42:02.073609Z

(apologies for hijacking the thread)

borkdude 2025-12-17T15:43:43.502299Z

We do have :shadowed-var btw, but I never use it myself. It already warns for special forms it seems:

$ clj -M:clj-kondo/dev --config '{:linters {:shadowed-var {:level :warning}}}' --lint - <<< "(let [var 1] var)"
<stdin>:1:7: warning: Shadowed var: clojure.core/var
linting took 32ms, errors: 0, warnings: 1

borkdude 2025-12-17T15:43:56.327069Z

In the linted example here, you don't call the special form

imre 2025-12-17T15:44:42.018739Z

good to know there's support

borkdude 2025-12-17T15:45:04.220039Z

maybe good to mention it in the issue

👍 1
imre 2025-12-17T15:45:19.179299Z

although I'd say special forms are a bit more special in this case

imre 2025-12-17T15:45:30.106739Z

because shadowing them will not really work

borkdude 2025-12-17T15:46:01.128239Z

shadowing will work, as long as you don't call them, but just reference them as values

imre 2025-12-17T15:47:43.682779Z

that's the not >really< part I guess 🙂

imre 2025-12-17T15:48:07.766219Z

anyway, I don't want to waste your time 🙂

imre 2025-12-17T15:49:21.807609Z

the failure modes are somewhat different between shadowing special forms and vars

imre 2025-12-17T15:53:39.622349Z

added this to the issue, feel free to close if considered covered by shadowed-var