Fork me on GitHub
#clj-kondo
<
2023-01-11
>
borkdude18:01:04

I wonder if clj-kondo should report (:require [my-namespace :as-alias mns]) as unused if the alias isn't used anywhere - there is no harm in this unused namespace since it doesn't really load the namespace? The reason I'm bringing this up is because in clerk, the following situation arises:

(:require [nextjournal.clerk.viewer :as-alias v])

'(fn [x] (v/html [:div x]))
The alias isn't really used, but clj-kondo exports analysis about the quoted symbol v/html along with information about what namespace might be targeted with it, so clojure-lsp can navigate to nextjournal.clerk.viewer/html when you navigate to that symbol. The already supported way of doing this is using syntax-quote, but writing functions in syntax-quote isn't always that convenient / nice to read? But from the perspective of clj-kondo, the alias v isn't really used since it only occurs in a quote. Hence you will get an unused namespace warning. 🧵

skylize18:01:19

> there is no harm in this unused namespace since it doesn't really load the namespace? > Wow. Really? So what happens when/if the quoted expression gets evaluated later? Does the namespace get loaded late as part of that evaluation?

borkdude18:01:06

I think the :as-alias is a syntactic sugar for writing:

(alias 'v (create-ns 'nextjournal.clerk.viewer))
which clj-kondo never warned about, so with that reasoning, it might make sense to not warn

borkdude18:01:26

In this case, the quoted expression gets evaluated on the front-end

borkdude18:01:37

in a SCI environment that has these aliases

ericdallo19:01:45

I agree it's unused, but This will make clojure-lsp remove that require when cleaning the ns, making that navigation of the symbol probably not work right?

borkdude19:01:57

I guess people could also use #_:clj-kondo/ignore

borkdude19:01:08

but clojure-lsp still removes the namespace in that case... why, clj-kondo didn't report it?

borkdude19:01:33

oh, no, it removes the #_clj-kondo/ignore

borkdude19:01:34

anyway, that's a different issue I guess

borkdude19:01:54

I'll remove the warning for as-aliased namespace and if desired, I can make an option later to re-enable this

borkdude11:01:55

already done on master

🎉 2
Ben Grabow15:08:45

What's the latest thought on reporting about unused aliases using :as-alias? I use :as-alias a lot and often have leftover aliases after refactoring that I forget to remove.

2
borkdude15:08:05

We don’t have unused alias yet but it’s not that hard to implement

Ben Grabow15:08:56

Is there a place I should write a feature request?

borkdude16:08:09

I'll re-open it

borkdude16:08:18

If nobody votes, it will disappear again eventually

Ben Grabow17:08:06

Done, thank you!