Fork me on GitHub
#clj-kondo
<
2022-09-19
>
lread14:09:55

Oh… being the king of typos, I should really try this one out!

eskos11:09:24

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 😅

lread12:09:28

@U8SFC8HLP I don't even ask that question anymore! simple_smile Just glad that clj-kondo, my ever-patient review buddy, helps me out. Thanks for requesting this feature.

seepel22:09:12

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.

skylize02:09:14

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"

seepel02:09:50

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")

skylize02:09:35

(.log js/console "foo") and (js/console.log "foo") should both be fine. You'll probably need to provide more info for help.

borkdude06:09:07

(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

borkdude07:09:14

@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

seepel02:09:38

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:

Anders Eknert20:09:32

I’m seeing this too, with or without cache

Anders Eknert20:09:36

(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")))

Anders Eknert20:09:51

clj-kondo --lint main.cljc
main.cljc:7:45: warning: Unresolved var: node/process.env

Anders Eknert20:09:06

code compiles/runs fine though

borkdude21:09:56

@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

borkdude21:09:21

ah wait, this is in a :cljs branch

borkdude21:09:47

Try (.-env node/process)

borkdude21:09:15

Btw, in Node you can also just write it like:

js/process.env

👍 1
borkdude21:09:41

but this seems like a genuine bug, so issue welcome

Anders Eknert21:09:43

> Try (.-env node/process) yes. that works.. I was just saying that I too have had problems with the construct reported above

Anders Eknert21:09:23

cool, I’ll file one before bedtime then 🙂

seancorfield22:09:32

Wrote my first hook today! Debugged it via the REPL per the docs. Thank you @borkdude for a great, extensible tool (and great docs!) gratitude

🎉 5
clj-kondo 2
borkdude08:09:14

Thanks for sharing, it's always nice to get feedback like this