Fork me on GitHub
#helix
<
2020-11-23
>
dominicm18:11:41

I'd like to start pooling together a clj-kondo config :) Here's what I have so far:

(ns hooks.frontend
  (:require [clj-kondo.hooks-api :as api]))

(defn defnc
  [{:keys [node]}]
  (let [[type params & body] (rest (:children node))
        [_docstring params body] (if (string? (api/sexpr params))
                                  [params (first body) (rest body)]
                                  [nil params body])]
    {:node
     (api/list-node
       (list* (api/token-node 'defn) type
              (api/vector-node [(api/token-node '&) (api/vector-node (vec (concat (:children params) [(api/token-node '_children)])))])
              body))}))

(defn defcomponent
  [{:keys [node]}]
  (let [[name & methods] (rest (:children node))]
    {:node
     (api/list-node
       (list* (api/token-node 'cljs.core/deftype)
              name
              (api/vector-node [])
              (api/token-node 'js/not-a-protocol-you-know)
              methods))}))
and
{:hooks {:analyze-call {helix.core/defnc hooks.frontend/defnc
                        helix.core/defcomponent hooks.frontend/defcomponent}}}

dominicm18:11:06

We could put it into Helix's code, then Kondo will pick it up automatically and we'll have more fun. I think it would be good to write a hook for $ that enforces that the second arg is a map literal.

💯 12
lilactown20:11:07

wait, but the second arg can be either a map literal or the first child :thinking_face:

lilactown20:11:44

I wonder if clj-kondo would be better at discerning that than helix. helix already throws a warning if it infers you're passing a CLJS map in to the first arg

lilactown20:11:30

problem is that children are polymorphic too; they can be elements, or functions, or anything really depending on the component being used to create the element

dominicm21:11:32

@lilactown Oh yeah, I guess :) nevermind then!