This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-20
Channels
- # announcements (16)
- # babashka (71)
- # beginners (121)
- # bristol-clojurians (2)
- # calva (55)
- # clj-kondo (16)
- # clojure (103)
- # clojure-europe (9)
- # clojure-italy (5)
- # clojure-nl (4)
- # clojure-spec (49)
- # clojure-uk (57)
- # clojurescript (28)
- # conjure (9)
- # cursive (6)
- # datascript (3)
- # datomic (35)
- # duct (20)
- # events (3)
- # figwheel-main (12)
- # fulcro (6)
- # graalvm (12)
- # juxt (3)
- # kaocha (5)
- # lumo (10)
- # malli (5)
- # off-topic (54)
- # pathom (8)
- # re-frame (19)
- # reitit (21)
- # remote-jobs (1)
- # shadow-cljs (102)
- # sql (38)
- # tools-deps (60)
- # uncomplicate (3)
- # xtdb (10)
Nice trick, you can tweak linter settings per language in a .cljc
file by using conditionals:
(ns clj-kondo-cljs-macros.ns2.ns
#?(:clj {:clj-kondo/config '{:linters {:unused-binding {:level :off}}}}))
(defn foo [x y]
#?(:cljs x))
If anyone feels like adding clj-kondo to this page: https://analysis-tools.dev/tag/clojure, go ahead
I get the following warnings:
src/main_ns.cljc:3:14: warning: namespace required-ns is required but never used
src/main_ns.cljc:5:17: warning: Unused private var main-ns/my-fun
The macro expansion has a use of my-fun
and a use of the r
alias, so I don’t think there should be any warnings.Either look at https://github.com/simon-katz/nomis-clj-kondo-cljc-macros-2 Or:
(ns required-ns)
(defn foo [] 42)
(ns main-ns
#?(:cljs (:require-macros [main-ns :refer [my-macro]]))
(:require [required-ns :as r]))
(defn ^:private my-fun [x]
(inc x))
#?(:clj
(defmacro my-macro []
`(my-fun (r/foo))))
I already see the problem. You are only using required-ns
in Clojure. So why not wrap that in a #?(:clj ...)
If I run (my-macro)
, I get a result of 43
in both CLJ and CLJS, so I’m pretty sure that both my-fun
and r/foo
are used in both CLJ and CLJS.
@nomiskatz It's an interesting edge case fore sure. You can fix it with a local config:
(ns main-ns
{:clj-kondo/config '{:linters {:unused-private-var {:exclude [main-ns/my-fun]}
:unused-namespace {:exclude [required-ns]}}}}
#?(:cljs (:require-macros [main-ns :refer [my-macro]]))
(:require [required-ns :as r]))
And feel free to post this edge case as an issue.I'm not sure if this is fixable since it depends on runtime usage of the macro if the namespace + private var will be really used.