🎉 Add linter for check duplicte potok types.

This commit is contained in:
Andrey Antukh 2021-09-06 15:58:36 +02:00 committed by Andrés Moya
parent 926fa483b9
commit 7e0c097f23
19 changed files with 54 additions and 35 deletions

View file

@ -23,6 +23,9 @@
{:unsorted-required-namespaces {:unsorted-required-namespaces
{:level :warning} {:level :warning}
:potok/reify-type
{:level :error}
:unresolved-namespace :unresolved-namespace
{:level :warning {:level :warning
:exclude [data_readers]} :exclude [data_readers]}

View file

@ -10,15 +10,34 @@
sname])] sname])]
{:node result})) {:node result}))
(def registry (atom {}))
(defn potok-reify (defn potok-reify
[{:keys [:node]}] [{:keys [:node :filename] :as params}]
(let [[rnode rtype & other] (:children node) (let [[rnode rtype & other] (:children node)
result (api/list-node rsym (symbol (str "event-type-" (name (:k rtype))))
(into [(api/token-node (symbol "deftype")) reg (get @registry filename #{})]
(api/token-node (gensym (name (:k rtype)))) (when-not (:namespaced? rtype)
(api/vector-node [])] (let [{:keys [:row :col]} (meta rtype)]
other))] (api/reg-finding! {:message "ptk/reify type should be namespaced"
{:node result})) :type :potok/reify-type
:row row
:col col})))
(if (contains? reg rsym)
(let [{:keys [:row :col]} (meta rtype)]
(api/reg-finding! {:message (str "duplicate type: " (name (:k rtype)))
:type :potok/reify-type
:row row
:col col}))
(swap! registry update filename (fnil conj #{}) rsym))
(let [result (api/list-node
(into [(api/token-node (symbol "deftype"))
(api/token-node rsym)
(api/vector-node [])]
other))]
{:node result})))
(defn clojure-specify (defn clojure-specify
[{:keys [:node]}] [{:keys [:node]}]

View file

@ -710,14 +710,14 @@
(defn go-to-files (defn go-to-files
([project-id] ([project-id]
(ptk/reify ::go-to-files (ptk/reify ::go-to-files-1
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(rx/of (rt/nav :dashboard-files {:team-id team-id (rx/of (rt/nav :dashboard-files {:team-id team-id
:project-id project-id})))))) :project-id project-id}))))))
([team-id project-id] ([team-id project-id]
(ptk/reify ::go-to-files (ptk/reify ::go-to-files-2
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(rx/of (rt/nav :dashboard-files {:team-id team-id (rx/of (rt/nav :dashboard-files {:team-id team-id
@ -739,13 +739,13 @@
(defn go-to-projects (defn go-to-projects
([] ([]
(ptk/reify ::go-to-projects (ptk/reify ::go-to-projects-0
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(rx/of (rt/nav :dashboard-projects {:team-id team-id})))))) (rx/of (rt/nav :dashboard-projects {:team-id team-id}))))))
([team-id] ([team-id]
(ptk/reify ::go-to-projects (ptk/reify ::go-to-projects-1
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(du/set-current-team! team-id) (du/set-current-team! team-id)

View file

@ -232,7 +232,7 @@
(rt/nav :viewer pparams (assoc qparams :index (dec index))))))))) (rt/nav :viewer pparams (assoc qparams :index (dec index)))))))))
(def select-next-frame (def select-next-frame
(ptk/reify ::select-prev-frame (ptk/reify ::select-next-frame
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(prn "select-next-frame") (prn "select-next-frame")
@ -290,7 +290,7 @@
(defn go-to-frame-by-index (defn go-to-frame-by-index
[index] [index]
(ptk/reify ::go-to-frame (ptk/reify ::go-to-frame-by-index
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [route (:route state) (let [route (:route state)

View file

@ -365,7 +365,6 @@
(when (= id (:current-page-id state)) (when (= id (:current-page-id state))
go-to-file)))))) go-to-file))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; WORKSPACE File Actions ;; WORKSPACE File Actions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -376,7 +375,7 @@
(ptk/reify ::rename-file (ptk/reify ::rename-file
IDeref IDeref
(-deref [_] (-deref [_]
{:ev/origin "workspace" :id id :name name}) {::ev/origin "workspace" :id id :name name})
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
@ -1134,7 +1133,7 @@
(defn align-objects (defn align-objects
[axis] [axis]
(us/verify ::gal/align-axis axis) (us/verify ::gal/align-axis axis)
(ptk/reify :align-objects (ptk/reify ::align-objects
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
@ -1165,7 +1164,7 @@
(defn distribute-objects (defn distribute-objects
[axis] [axis]
(us/verify ::gal/dist-axis axis) (us/verify ::gal/dist-axis axis)
(ptk/reify :align-objects (ptk/reify ::distribute-objects
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
@ -1240,7 +1239,7 @@
(rx/of (rt/nav' :workspace pparams qparams)))))) (rx/of (rt/nav' :workspace pparams qparams))))))
([page-id] ([page-id]
(us/verify ::us/uuid page-id) (us/verify ::us/uuid page-id)
(ptk/reify ::go-to-page (ptk/reify ::go-to-page-2
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [project-id (:current-project-id state) (let [project-id (:current-project-id state)
@ -1303,7 +1302,7 @@
(defn go-to-dashboard-fonts (defn go-to-dashboard-fonts
[] []
(ptk/reify ::go-to-dashboard (ptk/reify ::go-to-dashboard-fonts
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]

View file

@ -69,7 +69,7 @@
(defn show-palette (defn show-palette
"Show the palette tool and change the library it uses" "Show the palette tool and change the library it uses"
[selected] [selected]
(ptk/reify ::change-palette-selected (ptk/reify ::show-palette
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(-> state (-> state

View file

@ -9,7 +9,6 @@
[app.common.math :as mth] [app.common.math :as mth]
[app.common.spec :as us] [app.common.spec :as us]
[app.main.data.comments :as dcm] [app.main.data.comments :as dcm]
[app.main.data.events :as ev]
[app.main.data.workspace :as dw] [app.main.data.workspace :as dw]
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
[app.main.streams :as ms] [app.main.streams :as ms]
@ -72,7 +71,7 @@
(defn center-to-comment-thread (defn center-to-comment-thread
[{:keys [position] :as thread}] [{:keys [position] :as thread}]
(us/assert ::dcm/comment-thread thread) (us/assert ::dcm/comment-thread thread)
(ptk/reify :center-to-comment-thread (ptk/reify ::center-to-comment-thread
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(update state :workspace-local (update state :workspace-local

View file

@ -54,7 +54,7 @@
(defn remove-frame-grid (defn remove-frame-grid
[frame-id index] [frame-id index]
(ptk/reify ::set-frame-grid (ptk/reify ::remove-frame-grid
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(rx/of (dch/update-shapes [frame-id] (fn [o] (update o :grids (fnil #(d/remove-at-index % index) [])))))))) (rx/of (dch/update-shapes [frame-id] (fn [o] (update o :grids (fnil #(d/remove-at-index % index) []))))))))

View file

@ -295,7 +295,7 @@
[] []
(ptk/reify ::add-component (ptk/reify ::add-component
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [_ state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
selected (->> (wsh/lookup-selected state) selected (->> (wsh/lookup-selected state)
(cp/clean-loops objects))] (cp/clean-loops objects))]

View file

@ -107,7 +107,7 @@
(defn- handle-pointer-send (defn- handle-pointer-send
[file-id point] [file-id point]
(ptk/reify ::handle-pointer-update (ptk/reify ::handle-pointer-send
ptk/EffectEvent ptk/EffectEvent
(effect [_ state _] (effect [_ state _]
(let [ws (get-in state [:ws file-id]) (let [ws (get-in state [:ws file-id])

View file

@ -179,7 +179,7 @@
:right (gpt/point 1 0))) :right (gpt/point 1 0)))
(defn finish-move-selected [] (defn finish-move-selected []
(ptk/reify ::move-selected (ptk/reify ::finish-move-selected
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [id (get-in state [:workspace-local :edition])] (let [id (get-in state [:workspace-local :edition])]

View file

@ -20,7 +20,7 @@
;; Shortcuts format https://github.com/ccampbell/mousetrap ;; Shortcuts format https://github.com/ccampbell/mousetrap
(defn esc-pressed [] (defn esc-pressed []
(ptk/reify :esc-pressed (ptk/reify ::esc-pressed
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
;; Not interrupt when we're editing a path ;; Not interrupt when we're editing a path

View file

@ -90,7 +90,7 @@
"Joins the head with the previous undo in one. This is done so when the user changes a "Joins the head with the previous undo in one. This is done so when the user changes a
node handlers after adding it the undo merges both in one operation only" node handlers after adding it the undo merges both in one operation only"
[] []
(ptk/reify ::add-undo-entry (ptk/reify ::merge-head
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [id (st/get-path-id state) (let [id (st/get-path-id state)

View file

@ -114,7 +114,7 @@
(defn deselect-shape (defn deselect-shape
[id] [id]
(us/verify ::us/uuid id) (us/verify ::us/uuid id)
(ptk/reify ::select-shape (ptk/reify ::deselect-shape
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(update-in state [:workspace-local :selected] disj id)))) (update-in state [:workspace-local :selected] disj id))))

View file

@ -511,7 +511,7 @@
(defn- start-move-duplicate (defn- start-move-duplicate
[from-position] [from-position]
(ptk/reify ::start-move-selected (ptk/reify ::start-move-duplicate
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ stream] (watch [_ _ stream]
(->> stream (->> stream

View file

@ -19,6 +19,7 @@
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt] [app.util.router :as rt]
[beicon.core :as rx] [beicon.core :as rx]
[potok.core :as ptk]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(defn get-project-name (defn get-project-name

View file

@ -10,7 +10,6 @@
[app.common.spec :as us] [app.common.spec :as us]
[app.config :as cfg] [app.config :as cfg]
[app.main.data.dashboard :as dd] [app.main.data.dashboard :as dd]
[app.main.data.events :as ev]
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.refs :as refs] [app.main.refs :as refs]

View file

@ -8,7 +8,6 @@
(:require (:require
[app.common.spec :as us] [app.common.spec :as us]
[app.config :as cfg] [app.config :as cfg]
[app.main.data.events :as ev]
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.data.users :as du] [app.main.data.users :as du]

View file

@ -7,16 +7,16 @@
(ns app.main.ui.viewer.handoff.code (ns app.main.ui.viewer.handoff.code
(:require (:require
["js-beautify" :as beautify] ["js-beautify" :as beautify]
[app.main.data.events :as ev]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.main.data.events :as ev]
[app.main.store :as st]
[app.main.ui.components.code-block :refer [code-block]] [app.main.ui.components.code-block :refer [code-block]]
[app.main.ui.components.copy-button :refer [copy-button]] [app.main.ui.components.copy-button :refer [copy-button]]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.main.store :as st]
[potok.core :as ptk]
[app.util.code-gen :as cg] [app.util.code-gen :as cg]
[app.util.dom :as dom] [app.util.dom :as dom]
[cuerdas.core :as str] [cuerdas.core :as str]
[potok.core :as ptk]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(defn generate-markup-code [_type shapes] (defn generate-markup-code [_type shapes]