Fork me on GitHub

I'm using clj-kondo 2022.01.15 (with the latest Calva version), and it's treating clojure.core/alias as undefined. Is that a known issue? [Update: not a Kondo issue, I just didn't understand the behavior I should expect in a .cljc file. Thanks @borkdude!]


@U02STT6CVK5 Need more info. Can't repro using a simple example locally here.


Are you in a .cljc file?


@borkdude: I was, actually. I get the same result in a .cljs file. But I see that trying it in a .clj file works.


Yes, the issue is that alias is not defined in ClojureScript. So in a .cljc branch you'll have to put that code in a reader conditional.


Ah, that makes sense! Thank you!


This open issue is related:, maybe someday I’ll find time to work on it! simple_smile


Feel free to upvote the issue for higher priority. :)

Noah Bogart19:01:03

Is it possible to have a linter check if a given required namespace exists and warn if it doesn’t?


@nbtheduke That isn't yet available. Could be done though.

👍 1

There is one caveat: clj-kondo works and has always worked with partially linted projects

Noah Bogart19:01:32

what do you mean by “partially linted projects”?


That you're not required to lint your project + deps to have good feedback or false positives due to not doing that


So if there is a namespace not available in the cache, then clj-kondo just assumes you haven't linted that one yet, it can't see the difference between: it doesn't exist or it might exist maybe in the future, but I haven't seen it yet

👍 1
💯 1

Perhaps it's better if clojure-lsp did this linter, because clojure-lsp does require you to index the whole project. Similar to why :clojure-lsp/unused-public-var is implemented by lsp and not by clj-kondo out of the box


Or clj-kondo should have something in its cache that signals that clj-kondo --lint $classpath --dependencies has linted the entire project


and then it could with more certainty say: this ns doesn't exist


Maybe we could write such a file when you lint using --dependencies and after that activate this project-wide linter


There is one more edge case I could come up with, is when you rename namespaces, then clj-kondo might still think the old name still exists since there's that file lingering in the cache


but that might be better than nothing


ok, let's do it. I'll make an issue about it

Noah Bogart19:01:22

It’s interesting how the classpath makes this more challenging than, say, a node project where it’s as “simple” as searching first the local files and then node_modules for a given filepath


well, when you've linted your entire project, the linter is easy. it's just that you shouldn't emit warnings when you haven't.


clj-kondo has a file for each namespace in its cache


also partitioned by clj, cljs and cljc


When you lint a file, like (ns foo (:require [clojure.set])) then clj-kondo will read the file .cache/v1/clj/clojure/set.transit.json into memory


so when there is (:require [clojure.setx]) (typo), there should be no file and then it's a warning

Noah Bogart19:01:35

huh yeah, that makes sense

Noah Bogart19:01:17

so it’s a… two step process? or multi-step at least. first pass is “add a file to the cache for each file in the class path”, and then the second pass allows for referencing and filling those files?


every time clj-kondo lints a file, it writes the result of analyzing that file to the cache


so if you start with an empty cache and just start editing your project, the linting gets increasingly more informed.

Noah Bogart19:01:52

which is why it doesn’t attempt to do this kind of linting yet, if you lint a single file it won’t have any other files available in the cache. okay, that makes more sense

Noah Bogart19:01:01

thanks for explaining