While working on the tests for https://github.com/clojure-lsp/clojure-lsp/issues/1237 (lsp-organize-imports removes clj-kondo ignore) I noticed that namespace prefix lists (uses () in :require) aren't organized quite correctly. I looked at the code and have some ideas, but the only time I'e ever seen prefix lists was when I was going through the docs for the ns macro. Is this even worth thinking about? Admittedly, I'm a newbie so I might not know what I'm talking about. 🙂 More in the thread.
Specifically:
(ns game.state
(:require
(clojure [set :as set ]
[edn :as edn])
(clojure.java [io :as io])))
edn/read
set/join
here is unused. But it won't be removed if I use lsp-organize-imports. This is because the code has a list of unused namespaces (only http://clojure.java.io) and matches against the first thing in the prefix list (clojure.java).
Of course, this works perfectly when using a vector libspec, so this http://clojure.java.io is removed for this case:
(ns game.state
(:require
[clojure.set :as set]
[ :as io]
[clojure.edn :as edn]))
The code fix does complicate things a little bit, so it's not completely free.
Are these prefix lists used often enough that I should file a separate github issue to fix when unused namespaces aren't removed?If folks follow Sierra's guidelines: https://stuartsierra.com/2016/clojure-how-to-ns.html#prefix-lists
Never use prefix lists in :require. Write out the full name of each namespace. Because namespaces have no hierarchical relationship, and it makes searching easier.
I agree with Sandra here -- I think prefix lists in :require are horrible and I would turn on a linter that flagged them as bad style (heh, so now I need to go read clj-kondo's docs to see if that's available!).
That explains why I haven't seen them before. I guess you'd lean to not bothering with this?
I wouldn't bother trying to fix it. I'd rather see PR effort go to https://github.com/clj-kondo/clj-kondo/issues/1137
(closed due to lack of activity, unfortunately)
Got it. Kondo is out if my depth right now. But I'll keep #1137 in the back of my mind for when I delve in.