This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-06
Channels
- # announcements (4)
- # beginners (132)
- # calva (37)
- # chlorine-clover (60)
- # cider (1)
- # clara (12)
- # clj-kondo (40)
- # cljs-dev (109)
- # clojure (76)
- # clojure-dev (19)
- # clojure-europe (8)
- # clojure-france (17)
- # clojure-nl (4)
- # clojure-sg (1)
- # clojure-spec (14)
- # clojure-uk (7)
- # clojurescript (98)
- # conjure (96)
- # cursive (15)
- # data-science (2)
- # datalog (11)
- # datomic (24)
- # emacs (17)
- # figwheel-main (3)
- # fulcro (45)
- # jobs-discuss (1)
- # kaocha (3)
- # malli (2)
- # nrepl (1)
- # off-topic (135)
- # portal (2)
- # re-frame (17)
- # reagent (11)
- # reitit (4)
- # sci (60)
- # shadow-cljs (75)
- # spacemacs (3)
- # sql (32)
- # tools-deps (79)
- # vim (88)
- # xtdb (4)
@cnly No. But there is a tool for this based on clj-kondo: https://github.com/borkdude/carve
@borkdude Is there a tutorial or docs how to test & write custom hooks? I would love to tweak rum.core/defcs in free time
@karol.wojcik This is the most recent one: https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#hooks
Thank you very much! Why there is :node in keys instead of node?
@borkdude Btw I'm trying to find the exact source of clj-kondo.hooks-api. This is what I got so far:
(defn defcs
[{:keys [node]}]
(let [args (rest (:children node))
component-name (first args)
args (next args)
body
(loop [args* args
mixins []]
(if (seq args*)
(let [a (first args*)]
(if (vector? (api/sexpr a))
(do
(println a)
(println (api/vector-node (vec (rest (api/sexpr a)))))
(cons (api/vector-node (vec (rest (api/sexpr a)))) (concat mixins (rest args*))))
(recur (rest args*)
(conj mixins a))))
args))
new-node (with-meta
(api/list-node (list* (api/token-node 'defn) component-name body))
(meta node))]
;; (println (api/token-node 'defn))
;; (println new-node)
{:node new-node}))
But this throws unsupported binding form input
@borkdude I think that I should ignore state somehow, but dunno how to do it.
Can you please give me a hint?
For instance simply ignoring the first argument results in input
not being known.
Yes. You should probably wrap the body in an artificial let expression that has a binding state
, like (let [state nil] ... body ...)
@U050TNB9F @U0509NKGK Any ideas?
Finally got it working
(defn defcs
[{:keys [node]}]
(let [args (rest (:children node))
component-name (first args)
args (next args)
body (loop [args* args
mixins []]
(if (seq args*)
(let [a (first args*)]
(if (vector? (api/sexpr a))
(cons a (concat mixins (rest args*)))
(recur (rest args*)
(conj mixins a))))
args))
partial-state (api/list-node [(api/token-node 'partial)
(api/list-node (list* (api/token-node 'fn) body))
(api/token-node 'state)])
new-node (api/list-node
[(api/token-node 'let)
(api/vector-node
[(api/token-node 'state) (api/token-node {})])
(with-meta (api/list-node [(api/token-node 'def)
component-name
partial-state])
(meta node))])]
{:node new-node}))
Thank you for help @borkdude you are golden!
It's for making sure that state is provided
I think this generates something like:
(let [state {}] (def my-component (partial (fn [...] ...) state)))
Why not:
(defn my-component [args] (let [state {}] body)
?Is there a difference?
So in partial it's not seen?
You might want to do:
(defn my-component [args] (let [state {}] state ... body ...)
to make state being used, so it won't be reported.Hmm....
Frankly I want the state to be reported
Ahh wait.
so if you don't use state, then you're going to use def-something-else in rum right?
So I can just ignore the first arg?
I think that we are talking past each other 😄
I think so too. Maybe it's better to talk in examples. Paste an example of Rum usage and the desired sexpr for clj-kondo
@borkdude My goal is to make sure that both not used state is reported and function that takes like 2 (except state) args then when I provide only one argument then I want clj-kondo to report that not all function parameters are passed. Let the demo.cljs be defined like so:
(rum/defcs SomeComponent <
{:did-mount (fn [state] state)}
[state input another]
(let [x "Hello"]
nil))
(rum/defc SomeComponent1 <
{:did-mount (fn [state] state)}
[input]
input)
(SomeComponent "hello")
After running clj-kondo I got the following things reported:
demo.cljs:9:4: warning: unused binding state
demo.cljs:9:10: warning: unused binding input
demo.cljs:9:16: warning: unused binding another
demo.cljs:10:9: warning: unused binding x
linting took 17ms, errors: 0, warnings: 4
That's perfectly fine. What I need more is just the warning that not all parameters to function has been passed.
My question is how I can have that last warning working? What I understand is that I should not use 'partial, but how should I construct sexpr?@karol.wojcik I think more like (defn my-component [args] (let [state {}] body)
, so more like how it was originally, but with the extra let around the body
So you call it as (f 1)
and clj-kondo will think this is correct, since the generated form only receives one arg (or n-1 args in general) and state is still recognized as a valid binding.
Thanks.. Will try to do it in free time
@karol.wojcik Note: I edited the link, posted an old one earlier