This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-19
Channels
- # announcements (5)
- # asami (7)
- # aws (10)
- # babashka (10)
- # beginners (49)
- # calva (12)
- # cider (5)
- # circleci (1)
- # clj-kondo (25)
- # clj-yaml (14)
- # clojars (5)
- # clojure (134)
- # clojure-europe (142)
- # clojure-france (3)
- # clojure-nl (1)
- # clojure-norway (4)
- # clojurescript (10)
- # cursive (8)
- # datomic (19)
- # emacs (11)
- # fulcro (8)
- # graalvm (29)
- # honeysql (7)
- # jobs (4)
- # jobs-discuss (9)
- # lsp (196)
- # obb (4)
- # off-topic (40)
- # pathom (4)
- # releases (4)
- # remote-jobs (3)
- # shadow-cljs (16)
- # sql (25)
- # squint (2)
- # tools-deps (12)
- # xtdb (7)
- # yada (4)
This is great, and I’m not saying this just because I was one of the people who requested this. The not-so-great part is that this is one of those “why did I miss this obvious bug” things 😅
@U8SFC8HLP I don't even ask that question anymore! Just glad that clj-kondo, my ever-patient review buddy, helps me out. Thanks for requesting this feature.
When I have a line like this
(js/console.log "foo")
I get the following warning
Unresolved var: js/console.log
Is there any way to configure clj-kondo to handle these cases?
I'm also curious if this syntax has a name that I would be able to google for.The js
namespace is only provided by ClojureScript. So you need to either use a *.cljs
file or use a`*.cljc` file with a cljs reader conditional.
;; if cljc file
(js/console.log "foo") ;; unresolved
#?(:cljs (js/console.log "foo")) ;; => "foo"
If I understand you correctly I don't think the js
namespace is my problem. I am in a cljs file and the following lints fine
(.log js/console "foo")
I haven't changed my .clj-kondo/config.edn very much except to add a few :list-as
rules, so I'm not sure what I might have mis-configured for this to lint properly
(js/console.log "foo")
(.log js/console "foo")
and (js/console.log "foo")
should both be fine. You'll probably need to provide more info for help.
(js/console.log "foo")
is fine with clj-kondo, I do that all the time, but not when you're in a .clj
or .cljc
file
@U03NXD9TGBD If you can post a repro with your problem (a full complete .cljwhatever
file) then I'll be able to take a look. This shouldn't happen in .cljs
file
Sorry it took me a while to get back to you! I've been using clj-kondo only from vscode/vim so I wanted to make sure I installed the latest version and ran it directly. TLDR: I deleted .clj-kondo/.cache in my project and it seems to be working now? I don't get a warning for something like
(js/not.a.fn "foo)
but I could see how that might make sense. Is this the desired behaviour? Other symbols do give the warning, such as (foo 'bar)
I installed on Ubuntu via the installation script https://github.com/clj-kondo/clj-kondo/blob/master/doc/install.md#installation-script-macos-and-linux
Then I created a file src/test.cljs
(ns test)$ clj-kondo --lint src/test.cljs
src/test.cljs:3:2: warning: Unresolved var: js/console.log
linting took 9ms, errors: 0, warnings: 1
(js/console.log "foo")
Running the linter produced the warning
$ clj-kondo --lint src/test.cljs
src/test.cljs:3:2: warning: Unresolved var: js/console.log
linting took 9ms, errors: 0, warnings: 1
However, if I ran the same command outside of my project it did not produce the warning. This led me to believe it was a problem with my project, so I cleared the cache. Sorry I didn't have the foresight to save the cache before I deleted so I guess there is no way to debug now... :face_palm:I’m seeing this too, with or without cache
(ns main
#?(:cljs (:require [cljs.nodejs :as node])))
(def ^:dynamic *env*
#?(:clj (System/getenv)
:cljs (if (= *target* "nodejs")
(into {} (map #(vector % (aget node/process.env %)) (.keys js/Object node/process.env)))
{})))
(defn env-var [name]
(get *env* name))
(defn -main []
(println (env-var "USER")))
clj-kondo --lint main.cljc
main.cljc:7:45: warning: Unresolved var: node/process.env
code compiles/runs fine though
@U03AU2X8TD5 This is a different issue. In a .cljc file clj-kondo also lints the file as if it's a clj file. And in clj you can't write node/process.env
indeed
> Try (.-env node/process)
yes. that works.. I was just saying that I too have had problems with the construct reported above
cool, I’ll file one before bedtime then 🙂
Wrote my first hook today! Debugged it via the REPL per the docs. Thank you @borkdude for a great, extensible tool (and great docs!)
