clj-kondo

https://github.com/clj-kondo/clj-kondo
Aleksander Rendtslev 2020-12-09T09:56:57.076Z

Sweet! Just while I was looking for it. I was about to try to write it out, but I'm still pretty new to clojure. So i was scratching my head a little on this one (the rum hook does look like a good place to start though)

borkdude 2020-12-09T09:57:40.076300Z

Let me know if you need any help or have any questions

borkdude 2020-12-09T09:57:59.076500Z

The docs for hooks are here: https://github.com/borkdude/clj-kondo/blob/master/doc/hooks.md

seancorfield 2020-12-09T20:19:51.081600Z

@borkdude Just spotted this in the analysis of deps.edn:

#:worldsingles{worldsingles-test
                  #:local{:root "../worldsingles-test"}}
and clj-kondo flags worldsingles-test as being an unqualified lib name (which it isn't). I guess clj-kondo isn't reading namespaced-maps correctly?

borkdude 2020-12-09T20:20:17.081800Z

crap. I just pushed the button for release ;)

seancorfield 2020-12-09T20:20:39.082300Z

And it actually recommends changing the above to this, which is definitely wrong:

{worldsingles-test {:local/root "../worldsingles-test"}}/{worldsingles-test {:local/root "../worldsingles-test"}}

borkdude 2020-12-09T20:21:03.082700Z

@lee ^ interesting issue with namespaced maps in rewrite-clj wrt analysis..

borkdude 2020-12-09T20:21:29.083200Z

yes, that's because it doesn't look at a namespaced map like it should.

borkdude 2020-12-09T20:21:33.083400Z

issue welcome

borkdude 2020-12-09T20:21:45.083700Z

I'll fix it in the next release, I just hit the release button

lread 2020-12-09T20:25:59.085600Z

Interesting, thanks for the ping! I should have a look at how clj-kondo is using rewrite-clj here and make sure we are properly covered for rewrite-cljc.

borkdude 2020-12-09T20:26:34.086200Z

It could in fact be a bug in my own fork of rewrite-clj now I think about it. I'll hold off on releasing clj-kondo for today and take a look.

lread 2020-12-09T20:27:54.087700Z

In any case, I’m interested to learn more. I’ll be lurking! :simple_smile:

borkdude 2020-12-09T20:28:13.088100Z

I'm calling sexpr on those nodes... and probably my version of sexpr for this thing doesn't work correctly... https://github.com/borkdude/clj-kondo/blob/master/src/clj_kondo/impl/linters/deps_edn.clj

borkdude 2020-12-09T20:29:33.088500Z

hmm, it does appear to work:

user=> (n/sexpr (p/parse-string "#:foo{:a 1}"))
#:foo{:a 1}

borkdude 2020-12-09T20:29:42.088800Z

Then maybe the bug is in the deps_edn.clj code itself.

lread 2020-12-09T20:31:10.089700Z

yeah, namespaced element support is weak in rewrite-clj but my notes say that particular case is covered.

borkdude 2020-12-09T20:32:00.090Z

Hmm, this looks wrong:

user=> (n/sexpr (p/parse-string "#:worldsingles{worldsingles-test #:local{:root \"../worldsingles-test\"}}"))
{worldsingles-test #:local{:root "../worldsingles-test"}}

borkdude 2020-12-09T20:33:46.090500Z

It appears to go wrong when the map has symbols:

user=> (n/sexpr (p/parse-string "#:foo{x 1}"))
{x 1}

borkdude 2020-12-09T20:35:31.091100Z

I have never seen this case before. TIL.

lread 2020-12-09T20:35:38.091200Z

But symbols shouldn’t be namespaced, only keywords, right?

borkdude 2020-12-09T20:36:20.091400Z

user=> (keys (edn/read-string "#:foo{x 1}"))
(foo/x)

lread 2020-12-09T20:36:47.091700Z

hmmm

borkdude 2020-12-09T20:36:47.091800Z

otoh:

user=> (keys (edn/read-string "#:foo{\"x\" 1}"))
("x")

borkdude 2020-12-09T20:37:44.092600Z

@lee does rewrite-cljc do this correctly?

lread 2020-12-09T20:39:20.093Z

So I’m looking at my handy reference https://clojure.atlassian.net/browse/CLJ-1910

borkdude 2020-12-09T20:40:13.093200Z

> A keyword or symbol key without a namespace is read with the default namespace as its namespace.

lread 2020-12-09T20:41:13.094100Z

hmm… I think I missed that “symbol key” detail…

lread 2020-12-09T20:42:21.094800Z

so no, rewrite-cljc namespaced element support WIP does not handle this correctly yet!

borkdude 2020-12-09T20:42:52.095200Z

In clj-kondo this is a small fix:

user=> (keys (n/sexpr (p/parse-string "#:foo{x 1}")))
(foo/x)

borkdude 2020-12-09T20:43:32.095900Z

modified   parser/clj_kondo/impl/rewrite_clj/node/seq.clj
@@ -56,9 +56,11 @@
           m (first (node/sexprs children))
           nspace (name nspace-k)]
       (->> (for [[k v] m
-                 :let [k' (cond (not (keyword? k)) k
+                 :let [k' (cond (not (ident? k)) k
                                 (namespace k)      k
-                                :else (keyword nspace (name k)))]]
+                                :else (if (keyword? k)
+                                        (keyword nspace (name k))
+                                        (symbol nspace (name k))))]]

lread 2020-12-09T20:43:33.096Z

oh foo! :simple_smile: …but am happy to realize this fact!

lread 2020-12-09T20:45:46.097400Z

CLJ-1910 does deliver the gritty details, it just needs to be absorbed.

borkdude 2020-12-09T22:30:51.097900Z

@seancorfield Pushed a fix for https://github.com/borkdude/clj-kondo/issues/1093 to master. Re-scheduled the release for coming weekend.

seancorfield 2020-12-09T22:38:24.098300Z

Nice! Thank you, sir!