What do people think of a clj-kondo linter that warns on aliased keyword usage? e.g.
(ns blah.blah (:require [foo.bar :as bar]))
::bar/baz ;; <- WARNING: aliased keyword
:foo.bar/baz ;; <-- ok
i.e. to encourage find/replaceable keywords@rickmoynihan @snoe and @ericdallo and currently working on adding keyword analysis output (for LSP) but this would also allow you to get all aliased keywords (and write a tool that spits out warnings). But it can also included in clj-kondo pretty easily and by default turned off.
cool… so clj-kondo currently doesn’t preserve that sort of data or have keyword analysis, that would make this linter easy?
yes, the information is there, there is just not such a linter right now
cool
Similarly I was thinking of another for integrant keys, that ensures the keys are compatible with ig/load-namespaces
e.g.
(ns foo.bar (:require [integrant.core :as ig]))
(defmethod ig/init-key :wibble/wobble ;; <-- WARNING: integrant key does not match the namespace defining ig/init-key not discoverable by ig/load-namespaces
[_ opts] ,,,)
(defmethod ig/init-key :foo.bar/baz ;; ok
[_ opts] ,,,)
(defmethod ig/init-key :foo/bar ;; ok
[_ opts] ,,,)
what would make wibble/wobble not compatible?
the defmethod would need to be put in a namespace wibble.wobble
or wibble
(single segment namespaces aside)
essentially ig/load-namespaces
uses the key names specified in the integrant config to load the set of configured keys / namespaces. So it infers the namespace from the keywords name
ah right
I wonder if you could do this with a hook. I think you could but the namespace is currently not passed to the hook function. Can be added though.
How is ig/init-key :foo/bar
ok here though?
shouldn't this be :foo.bar/something
?
no its ok because there are two rules for matching… I forget exactly but something like:
1. if you have the key :foo/bar
try first to load the namespace foo.bar
2. if that fails try the namespace foo
(and expect to find the ig/init-key :foo/bar
in it)
i.e. sometimes a namespaced keyword might fully identify a namespace (and a single component). Other times a namespace might contain many components; either is fine.
my example is perhaps a bit confusing because I combined all the examples in a single ns. See here for the official docs: https://github.com/weavejester/integrant#loading-namespaces
Feel free to post issues about both your ideas
Thanks, will do :thumbsup: just wanted to check they seemed feasible
I think there's a linter that warns for inconssistent aliasing
Not sure if it cover keywords
But if it did, you could use that to still make it easy to find/replace, and still let people use aliases
Basically, it forces the alias to be consistent across the board. So you know that you just need to find/replace that one alias.