This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-14
Channels
- # announcements (2)
- # babashka (54)
- # beginners (53)
- # biff (15)
- # catalyst (2)
- # cider (5)
- # clerk (17)
- # clj-kondo (36)
- # clj-otel (3)
- # clojure (52)
- # clojure-argentina (1)
- # clojure-brasil (1)
- # clojure-europe (35)
- # clojure-losangeles (2)
- # clojure-nl (3)
- # clojure-norway (20)
- # clojure-uk (5)
- # clojurescript (24)
- # cursive (10)
- # datahike (9)
- # datomic (15)
- # defnpodcast (8)
- # events (6)
- # funcool (2)
- # hyperfiddle (21)
- # jobs (1)
- # lsp (19)
- # malli (4)
- # matrix (1)
- # off-topic (25)
- # podcasts-discuss (1)
- # portal (13)
- # releases (1)
- # shadow-cljs (25)
- # solo-full-stack (16)
- # squint (27)
- # tools-deps (6)
- # tree-sitter (4)
Is it possible to use hooks to tell clj-kondo
that a namespace is used? For hysterical raisins, we have some ancient code with circular dependencies which are extremely complicated to unwind. I'd like to unwind as much as I can, but the way these circular dependencies were added currently defeats clj-kondo
's analysis, which makes finding unused code with carve
harder.
Back in the mists of time a macro was added to our codebase that implements a lazy definition of a function in another namespace: (declare-fn other.namespace/function)
This macro will create the namespace if necessary, and define a function which on first invocation require
s the namespace if necessary, resolves the function's symbol in that namespace, and then invokes the real function.
What I'm looking to do is to teach clj-kondo
's analyser that the namespace passed to declare-fn
should be considered as require
d
My first attempt was to use a hook to rewrite (declare-fn other.namespace/function)
into (require '[other.namespace :refer [function])
, but that doesn't seem to impact namespace analysis.
Is what I'm looking to do possible?
Thanks again for the suite of super-useful tooling, I use carve
and clj-kondo
every day.
There's no easy way to do this, but if you add the namespaces to {:linters {:unresolved-namespace {:exclude [...]}}}
then clj-kondo will assume that those are loaded by you
No bother, I'm sure this is a very niche use-case, most folks don't go to these lengths to add circular dependencies to their codebases 🙂
I'm very curious; why was the circular dependence deemed necessary? (Maybe you don't know 😄 )
The honest answer is "poorly structured code". It was allowed to last long enough that it's deeply entrenched.
It happens. You're busy building, and don't realize that the foundation is being eroded.
I have some of this in clj-kondo. The analyzer.clj namespace is huge so I wanted to chop it into a few subparts, but those sub parts also need functions from analyzer.clj
What I did is create a analyzer/common.clj namespace and put a bunch of atoms in there in which I set the functions which I then use from the sub-namespaces
Heh, that's funny that you're actively preventing your own tool from working on itself.
Ah 😅 well, doesn't it also prevent some analysis that clj-kondo could otherwise have done? Of function usage and such.
yes, but a man's gotta do what a man's gotta do when you want to prevent cyclic dependencies and still split things up
Sure sure, whatever makes sense in a context. The notion just made me smile 😊
these are those things: https://github.com/clj-kondo/clj-kondo/blob/master/src/clj_kondo/impl/analyzer/common.clj I still get arity warnings and I only use them from a limited number of places, so it's ok-ish
Also, you're the boss, so that helps
I can't seem to get clj-kondo to copy the config for helix into a new project.
;; shadow-cljs.edn
{:source-paths ["src"]
:dependencies [[lilactown/helix "0.1.10"]
[binaryage/devtools "1.0.7"]]}
output of copy config command:
$ clj-kondo --lint "$(shadow-cljs classpath)" --dependencies --parallel --copy-configs
shadow-cljs - config: /Users/lilactown/Code/helix-fundamentals/shadow-cljs.edn
No configs copied.
you have to create one yourself, this is clj-kondo's way of giving it permission to write to a local folder
$ mkdir .clj-kondo
$ clj-kondo --lint "$(shadow-cljs classpath)" --dependencies --parallel --copy-configs
shadow-cljs - config: /Users/lilactown/Code/helix-fundamentals/shadow-cljs.edn
Configs copied:
- .clj-kondo/lilactown/helix
🎉> To detect lint errors across namespaces in your project, a cache is needed. To let clj-kondo know where to create one, make a .clj-kondo
directory in the root of your project, meaning on the same level as your project.clj
, deps.edn
or build.boot
.
missed it in my skimming then 🙂