Skip to content

Instantly share code, notes, and snippets.

@gmp26
Last active December 28, 2023 14:23

Revisions

  1. gmp26 revised this gist Nov 13, 2021. 2 changed files with 16 additions and 5 deletions.
    19 changes: 15 additions & 4 deletions config.edn
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,15 @@
    ;
    ; Put this under .clj-kondo in the project folder. Includes some fulcro, mount and pathom config.
    ; Put this under .clj-kondo in the project folder. Includes some fulcro, mount, pathom22, nubank workspaces,
    ; and fulcro-rad config.
    ;
    {:hooks {:analyze-call {com.fulcrologic.fulcro.mutations/defmutation com.fulcrologic.fulcro.clj-kondo-hooks/defmutation
    com.fulcrologic.guardrails.core/>defn com.fulcrologic.fulcro.clj-kondo-hooks/>defn}}
    :linters {:clj-kondo.fulcro.defmutation/handler-arity {:level :error}
    :clj-kondo.fulcro.>defn/signature-mismatch {:level :error}}
    :lint-as {com.fulcrologic.fulcro.components/defsc clojure.core/defn
    :lint-as {;com.fulcrologic.fulcro.mutations/defmutation clojure.core/def
    nubank.workspaces.core/defcard clojure.core/def
    com.fulcrologic.fulcro.networking.websockets/stop! clojure.core/def
    com.fulcrologic.fulcro.components/defsc clojure.core/defn
    com.fulcrologic.fulcro.routing.dynamic-routing/defrouter clojure.core/defn
    com.fulcrologic.fulcro.ui-state-machines/defstatemachine clojure.core/def
    com.fulcrologic.guardrails.core/>def clojure.core/def
    @@ -14,6 +18,13 @@
    com.fulcrologic.rad.report/defsc-report clojure.core/defn
    com.fulcrologic.rad.form/defsc-form clojure.core/defn
    com.fulcrologic.rad.authorization/defauthenticator clojure.core/def
    com.wsscode.pathom.connect/defresolver clojure.core/defn
    com.wsscode.pathom.connect/defmutation clojure.core/defn
    mount.core/defstate clojure.core/def}}
    com.wsscode.pathom.connect/defresolver clojure.core/defn
    com.wsscode.async.async-clj/deftest-async clojure.test/deftest
    com.wsscode.async.async-clj/go-try-stream clojure.core/let
    com.wsscode.async.async-clj/let-chan clojure.core/let
    com.wsscode.async.async-clj/let-chan* clojure.core/let
    com.wsscode.async.async-cljs/deftest-async clojure.test/deftest
    com.wsscode.async.async-cljs/go-try-stream clojure.core/let
    com.wsscode.async.async-cljs/let-chan clojure.core/let
    com.wsscode.async.async-cljs/let-chan* clojure.core/let}}
    2 changes: 1 addition & 1 deletion fulcro
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    ;
    ; Path to this file should be .clj-kondo/com.fulcrologic/fulcro/com/fulcrologic/fulcro
    ; Path to this file should be .clj-kondo/com/fulcrologic/fulcro/com/fulcro/clj-kondo-hooks.clj
    ;
    (ns com.fulcrologic.fulcro.clj-kondo-hooks
    (:require [clj-kondo.hooks-api :as api]))
  2. gmp26 revised this gist Nov 8, 2021. No changes.
  3. gmp26 revised this gist Nov 8, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion config.edn
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    ;
    ; Put this under .clj-kondo in teh project folder. Includes some fulcro, mount and pathom config.
    ; Put this under .clj-kondo in the project folder. Includes some fulcro, mount and pathom config.
    ;
    {:hooks {:analyze-call {com.fulcrologic.fulcro.mutations/defmutation com.fulcrologic.fulcro.clj-kondo-hooks/defmutation
    com.fulcrologic.guardrails.core/>defn com.fulcrologic.fulcro.clj-kondo-hooks/>defn}}
  4. gmp26 revised this gist Nov 8, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fulcro
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    ;
    ; Put this in .clj-kondo/com.fulcrologic/fulcro/com/fulcrologic/fulcro
    ; Path to this file should be .clj-kondo/com.fulcrologic/fulcro/com/fulcrologic/fulcro
    ;
    (ns com.fulcrologic.fulcro.clj-kondo-hooks
    (:require [clj-kondo.hooks-api :as api]))
  5. gmp26 renamed this gist Nov 8, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. gmp26 created this gist Nov 8, 2021.
    19 changes: 19 additions & 0 deletions config.edn
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    ;
    ; Put this under .clj-kondo in teh project folder. Includes some fulcro, mount and pathom config.
    ;
    {:hooks {:analyze-call {com.fulcrologic.fulcro.mutations/defmutation com.fulcrologic.fulcro.clj-kondo-hooks/defmutation
    com.fulcrologic.guardrails.core/>defn com.fulcrologic.fulcro.clj-kondo-hooks/>defn}}
    :linters {:clj-kondo.fulcro.defmutation/handler-arity {:level :error}
    :clj-kondo.fulcro.>defn/signature-mismatch {:level :error}}
    :lint-as {com.fulcrologic.fulcro.components/defsc clojure.core/defn
    com.fulcrologic.fulcro.routing.dynamic-routing/defrouter clojure.core/defn
    com.fulcrologic.fulcro.ui-state-machines/defstatemachine clojure.core/def
    com.fulcrologic.guardrails.core/>def clojure.core/def
    com.fulcrologic.guardrails.core/>defn clojure.core/defn
    com.fulcrologic.rad.attributes/defattr clojure.core/def
    com.fulcrologic.rad.report/defsc-report clojure.core/defn
    com.fulcrologic.rad.form/defsc-form clojure.core/defn
    com.fulcrologic.rad.authorization/defauthenticator clojure.core/def
    com.wsscode.pathom.connect/defresolver clojure.core/defn
    com.wsscode.pathom.connect/defmutation clojure.core/defn
    mount.core/defstate clojure.core/def}}
    65 changes: 65 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    ;
    ; Put this in .clj-kondo/com.fulcrologic/fulcro/com/fulcrologic/fulcro
    ;
    (ns com.fulcrologic.fulcro.clj-kondo-hooks
    (:require [clj-kondo.hooks-api :as api]))

    (defn defmutation
    [{:keys [node]}]
    (let [args (rest (:children node))
    mutation-name (first args)
    ?docstring (when (string? (api/sexpr (second args)))
    (second args))
    args (if ?docstring
    (nnext args)
    (next args))
    params (first args)
    handlers (rest args)
    handler-syms (map (comp first :children) handlers)
    bogus-usage (api/vector-node (vec handler-syms))
    letfn-node (api/list-node
    (list
    (api/token-node 'letfn)
    (api/vector-node (vec handlers))
    bogus-usage))
    new-node (api/list-node
    (list
    (api/token-node 'defn)
    mutation-name
    params
    letfn-node))]
    (doseq [handler handlers]
    (let [hname (some-> handler :children first api/sexpr str)
    argv (some-> handler :children second)]
    (when-not (= 1 (count (api/sexpr argv)))
    (api/reg-finding! (merge
    (meta argv)
    {:message (format "defmutation handler '%s' should be a fn of 1 arg" hname)
    :type :clj-kondo.fulcro.defmutation/handler-arity})))))
    {:node new-node}))

    (defn >defn
    [{:keys [node]}]
    (let [args (rest (:children node))
    fn-name (first args)
    ?docstring (when (string? (api/sexpr (second args)))
    (second args))
    args (if ?docstring
    (nnext args)
    (next args))
    argv (first args)
    gspec (second args)
    body (nnext args)
    new-node (api/list-node
    (list*
    (api/token-node 'defn)
    fn-name
    argv
    gspec
    body))]
    (when (not= (count (api/sexpr argv))
    (count (take-while #(not= '=> %) (api/sexpr gspec))))
    (api/reg-finding! (merge (meta gspec)
    {:message "Guardrail spec does not match function signature"
    :type :clj-kondo.fulcro.>defn/signature-mismatch})))
    {:node new-node}))