clj-kondo

https://github.com/clj-kondo/clj-kondo
2021-01-21T08:47:36.002900Z

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

borkdude 2021-01-21T08:50:35.006200Z

@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.

2021-01-21T08:53:35.008700Z

cool… so clj-kondo currently doesn’t preserve that sort of data or have keyword analysis, that would make this linter easy?

borkdude 2021-01-21T08:54:28.009600Z

yes, the information is there, there is just not such a linter right now

2021-01-21T08:55:00.010Z

cool

2021-01-21T08:55:02.010200Z

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] ,,,) 

borkdude 2021-01-21T08:55:48.010500Z

what would make wibble/wobble not compatible?

2021-01-21T08:56:50.011600Z

the defmethod would need to be put in a namespace wibble.wobble or wibble (single segment namespaces aside)

2021-01-21T08:59:15.013100Z

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

borkdude 2021-01-21T09:00:16.013300Z

ah right

borkdude 2021-01-21T09:00:47.013800Z

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.

borkdude 2021-01-21T09:01:23.014100Z

How is ig/init-key :foo/bar ok here though?

borkdude 2021-01-21T09:03:00.016Z

shouldn't this be :foo.bar/something?

2021-01-21T09:05:16.017100Z

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)

2021-01-21T09:06:03.017900Z

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.

2021-01-21T09:07:22.018600Z

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

borkdude 2021-01-21T09:08:11.018900Z

Feel free to post issues about both your ideas

2021-01-21T09:08:44.019300Z

Thanks, will do :thumbsup: just wanted to check they seemed feasible

2021-01-21T21:38:20.020600Z

wOOt WooT!!

2021-01-21T21:40:59.020800Z

I think there's a linter that warns for inconssistent aliasing

2021-01-21T21:41:11.021Z

Not sure if it cover keywords

2021-01-21T21:41:29.021200Z

But if it did, you could use that to still make it easy to find/replace, and still let people use aliases

2021-01-21T21:42:00.021400Z

Basically, it forces the alias to be consistent across the board. So you know that you just need to find/replace that one alias.