aroemers / redelay

Clojure library for first class lifecycle-managed state.
Other
60 stars 1 forks source link

clj-kondo configuration #1

Open dpassen opened 10 months ago

dpassen commented 10 months ago

Is there any interest in clj-kondo configuration? I see mount-lite has some hooks defined.

aroemers commented 10 months ago

Hi Derek,

Yes, for sure. That way many clj-kondo users benefit from better linting.

piranha commented 1 month ago

Got it working like that (based on mount-lite hook):

(ns hooks.redelay
  (:require [clojure.string :as str]))

(defn- qualified-exprs [qualifiers exprs]
  (loop [qualifiers (set qualifiers)
         exprs      exprs
         qualifier  nil
         qualified  {}]
    (if (seq exprs)
      (let [expr (first exprs)]
        (if-let [qualifier (qualifiers expr)]
          (recur (disj qualifiers qualifier) (rest exprs) qualifier qualified)
          (recur qualifiers (rest exprs) qualifier (update qualified qualifier (fnil conj []) expr))))
      qualified)))

(defmacro defstate [name & args]
  (let [{:keys [start stop] names :name metas :meta implicit-start nil}
        (qualified-exprs [:name :start :stop :meta]
          (concat [:name name] args))
        start (or start implicit-start)
        hmap  {:name     (first names)
               :start-fn `(fn [] ~@start)
               :stop-fn  (if (str/includes? (str stop) "this")
                           `(fn [~'this] ~@stop)
                           `(fn [] ~@stop))
               :meta     (first metas)}]
    `(def ~name (redelay.core/map->State ~hmap))))
aroemers commented 3 weeks ago

@dpassen and @piranha could you have a look at #2? I hope it satisfies your needs with minimal code.