helix

https://github.com/Lokeh/helix
dominicm 2020-11-23T18:46:41.192700Z

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

dominicm 2020-11-23T18:48:06.192800Z

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.

💯 4
lilactown 2020-11-23T20:39:07.193500Z

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

lilactown 2020-11-23T20:39:44.194300Z

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

lilactown 2020-11-23T20:42:30.195600Z

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

dominicm 2020-11-23T21:58:32.195800Z

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