Skip to content

Commit

Permalink
Lint a good chunk of src/main/frontend
Browse files Browse the repository at this point in the history
Left some TODOs to discuss with others and others for me to finish
  • Loading branch information
logseq-cldwalker committed Jan 11, 2022
1 parent 3ded9ee commit 7497d8b
Show file tree
Hide file tree
Showing 37 changed files with 327 additions and 366 deletions.
13 changes: 9 additions & 4 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{:linters {:unresolved-symbol {:exclude [goog.DEBUG
goog.string.unescapeEntities]}}
{:linters
{:unresolved-symbol {:exclude [goog.DEBUG
goog.string.unescapeEntities
;; TODO: Fix when fixing all type hints
object]}}

:hooks {:analyze-call {rum.core/defc hooks.rum/defc
rum.core/defcs hooks.rum/defcs}}
rum.core/defcs hooks.rum/defcs}}
:lint-as {promesa.core/let clojure.core/let
promesa.core/loop clojure.core/loop
promesa.core/recur clojure.core/recur
garden.def/defstyles clojure.core/def
garden.def/defkeyframes clojure.core/def
rum.core/defcc rum.core/defc
Expand All @@ -17,4 +22,4 @@
frontend.namespaces/import-vars potemkin/import-vars
;; src/test
frontend.react/defc clojure.core/defn}
:skip-comments true}
:skip-comments true}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ strings.csv

.calva
resources/electron.js
.clj-kondo/
.clj-kondo/.cache
.lsp/
/libs/dist/
charlie/
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/db/conn.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
(swap! conns dissoc (datascript-db repo)))

(defn me-tx
[db {:keys [name email avatar]}]
[_db {:keys [name email avatar]}]
(util/remove-nils {:me/name name
:me/email email
:me/avatar avatar}))
Expand Down
3 changes: 1 addition & 2 deletions src/main/frontend/db/debug.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
:block/parent (:db/id (:block/parent e))}))))
(remove nil?))
count-1 (count blocks)
count-2 (count (distinct blocks))
result (filter #(> (second %) 1) (frequencies blocks))]
count-2 (count (distinct blocks))]
(assert (= count-1 count-2) (util/format "Blocks count: %d, repeated blocks count: %d"
count-1
(- count-1 count-2)))))
Expand Down
28 changes: 10 additions & 18 deletions src/main/frontend/db/model.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,7 @@
(defn flatten-blocks-sort-by-left
[blocks parent]
(let [ids->blocks (zipmap (map (fn [b] [(:db/id (:block/parent b))
(:db/id (:block/left b))]) blocks) blocks)
top-block (get ids->blocks [(:db/id parent) (:db/id parent)])]
(:db/id (:block/left b))]) blocks) blocks)]
(loop [node parent
next-siblings '()
result []]
Expand All @@ -461,7 +460,7 @@
(when block-id
(some->
(react/q repo-url [:block/refs-count block-id]
{:query-fn (fn [db]
{:query-fn (fn [_db]
(count (:block/_refs (db-utils/entity repo-url [:block/uuid block-id]))))}
nil)
react))))
Expand All @@ -479,8 +478,7 @@
(let [page (util/page-name-sanity-lc (string/trim page))
page-entity (or (db-utils/entity repo-url [:block/name page])
(db-utils/entity repo-url [:block/original-name page]))
page-id (:db/id page-entity)
db (conn/get-conn repo-url)]
page-id (:db/id page-entity)]
(when page-id
(some->
(react/q repo-url [:page/blocks page-id]
Expand Down Expand Up @@ -603,7 +601,7 @@
ids))))))

(defn block-and-children-transform
[result repo-url block-uuid]
[result repo-url _block-uuid]
(some->> result
db-utils/seq-flatten
(db-utils/with-repo repo-url)))
Expand Down Expand Up @@ -742,12 +740,6 @@
(db-utils/entity [:block/uuid (uuid page-name)])
(db-utils/entity [:block/name (util/page-name-sanity-lc page-name)])))

(defn- heading-block?
[block]
(and
(vector? block)
(= "Heading" (first block))))

(defn get-redirect-page-name
"Accepts both sanitized or unsanitized"
([page-name] (get-redirect-page-name page-name false))
Expand Down Expand Up @@ -897,7 +889,7 @@
db-utils/seq-flatten)]
(mapv (fn [page] [page (get-page-alias repo page)]) mentioned-pages))))

(defn- remove-children!
(defn remove-children!
[blocks]
(let [parents (->> (mapcat :block/parent blocks)
(map :db/id)
Expand Down Expand Up @@ -1135,7 +1127,7 @@
(defn get-matched-blocks
[match-fn limit]
(when-let [repo (state/get-current-repo)]
(let [pred (fn [db content]
(let [pred (fn [_db content]
(match-fn content))]
(->> (d/q
'[:find ?block
Expand Down Expand Up @@ -1231,7 +1223,7 @@

(defn get-all-templates
[]
(let [pred (fn [db properties]
(let [pred (fn [_db properties]
(some? (:template properties)))]
(->> (d/q
'[:find ?b ?p
Expand Down Expand Up @@ -1315,7 +1307,7 @@
non-public-datoms (get-public-false-block-ids db)
non-public-datom-ids (set (concat non-public-pages non-public-datoms))
filtered-db (d/filter db
(fn [db datom]
(fn [_db datom]
(let [ns (namespace (:a datom))]
(and (not (remove? ns))
(not (contains? #{:block/file} (:a datom)))
Expand Down Expand Up @@ -1347,7 +1339,7 @@
[@(d/conn-from-datoms datoms db-schema/schema) assets]))))

(defn delete-blocks
[repo-url files delete-page?]
[repo-url files _delete-page?]
(when (seq files)
(let [blocks (get-files-blocks repo-url files)]
(mapv (fn [eid] [:db.fn/retractEntity eid]) blocks))))
Expand Down Expand Up @@ -1535,7 +1527,7 @@
([repo] (remove-orphaned-pages! repo (get-orphaned-pages {})))
([repo orphaned-pages]
(let [transaction (mapv (fn [page] [:db/retractEntity (:db/id page)]) orphaned-pages)]
(db-utils/transact! transaction))))
(db-utils/transact! repo transaction))))

(defn get-block-last-direct-child
[db-id]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/db/outliner.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[conn id]
(try
(d/pull @conn '[*] id)
(catch js/Error e nil)))
(catch js/Error _e nil)))

(defn get-by-parent-&-left
[conn parent-id left-id]
Expand Down
1 change: 0 additions & 1 deletion src/main/frontend/db/persist.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns frontend.db.persist
(:require [frontend.util :as util]
[frontend.mobile.util :as mobile]
[frontend.idb :as idb]
[frontend.config :as config]
[electron.ipc :as ipc]
Expand Down
6 changes: 2 additions & 4 deletions src/main/frontend/db/query_custom.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[clojure.string :as string]
[cljs.reader :as reader]
[frontend.db.query-react :as react]
[frontend.template :as template]
[frontend.db.query-dsl :as dsl]
[frontend.db.model :as model]
[clojure.walk :as walk]))
Expand All @@ -26,11 +25,10 @@
([query]
(custom-query query {}))
([query query-opts]
(when-let [query' (cond
(when-let [_query' (cond
(and (string? query)
(not (string/blank? query)))
(let [query-string (template/resolve-dynamic-template! query)]
(reader/read-string query))
(reader/read-string query)

(map? query)
query
Expand Down
57 changes: 28 additions & 29 deletions src/main/frontend/db/query_dsl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -311,23 +311,23 @@
(keyword (string/lower-case (name order)))
:desc)
k (-> (string/lower-case (name k))
(string/replace "_" "-"))]
(let [get-value (cond
(= k "created-at")
:block/created-at

(= k "updated-at")
:block/updated-at

:else
#(get-in % [:block/properties k]))
comp (if (= order :desc) >= <=)]
(reset! sort-by
(fn [result]
(->> result
flatten
(clojure.core/sort-by get-value comp))))
nil))
(string/replace "_" "-"))
get-value (cond
(= k "created-at")
:block/created-at

(= k "updated-at")
:block/updated-at

:else
#(get-in % [:block/properties k]))
comp (if (= order :desc) >= <=)]
(reset! sort-by
(fn [result]
(->> result
flatten
(clojure.core/sort-by get-value comp))))
nil)

(= 'page fe)
(let [page-name (text/page-ref-un-brackets! (str (first (rest e))))
Expand Down Expand Up @@ -362,18 +362,17 @@
[true]]))

(= 'page-tags fe)
(do
(let [tags (if (coll? (first (rest e)))
(first (rest e))
(rest e))
tags (map (comp string/lower-case name) tags)]
(when (seq tags)
(let [tags (set (map (comp text/page-ref-un-brackets! string/lower-case name) tags))]
(let [sym-1 (uniq-symbol counter "?t")
sym-2 (uniq-symbol counter "?tag")]
[['?p :block/tags sym-1]
[sym-1 :block/name sym-2]
[(list 'contains? tags sym-2)]])))))
(let [tags (if (coll? (first (rest e)))
(first (rest e))
(rest e))
tags (map (comp string/lower-case name) tags)]
(when (seq tags)
(let [tags (set (map (comp text/page-ref-un-brackets! string/lower-case name) tags))
sym-1 (uniq-symbol counter "?t")
sym-2 (uniq-symbol counter "?tag")]
[['?p :block/tags sym-1]
[sym-1 :block/name sym-2]
[(list 'contains? tags sym-2)]])))

(= 'all-page-tags fe)
[['?e :block/tags '?p]]
Expand Down
46 changes: 23 additions & 23 deletions src/main/frontend/db/query_react.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,29 @@
(try
(let [repo (state/get-current-repo)
result (db-utils/seq-flatten query-result)
block? (:block/uuid (first result))]
(let [result (if block?
(let [result (if (seq remove-blocks)
(let [remove-blocks (set remove-blocks)]
(remove (fn [h]
(contains? remove-blocks (:block/uuid h)))
result))
result)]
(some->> result
remove-nested-children-blocks
(model/sort-by-left-recursive)
(db-utils/with-repo repo)
(model/with-pages)))
result)]
(if-let [result-transform (:result-transform q)]
(if-let [f (sci/eval-string (pr-str result-transform))]
(try
(sci/call-fn f result)
(catch js/Error e
(log/error :sci/call-error e)
result))
result)
result)))
block? (:block/uuid (first result))
result (if block?
(let [result (if (seq remove-blocks)
(let [remove-blocks (set remove-blocks)]
(remove (fn [h]
(contains? remove-blocks (:block/uuid h)))
result))
result)]
(some->> result
remove-nested-children-blocks
(model/sort-by-left-recursive)
(db-utils/with-repo repo)
(model/with-pages)))
result)]
(if-let [result-transform (:result-transform q)]
(if-let [f (sci/eval-string (pr-str result-transform))]
(try
(sci/call-fn f result)
(catch js/Error e
(log/error :sci/call-error e)
result))
result)
result))
(catch js/Error e
(log/error :query/failed e))))

Expand Down
14 changes: 6 additions & 8 deletions src/main/frontend/db/react.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[frontend.db.conn :as conn]
[frontend.db.utils :as db-utils]
[frontend.state :as state]
[frontend.util :as util :refer [profile react]]
[frontend.util :as util :refer [react]]
[frontend.util.marker :as marker]
[frontend.db.rules :as rules]))

Expand Down Expand Up @@ -50,13 +50,13 @@
(defn clear-query-state-without-refs-and-embeds!
[]
(let [state @query-state
state (->> (filter (fn [[[_repo k] v]]
state (->> (filter (fn [[[_repo k] _v]]
(contains? #{:blocks :block/block :custom} k)) state)
(into {}))]
(reset! query-state state)))

(defn get-current-repo-refs-keys
[{:keys [key data]}]
[{:keys [data]}]
(when-let [current-repo (state/get-current-repo)]
(->>
(map (fn [[repo k id]]
Expand Down Expand Up @@ -143,8 +143,7 @@
(defn q
[repo k {:keys [use-cache? transform-fn query-fn inputs-fn disable-reactive?]
:or {use-cache? true
transform-fn identity}
:as opts} query & inputs]
transform-fn identity}} query & inputs]
(let [kv? (and (vector? k) (= :kv (first k)))
k (vec (cons repo k))]
(when-let [conn (conn/get-conn repo)]
Expand Down Expand Up @@ -230,7 +229,6 @@
current-priority (get-current-priority)
current-marker (get-current-marker)
current-page-id (:db/id (get-current-page))
{:block/keys [page]} (first blocks)
related-keys (->>
(util/concat-without-nil
(mapcat
Expand Down Expand Up @@ -304,7 +302,7 @@
[[key]])))

(defn refresh!
[repo-url {:keys [key data] :as handler-opts}]
[repo-url handler-opts]
(let [related-keys (get-related-keys handler-opts)
db (conn/get-conn repo-url)]
(doseq [related-key related-keys]
Expand Down Expand Up @@ -336,7 +334,7 @@
(set-new-result! related-key new-result)))))))))

(defn transact-react!
[repo-url tx-data {:keys [key data] :as handler-opts}]
[repo-url tx-data handler-opts]
(when-not config/publishing?
(let [repo-url (or repo-url (state/get-current-repo))
tx-data (->> (util/remove-nils tx-data)
Expand Down
Loading

0 comments on commit 7497d8b

Please sign in to comment.