Fork me on GitHub
#clj-kondo
<
2023-01-29
>
Clojuri0an13:01:49

The following code seems to be checked by flycheck incorrectly

Clojuri0an13:01:18

(ns 
  (:require [mithril :as m]))

(def my-pictures #js {:view (
                      fn [] (m "div" #js {:class "container"}
                               (m "article" (
                                             (m "h1" #js {:role "button"} "my name")
                                             (m "h2" "My Pictures")))))})

borkdude13:01:01

Hmm, looks like a bug indeed

borkdude13:01:45

Use this:

(:require ["mithril" :as m])

borkdude13:01:00

JS libraries are indicated with a string lib name

borkdude13:01:23

This is merely a convention, but helpful to let clj-kondo know this is a JS library and you can use the namespace name as a function

borkdude13:01:36

And this convention is also enforced by shadow-cljs

Clojuri0an13:01:45

ty, I checked and added it. Oddly, it still has the issue. The following with the same structure does not produce the error

Clojuri0an13:01:59

(def my-pictures #js {:view (fn []
                                (m "div" #js {:class "container"}
                                   (m "article" 
                                      (m "h1" #js {:role "button"} "my name")
                                      (m "h2" "My Pictures"))))}))

Clojuri0an13:01:56

Figured it out

Clojuri0an13:01:02

There was an extra paren there

Clojuri0an13:01:15

Should be fixed

Clojuri0an13:01:32

error unresolved symbol m at line 12 (m h1)

Clojuri0an13:01:41

Seems to have been a combination of "mithril" needing to be defined in string (js libraries indicated with string lib name) and extra paren. had bracket in wrong part of the namespace as well. not sure how it managed to have been compiling correctly thus far

nooga23:01:58

why would clj-kondo complain about unresolved symbols on in arg lists? I think it doesn't like my fn and friends

borkdude23:01:08

you need to lint your custom fn with :lint-as

nooga23:01:23

...seems like it evaluated (def fn ...) and stopped treating it as your usual fn?

borkdude23:01:40

{:lint-as {core/fn clojure.core/fn}}

nooga23:01:59

thx! going to look into this now 👍

borkdude23:01:27

you can do that on your ns form:

(ns core
  {:clj-kondo/config '{:lint-as ...}})

nooga23:01:47

added .clj-kondo/config.edn with this:

{:lint-as {core/fn clojure.core/fn
           core/defn clojure.core/defn
           core/let clojure.core/let
           core/defmacro clojure.core/defmacro
           core/loop clojure.core/loop
           core/declare clojure.core/declare
           core/defn- clojure.core/defn-
           core/def- clojure.core/def-
           core/when-let clojure.core/when-let
           core/if-let clojure.core/if-let}
 :linters
 {:redefined-var 
  {:level :off}
  :unresolved-symbol
  {:exclude [set-macro! apply* parse-int gt lt]}}}
and it seems like it cured all squiggly lines across my codebase 😂

🎉 2