This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-31
Channels
- # announcements (1)
- # aws (4)
- # babashka (40)
- # beginners (89)
- # calva (13)
- # cider (3)
- # clj-kondo (36)
- # cljdoc (16)
- # clojure (74)
- # clojure-boston (1)
- # clojure-dev (7)
- # clojure-europe (30)
- # clojure-new-zealand (1)
- # clojure-nl (17)
- # clojure-uk (5)
- # clojurescript (16)
- # core-async (9)
- # cursive (16)
- # datahike (3)
- # datalog (6)
- # datascript (7)
- # datomic (15)
- # emacs (38)
- # events (2)
- # figwheel-main (3)
- # fulcro (6)
- # google-cloud (18)
- # graalvm (6)
- # gratitude (1)
- # honeysql (1)
- # introduce-yourself (1)
- # jobs (1)
- # leiningen (5)
- # lsp (6)
- # malli (11)
- # meander (2)
- # off-topic (4)
- # re-frame (6)
- # reitit (8)
- # releases (2)
- # remote-jobs (3)
- # reveal (4)
- # shadow-cljs (200)
- # sql (8)
- # tools-deps (16)
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.
@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.
This open issue is related: https://github.com/clj-kondo/clj-kondo/issues/1196, maybe someday I’ll find time to work on it!
Is it possible to have a linter check if a given required namespace exists and warn if it doesn’t?
There is one caveat: clj-kondo works and has always worked with partially linted projects
want me to open a new github issue about it? i see https://github.com/clj-kondo/clj-kondo/issues/842 and https://github.com/clj-kondo/clj-kondo/issues/1240 and https://github.com/clj-kondo/clj-kondo/issues/1460 are all about namespaces and filenames
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
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
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
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.
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
huh yeah, that makes sense
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.
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
thanks for explaining