This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-10
Channels
- # announcements (9)
- # aws (11)
- # babashka (37)
- # beginners (97)
- # biff (2)
- # calva (73)
- # clj-kondo (17)
- # cljfx (3)
- # clojure (89)
- # clojure-europe (45)
- # clojure-norway (12)
- # clojurescript (17)
- # datahike (8)
- # datomic (13)
- # deps-new (4)
- # figwheel-main (1)
- # graalvm (2)
- # hyperfiddle (8)
- # introduce-yourself (6)
- # leiningen (38)
- # lsp (57)
- # malli (13)
- # nbb (46)
- # off-topic (40)
- # pathom (3)
- # polylith (8)
- # rum (4)
- # shadow-cljs (14)
- # spacemacs (1)
- # sql (11)
- # xtdb (10)
How to I lint a macro like:
(defmacro with-resource [symbol & body])
so it’s like with-open
but with a symbol instead of a binding vector. symbol
should be used in body@peder.refsnes This macro is similar to cljs.test/async
so you could use :lint-as
for this
thanks. anyway I could have figured this out myself? My strategy is usually to only look in clojure.core for a similar macro. is this the definition? https://github.com/clj-kondo/clj-kondo/blob/master/src/clj_kondo/impl/analyzer/test.clj#L26
of the lint rule?
meant the definition of the lint rule, not the macro. my bad
I did, it works. but does not assert the usage of symbol
in body. wanted to try creating a rule in clj-kondo that would do that for fun
I think you're better off creating your own hook then: https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md
aha, I see. thanks! ❤️
If the docs are too terse, you can consider doing these exercises: https://github.com/clj-kondo/hooks-workshop-clojured-2022
nice, thanks :thumbsup:
given this macro
(defmacro with-resource [symbol & body]
`(let [~symbol (constantly 1)]
~@body))
(with-resource x
(+ 1 (x)))
I want a hook for linting it. Came up with this
(defn with-resource [{:keys [:node]}]
(let [[sym & body] (rest (:children node))
fn-node (api/list-node
(list (api/token-node 'constantly)
(api/token-node 'nil)))
new-node (api/list-node
(list* (api/token-node 'let)
(api/vector-node [sym fn-node])
body))]
{:node new-node}))
This works exactly as I want it to. Just wondering if there is a more idiomatic way of writing it.