Fork me on GitHub

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}}}

💡 1

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?


Currently not


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?


With global I meant :cljc {:features #{:cljs}} which I think makes sense for your project. And then you could maybe just ignore the one .clj file or put a namespace config in that one.

👍 1

Or perhaps I'm still missing what the issue is.


Yep, utilizing the :cljc config + ignoring the one .clj file was what I had in mind 🙂 Thanks!