This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-08
Channels
- # announcements (3)
- # babashka (3)
- # beginners (25)
- # calva (12)
- # cider (58)
- # clara (11)
- # clj-kondo (19)
- # cljsrn (2)
- # clojure (84)
- # clojure-austin (1)
- # clojure-europe (5)
- # clojure-nl (4)
- # clojure-spec (23)
- # clojure-uk (53)
- # clojuredesign-podcast (5)
- # clojurescript (24)
- # core-async (57)
- # cursive (16)
- # datomic (39)
- # emacs (1)
- # fulcro (40)
- # funcool (2)
- # graphql (17)
- # jackdaw (31)
- # jobs (2)
- # joker (3)
- # malli (7)
- # off-topic (12)
- # re-frame (9)
- # reagent (2)
- # reitit (1)
- # ring (4)
- # shadow-cljs (170)
- # sql (36)
- # tools-deps (5)
- # xtdb (20)
Hello, I'm having problems with alot of our projects at work when jacking in with cider. After jacking in, when I load a namespace with cider-load-buffer
I sometimes get this clojure.lang.Compiler$CompilerException
in the :compile-syntax-check
phase saying some namespace can't be found. For example namespace 'taoensso.faraday' not found
. I'm sure that this namespace exists on my classpath, because requiring this file manually by evaluating (require 'taoensso.faraday :reload)
works. After loading random files in the project in a order I never remember I eventually can get the initial namespace loaded and can work from there. We do have a lot of dependencies and it might be that somewhere things are messed up. Any idea how to debug this?
@r0man I would be betting that your project is using namespaces without requiring them 🙂 clj-kondo is pretty good at picking up on that.
clj-kondo does report unused namespaces. can you give an example where it doesn't do this where it should?
oh you mean the other way around: you're using the namespace but you haven't required it. yeah
@r0man in the past I've resolved this by writing a script to start a fresh JVM and require every namespace. That usually roots out any failures.
Sorry. Looks like the code is gone. It could be patched up with some clever grep + bash-fu though
depending on lein, clj, boot, you'll have to differ what you do, but something like: while read -r namespace; do clj -e "(require '${namespace})"; done
And then you pipe these together. So
grep -Poh '(?<=^\(ns )[a-z_\.]+$' **/*.clj | while read -r namespace; do clj -e "(require '${namespace})"; done
you have the full list of namespaces from the initial analysis right? So if there's a use of a namespace from that list without an explicit require then it's a lint line.
it could be a custom linter which works on the export if you want to do it like that. but clj-kondo should always be able to work without the initial cache as well, so it's not an option to use that for built-in linting
if kondo doesn't know about any namespaces, then none of them will be on the blacklist, hence they will all be okay.
it only loads namespaces from the cache which have been required by the user. it seems you want to know about all namespaces, even if they aren't required?
I have the same kind of problem with the private var linter. private vars might be validly used in other namespaces (e.g. foo.cljs + foo.cljc), but I can't really check for that while linting only one file. using the cache for this is too slow, because I'd have to scan all the previously linted namespaces as well
we only need to know if clojure.string
exists or not, so the presence of the file is sufficient. The file doesn't need to be parsed necessarily. Alternatively you could spit out a tiny extra file with all the ns' in (assuming loading that doesn't take a long time that is)
if there is no cache yet, how can clj-kondo know about the existence of a namespace? it should be able to work with that
(when (and (file/exists? "cache/clojure.string") (not (required? ana "clojure.string")) (add-lint-error!))
if there's no cache then file/exists?
will not pass, and there will be no false positive.
scenario without cache:
user types (foo/bar)
. clj-kondo doesn't know foo. so no error.
scenario with cache:
user types (foo/bar)
and foo is in the cache. but hasn't been required. now you get an error?
hey guys, thanks for the tips, trying joker then and see if it finds anything suspicious ...
better way to list all namespaces: echo "(require '[clojure.tools.namespace.find :as f]) (run! println (f/find-namespaces (map
when I used joker it was a bit trigger-happy with this stuff. I'd go for the grep/require solution: https://clojurians.slack.com/archives/C0617A8PQ/p1570530047263100?thread_ts=1570529577.260100&cid=C0617A8PQ not very sophisticated.
you might also be able to use the clj-kondo analysis export for this. right now it spits out:
:var-usages [{:filename "<stdin>", :row 1, :col 1, :from user, :to nil, :name foo/bar, :arity 0}]
:to nil = unknown, while the symbol does have a namespaceThis is the output from:
clj-kondo --lint - --config '{:output {:analysis true :format :edn}}' <<< '(foo/bar)'
CIDER 0.23 is out https://metaredux.com/posts/2019/10/08/cider-0-23-lima.html
