This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-09
Channels
- # announcements (2)
- # babashka (11)
- # beginners (9)
- # biff (7)
- # calva (20)
- # catalyst (1)
- # cider (8)
- # clerk (46)
- # clj-kondo (18)
- # clj-otel (2)
- # clojure-brasil (22)
- # clojure-europe (18)
- # clojure-gamedev (23)
- # clojure-italy (5)
- # clojure-nl (2)
- # clojure-norway (14)
- # clojure-uk (6)
- # clr (1)
- # datomic (13)
- # emacs (1)
- # hoplon (13)
- # hyperfiddle (53)
- # introduce-yourself (1)
- # java (23)
- # malli (7)
- # obb (35)
- # off-topic (31)
- # polylith (2)
- # portal (9)
- # rdf (15)
- # reitit (12)
- # releases (3)
- # ring (4)
- # shadow-cljs (6)
- # solo-full-stack (3)
Here is a proposal for an extension to the :consistent-alias
linter which checks consistency of aliases between multiple files: https://github.com/clj-kondo/clj-kondo/issues/2195
I've previously not implemented this because it would not work in an editor, but for command line usage it's probably still useful, right?
I can see this being useful via clojure-lsp if it could figure out the most common alias used for a given ns and then flag all the other aliases as not matching that.
I would not use this, however, because we have a convention of always using sut
as the alias for the primary ns being tested in our test nses, so it would always flag those as inconsistent.
We tend to use the alias linter almost solely for 3rd party nses.
clojure-lsp already has the data it needs to implement this feature. clj-kondo could do it too but then you'd just get the feature when linting a directory, not via the editor (unless we keep more stuff in the on disk cache, which is kinda complicated)
I do think this is quite useful, but IMO would be nice to have built-in clj-kondo similar to unresolved-var
linter which has context about other ns
If you have 100 uses of a ns and only one is inconsistent, the order you lint the code matters... If you see the inconsistent use first, the other 99 will be flagged; if you see it elsewhere, only that 1 use would be flagged:grin:
AFAIK clj-kondo does that for unresolved-var
lint which reports when you have a unknown function from an alias
sure, I'm willing to think about it but then we get at the "complicated caching" bit, since clj-kondo needs to know about all aliases used in the project for a certain namespace. the process would be like this, when in an editor:
(ns foo (:require [clojure.string :as str]))
store {clojure.string {str {foo}}
or so (not sure which layout is most handy
and then lint the next file in an editor:
(ns bar (:require [clojure.string :as string]))
Add to index
{clojure.string {str #{foo} string #{bar}})
Now we find that there are multiple aliases, so we can show that there is another namespace with a different alias.
But if you remove (:require [clojure.string ])
from foo
how do we update the index? There is not a single layout which is optimal for querying probably.
When you have a server process like with clojure-lsp, it becomes a little easierGot it, how we update the cache for the unresolved-var
case?
indeed doing in clojure-lsp should be easier
.clj-kondo-cache/v1/foo/bar/baz.transit.edn
(there are some indirections in there per clojure dialect, but this is the main idea)I see, I think I or @U04CAPVN1HS can take a look how hard would be to implement as a new custom linter in clojure-lsp
I think the only difficult thing about the on disk cache is: how to efficiently detect removals, e.g. when you change or remove an alias, how would you efficiently update the on disk cache