This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-23
Channels
- # announcements (2)
- # atom-editor (3)
- # babashka (49)
- # beginners (100)
- # biff (9)
- # calva (78)
- # clj-kondo (18)
- # clojure (143)
- # clojure-europe (13)
- # clojure-germany (1)
- # clojure-nl (2)
- # clojure-spec (5)
- # clojure-sweden (2)
- # clojure-uk (4)
- # clojurescript (58)
- # conjure (1)
- # cursive (4)
- # datascript (11)
- # datomic (63)
- # docker (7)
- # emacs (18)
- # events (1)
- # fulcro (18)
- # graalvm (5)
- # helix (4)
- # improve-getting-started (13)
- # jobs (4)
- # jobs-discuss (3)
- # lsp (15)
- # malli (90)
- # membrane (14)
- # off-topic (12)
- # other-languages (5)
- # pedestal (7)
- # polylith (53)
- # re-frame (15)
- # reitit (23)
- # releases (4)
- # remote-jobs (9)
- # ring (11)
- # shadow-cljs (90)
- # specter (2)
- # testing (3)
- # tools-build (63)
- # vim (2)
- # xtdb (8)
For cljc
files is there a way to not lint the Clojure side of things and instead only lint ClojureScript?
Asking because with shadow-cljs it’s somewhat common to use #?(:browser ..)
and node reader conditionals
and you don’t really want to lint the namespace as Clojure
Yes, but undocumented since I was unsure about the API. Try:
{:cljc {:features #{:cljs}}}
If we adopt the above config, what is the recommended approach for linting the Clojure branch in some .cljc
files but not others?
Most of our .cljc
files are Clojurescript only, but there are a handful that expose implementations for both Clj and Cljs
After implementing the :cljc
config above, I'm seeing that clj-kondo
reports "Unresolved var" wherever a Clojure namespace consumes a var defined in a .cljc
file
For example,
;; log.cljc
(defn info
[& s]
(let [msg (fmt s)]
#?(:clj (log/info msg)
:cljs (glog/info logger msg))))
;; user.clj
(log/info (str "Rendering CSS to " path))
;; clj-kondo reports unresolved var log/info
I tried adding a {:clj-kondo/config '{:cljc {:features #{:clj :cljs}}}}
override in the log.cljc
namespace declaration, but that didn't seem to work
That doesn't work yet, since by the time clj-kondo reads that config, the cljc branches have already been parsed
The unresolved var is because clj-kondo is only going to analyze the features you specify. The intention of that config is to disable .cljs completely for babashka projects that use .cljc files
Ah got it, so right now it's an all-or-nothing type of deal with the :cljc
config
Hmm, given the situation described in our use case above, do you any suggestions on a way to make this work?
Thanks! That is our lone Clojure namespace, and it's rarely updated, so maybe we can just get away with not linting it... 😬
Maybe you can explain what your issue is with this, since this requirement has never come up before
If it's your only clojure namespace then I don't see why you wouldn't use the global config
Ah sure - thanks for working through it with me. My issue is an extension of what Martin wrote above
We have lots of .cljs
files, ~20 .cljc
files, and a single .clj
file.
The .cljs
files are used in both Node and browser for server and client-side rendering
We have 2 distinct sets of .cljc
files:
• those that target :node
and :browser
; shadow-cljs supports using the reader conditional to target different JS platforms e.g. node
and browser
to consume specific platform-specific APIs. These import other CLJS namespaces
• those that target :clj
and :cljs
And we have a single .clj
file that imports a couple .cljc
namespaces
---
Without the :cljc {:features #{:cljs}}
config you shared above, we would have to wrap most of the .cljc
namespaces (required imports and vars) in #?(:cljs)
to prevent the Clojure path from being linted.
Ideally we would be able to just use the #?(:browser)
reader conditional on the leaf nodes where we utilize the browser-specific API e.g. js/window
or js/document
Is your suggestion to use the global config to ignore the unresolved var errors for Clojure files?