clj-kondo

https://github.com/clj-kondo/clj-kondo
eskos 2020-06-09T09:40:08.373600Z

I was reading this https://clojuredocs.org/clojure.core/keyword#example-542692d3c026201cdc326fde and had a thought to test this out, and seems clj-kondo doesn’t warn about these non-conformant keywords. Should it/could it?

borkdude 2020-06-09T09:42:34.374100Z

@suomi.esko can you give a concrete example that doesn't require me to read this entire page?

eskos 2020-06-09T10:12:53.374200Z

Hmm, the anchor link doesn’t work for you? There’s a list of non-conformant keywords, eg. (keyword "abc def") (keyword "") (keyword "...") and one I’ve actually seen in production, (keyword ":a")

borkdude 2020-06-09T10:14:25.374400Z

the link works, but I don't have time to read all this, so if you can condense your question that would be helpful. clj-kondo can check those kinds of things, but in general the argument to keyword are runtime values, not literal strings - this is something which clj-kondo cannot check

eskos 2020-06-09T10:27:46.374600Z

That’s the could/should part. I’m not really sure why Clojure hasn’t natively spec’d that part, since it’s quite easy to make all kinds of mangled garble with the keyword function.

borkdude 2020-06-09T10:29:42.374800Z

this topic has come up often in the #clojure channel. I think one of the problems with narrowing down the possible keys is that it would break existing code which clojure will never do

borkdude 2020-06-09T10:30:16.375Z

you can always write your own my-keyword function that checks things. one other reason is performance. creating keywords should be very fast in clojure. additional checks will mean a performance penalty

dominicm 2020-06-09T10:48:21.375200Z

In the future these things will maybe be made valid too

borkdude 2020-06-09T10:49:29.375400Z

@dominicm in which context do you mean valid? is anything invalid right now?

dominicm 2020-06-09T10:50:19.375600Z

Well, :1 isn't valid right now, but it works in some places

dominicm 2020-06-09T10:51:21.375800Z

I guess what I really mean is that Alex has hinted that (keyword "foo bar") will eventually print in such a way that it can be (read-string)

borkdude 2020-06-09T10:52:25.376100Z

interesting, I wonder how they're going to do that

dominicm 2020-06-09T10:52:59.376300Z

It was hinted that the syntax would be something like :|foo bar|

dominicm 2020-06-09T10:53:07.376500Z

and | would ergo be the only restricted character.

borkdude 2020-06-09T10:54:07.376700Z

:"foo" could also work

dominicm 2020-06-09T10:54:31.376900Z

Yeah, I recall the pipe character being mentioned explicitly

borkdude 2020-06-09T10:55:27.377500Z

so tl;dr: clj-kondo isn't going to do anything about this 🙂

dominicm 2020-06-09T10:57:00.378Z

I think this was the conversation

dominicm 2020-06-09T11:01:36.378200Z

Nope, a separate one 😁

dominicm 2020-06-09T11:06:07.379Z

I'm bored of searching now, I swear there was a | syntax though

dominicm 2020-06-09T11:06:14.379200Z

maybe specifically for symbols? Dunno

dominicm 2020-06-09T11:08:01.379700Z

symbols was the key term

dominicm 2020-06-09T11:13:59.379900Z

@borkdude fwiw, I think the specific typo of (keyword ":ANYTHING") might be worth catching

dominicm 2020-06-09T11:14:06.380100Z

(having reflected on it for all of 30s)

dominicm 2020-06-09T11:14:23.380300Z

Nothing broad, just catching the silly mistake of putting : when using the function

borkdude 2020-06-09T11:14:47.380500Z

wouldn't that also be valid in the future with :|:foo|?

dominicm 2020-06-09T13:36:25.380700Z

Yeah, I suppose it would :)

eskos 2020-06-09T14:07:32.380900Z

I’m willing to bet that pipe surrounded form will break backwards compatibility even worse though… 🙂

dominicm 2020-06-09T14:08:06.381100Z

I doubt it. Besides, anyone relying on that is relying on something that was never promised.

borkdude 2020-06-09T14:09:32.381300Z

I think the Clojure on DotNet has special syntax which uses this. It will break them