Bläddra i källkod

Mark most vars as cleanup-todo

Fixed a few that I knew how to QA and were low risk
Gabriel Horner 3 år sedan
förälder
incheckning
e81678fc69

+ 10 - 2
scripts/large_vars.clj

@@ -4,6 +4,7 @@
   "This script detects vars that are too large and that make it difficult for
   "This script detects vars that are too large and that make it difficult for
   the team to maintain and understand them."
   the team to maintain and understand them."
   (:require [babashka.pods :as pods]
   (:require [babashka.pods :as pods]
+            [clojure.pprint :as pprint]
             [clojure.set :as set]))
             [clojure.set :as set]))
 
 
 (pods/load-pod 'clj-kondo/clj-kondo "2021.12.19")
 (pods/load-pod 'clj-kondo/clj-kondo "2021.12.19")
@@ -14,7 +15,11 @@
   {:max-lines-count 100
   {:max-lines-count 100
    ;; Vars with these metadata flags are allowed. Name should indicate the reason
    ;; Vars with these metadata flags are allowed. Name should indicate the reason
    ;; it is allowed
    ;; it is allowed
-   :metadata-exceptions #{::data-var}})
+   :metadata-exceptions #{::data-var
+                          ;; TODO: Address vars tagged with cleanup-todo. These
+                          ;; are left mostly because they are not high priority
+                          ;; or not well understood
+                          ::cleanup-todo}})
 
 
 (defn -main
 (defn -main
   [args]
   [args]
@@ -34,7 +39,10 @@
                                :filename (:filename m)}))))
                                :filename (:filename m)}))))
                   (sort-by :lines-count (fn [x y] (compare y x))))]
                   (sort-by :lines-count (fn [x y] (compare y x))))]
     (if (seq vars)
     (if (seq vars)
-      (do (prn vars)
+      (do
+        (println (format "The following vars exceed the line count max of %s:"
+                         (:max-lines-count config)))
+        (pprint/print-table vars)
         (System/exit 1))
         (System/exit 1))
       (println "All vars are below the max size!"))))
       (println "All vars are below the max size!"))))
 
 

+ 1 - 1
scripts/src/logseq/tasks/lang.clj

@@ -31,7 +31,7 @@
 
 
 (defn- get-en-categories
 (defn- get-en-categories
   []
   []
-  (->> (rewrite-clj/var-sexp
+  (->> (rewrite-clj/metadata-var-sexp
         "src/main/frontend/modules/shortcut/config.cljs"
         "src/main/frontend/modules/shortcut/config.cljs"
         "category")
         "category")
        (map (fn [[k v]] (vector k (:doc (meta v)))))
        (map (fn [[k v]] (vector k (:doc (meta v)))))

+ 4 - 4
src/main/frontend/components/block.cljs

@@ -817,7 +817,7 @@
     (page-cp config {:block/name namespace})]
     (page-cp config {:block/name namespace})]
    (namespace-hierarchy-aux config namespace children)])
    (namespace-hierarchy-aux config namespace children)])
 
 
-(defn inline
+(defn ^:large-vars/cleanup-todo inline
   [{:keys [html-export?] :as config} item]
   [{:keys [html-export?] :as config} item]
   (match item
   (match item
     ["Plain" s]
     ["Plain" s]
@@ -2171,7 +2171,7 @@
      children)
      children)
     (distinct @refs)))
     (distinct @refs)))
 
 
-(rum/defcs block-container < rum/reactive
+(rum/defcs ^:large-vars/cleanup-todo block-container < rum/reactive
   {:init (fn [state]
   {:init (fn [state]
            (let [[config block] (:rum/args state)]
            (let [[config block] (:rum/args state)]
              (when (and (not (some? (state/sub-collapsed (:block/uuid block))))
              (when (and (not (some? (state/sub-collapsed (:block/uuid block))))
@@ -2468,7 +2468,7 @@
                      result-atom)]
                      result-atom)]
     (assoc state :query-atom query-atom)))
     (assoc state :query-atom query-atom)))
 
 
-(rum/defcs custom-query < rum/reactive
+(rum/defcs ^:large-vars/cleanup-todo custom-query < rum/reactive
   {:will-mount trigger-custom-query!
   {:will-mount trigger-custom-query!
    :did-mount (fn [state]
    :did-mount (fn [state]
                 (when-let [query (last (:rum/args state))]
                 (when-let [query (last (:rum/args state))]
@@ -2652,7 +2652,7 @@
                (when (and (= language "clojure") (contains? (set options) ":results"))
                (when (and (= language "clojure") (contains? (set options) ":results"))
                  (sci/eval-result code)))]))))))
                  (sci/eval-result code)))]))))))
 
 
-(defn markup-element-cp
+(defn ^:large-vars/cleanup-todo markup-element-cp
   [{:keys [html-export?] :as config} item]
   [{:keys [html-export?] :as config} item]
   (let [format (or (:block/format config)
   (let [format (or (:block/format config)
                    :markdown)]
                    :markdown)]

+ 1 - 1
src/main/frontend/components/content.cljs

@@ -146,7 +146,7 @@
                     (reset! edit? true))}
                     (reset! edit? true))}
        "Make template"))))
        "Make template"))))
 
 
-(rum/defc block-context-menu-content
+(rum/defc ^:large-vars/cleanup-todo block-context-menu-content
   [_target block-id]
   [_target block-id]
 
 
   (let [*el-ref (rum/use-ref nil)]
   (let [*el-ref (rum/use-ref nil)]

+ 1 - 1
src/main/frontend/components/editor.cljs

@@ -227,7 +227,7 @@
                            template)
                            template)
             :class       "black"}))))))
             :class       "black"}))))))
 
 
-(rum/defc mobile-bar < rum/reactive
+(rum/defc ^:large-vars/cleanup-todo mobile-bar < rum/reactive
   [_parent-state parent-id]
   [_parent-state parent-id]
   (let [vw-state (state/sub :ui/visual-viewport-state)
   (let [vw-state (state/sub :ui/visual-viewport-state)
         vw-pending? (state/sub :ui/visual-viewport-pending?)
         vw-pending? (state/sub :ui/visual-viewport-pending?)

+ 1 - 1
src/main/frontend/components/onboarding.cljs

@@ -5,7 +5,7 @@
             [rum.core :as rum]
             [rum.core :as rum]
             [frontend.ui :as ui]))
             [frontend.ui :as ui]))
 
 
-(rum/defc intro
+(rum/defc ^:large-vars/cleanup-todo intro
   []
   []
   (rum/with-context [[t] i18n/*tongue-context*]
   (rum/with-context [[t] i18n/*tongue-context*]
     [:div#logseq-intro.pl-1
     [:div#logseq-intro.pl-1

+ 2 - 2
src/main/frontend/components/page.cljs

@@ -359,7 +359,7 @@
 (defonce *orphan-pages? (atom true))
 (defonce *orphan-pages? (atom true))
 (defonce *builtin-pages? (atom nil))
 (defonce *builtin-pages? (atom nil))
 
 
-(rum/defc graph-filters < rum/reactive
+(rum/defc ^:large-vars/cleanup-todo graph-filters < rum/reactive
   [graph settings n-hops]
   [graph settings n-hops]
   (let [{:keys [journal? orphan-pages? builtin-pages?]
   (let [{:keys [journal? orphan-pages? builtin-pages?]
          :or {orphan-pages? true}} settings
          :or {orphan-pages? true}} settings
@@ -662,7 +662,7 @@
                       (notification/show! (str (t :tips/all-done) "!") :success)
                       (notification/show! (str (t :tips/all-done) "!") :success)
                       (js/setTimeout #(refresh-fn) 200)))]])))
                       (js/setTimeout #(refresh-fn) 200)))]])))
 
 
-(rum/defcs all-pages < rum/reactive
+(rum/defcs ^:large-vars/cleanup-todo all-pages < rum/reactive
   (rum/local nil ::pages)
   (rum/local nil ::pages)
   (rum/local nil ::search-key)
   (rum/local nil ::search-key)
   (rum/local nil ::results-all)
   (rum/local nil ::results-all)

+ 2 - 2
src/main/frontend/components/plugins.cljs

@@ -155,7 +155,7 @@
       Meanwhile, make sure you have regular backups of your graphs and only install the plugins when you can read and
       Meanwhile, make sure you have regular backups of your graphs and only install the plugins when you can read and
       understand the source code."]))
       understand the source code."]))
 
 
-(rum/defc plugin-item-card < rum/static
+(rum/defc ^:large-vars/cleanup-todo plugin-item-card < rum/static
   [{:keys [id name title settings version url description author icon usf iir repo sponsors] :as item}
   [{:keys [id name title settings version url description author icon usf iir repo sponsors] :as item}
    market? *search-key has-other-pending?
    market? *search-key has-other-pending?
    installing-or-updating? installed? stat coming-update]
    installing-or-updating? installed? stat coming-update]
@@ -295,7 +295,7 @@
                          (page-handler/init-commands!))
                          (page-handler/init-commands!))
                        true)]])]])))
                        true)]])]])))
 
 
-(rum/defc panel-control-tabs
+(rum/defc ^:large-vars/cleanup-todo panel-control-tabs
   < rum/static
   < rum/static
   [t search-key *search-key category *category
   [t search-key *search-key category *category
    sort-or-filter-by *sort-or-filter-by selected-unpacked-pkg
    sort-or-filter-by *sort-or-filter-by selected-unpacked-pkg

+ 25 - 20
src/main/frontend/components/query_table.cljs

@@ -54,6 +54,28 @@
       (map #(medley/dissoc-in % ks) result)
       (map #(medley/dissoc-in % ks) result)
       result)))
       result)))
 
 
+(defn- sort-by-fn [sort-by-item item]
+  (case sort-by-item
+    :created-at
+    (:block/created-at item)
+    :updated-at
+    (:block/updated-at item)
+    :block
+    (:block/content item)
+    :page
+    (:block/name item)
+    (get-in item [:block/properties key])))
+
+(defn- desc?
+  [*desc? p-desc?]
+  (cond
+    (some? @*desc?)
+    @*desc?
+    (some? p-desc?)
+    p-desc?
+    :else
+    true))
+
 (rum/defcs result-table < rum/reactive
 (rum/defcs result-table < rum/reactive
   (rum/local nil ::sort-by-item)
   (rum/local nil ::sort-by-item)
   (rum/local nil ::desc?)
   (rum/local nil ::desc?)
@@ -66,13 +88,6 @@
           *sort-by-item (get state ::sort-by-item)
           *sort-by-item (get state ::sort-by-item)
           *desc? (get state ::desc?)
           *desc? (get state ::desc?)
           sort-by-item (or @*sort-by-item (some-> p-sort-by keyword) :updated-at)
           sort-by-item (or @*sort-by-item (some-> p-sort-by keyword) :updated-at)
-          desc? (cond
-                  (some? @*desc?)
-                  @*desc?
-                  (some? p-desc?)
-                  p-desc?
-                  :else
-                  true)
           ;; remove templates
           ;; remove templates
           result (remove (fn [b] (some? (get-in b [:block/properties :template]))) result)
           result (remove (fn [b] (some? (get-in b [:block/properties :template]))) result)
           result (if page? result (attach-clock-property result))
           result (if page? result (attach-clock-property result))
@@ -91,19 +106,9 @@
                           (filter included-keys keys)
                           (filter included-keys keys)
                           included-keys)
                           included-keys)
                   keys))
                   keys))
-          sort-by-fn (fn [item]
-                       (let [key sort-by-item]
-                         (case key
-                           :created-at
-                           (:block/created-at item)
-                           :updated-at
-                           (:block/updated-at item)
-                           :block
-                           (:block/content item)
-                           :page
-                           (:block/name item)
-                           (get-in item [:block/properties key]))))
-          result (sort-result-by sort-by-fn desc? result)]
+          result (sort-result-by (partial sort-by-fn sort-by-item)
+                                 (desc? *desc? p-desc?)
+                                 result)]
       [:div.overflow-x-auto {:on-mouse-down (fn [e] (.stopPropagation e))
       [:div.overflow-x-auto {:on-mouse-down (fn [e] (.stopPropagation e))
                              :style {:width "100%"}}
                              :style {:width "100%"}}
        [:table.table-auto
        [:table.table-auto

+ 12 - 11
src/main/frontend/components/repo.cljs

@@ -185,23 +185,24 @@
     (p/let [multiple-windows? (ipc/ipc "graphHasMultipleWindows" (state/get-current-repo))]
     (p/let [multiple-windows? (ipc/ipc "graphHasMultipleWindows" (state/get-current-repo))]
       (reset! (::electron-multiple-windows? state) multiple-windows?))))
       (reset! (::electron-multiple-windows? state) multiple-windows?))))
 
 
+(defn- get-repo-name [repo]
+  (cond
+    (mobile-util/is-native-platform?)
+    (text/get-graph-name-from-path repo)
+
+    (config/local-db? repo)
+    (config/get-local-dir repo)
+
+    :else
+    (db/get-repo-path repo)))
+
 (rum/defcs repos-dropdown < rum/reactive
 (rum/defcs repos-dropdown < rum/reactive
   (rum/local false ::electron-multiple-windows?)
   (rum/local false ::electron-multiple-windows?)
   [state]
   [state]
   (let [multiple-windows? (::electron-multiple-windows? state)]
   (let [multiple-windows? (::electron-multiple-windows? state)]
     (when-let [current-repo (state/sub :git/current-repo)]
     (when-let [current-repo (state/sub :git/current-repo)]
       (rum/with-context [[t] i18n/*tongue-context*]
       (rum/with-context [[t] i18n/*tongue-context*]
-        (let [get-repo-name (fn [repo]
-                              (cond
-                                (mobile-util/is-native-platform?)
-                                (text/get-graph-name-from-path repo)
-
-                                (config/local-db? repo)
-                                (config/get-local-dir repo)
-
-                                :else
-                                (db/get-repo-path repo)))
-              repos (state/sub [:me :repos])
+        (let [repos (state/sub [:me :repos])
               repos (remove (fn [r] (= config/local-repo (:url r))) repos)
               repos (remove (fn [r] (= config/local-repo (:url r))) repos)
               switch-repos (remove (fn [repo]
               switch-repos (remove (fn [repo]
                                      (= current-repo (:url repo)))
                                      (= current-repo (:url repo)))

+ 1 - 1
src/main/frontend/components/search.cljs

@@ -80,7 +80,7 @@
 
 
 (defonce search-timeout (atom nil))
 (defonce search-timeout (atom nil))
 
 
-(rum/defc search-auto-complete
+(rum/defc ^:large-vars/cleanup-todo search-auto-complete
   [{:keys [pages files blocks has-more?] :as result} search-q all?]
   [{:keys [pages files blocks has-more?] :as result} search-q all?]
   (rum/with-context [[t] i18n/*tongue-context*]
   (rum/with-context [[t] i18n/*tongue-context*]
     (let [pages (when-not all? (map (fn [page]
     (let [pages (when-not all? (map (fn [page]

+ 1 - 1
src/main/frontend/components/settings.cljs

@@ -517,7 +517,7 @@
     {:left-label "Plug-in system"
     {:left-label "Plug-in system"
      :action (plugin-enabled-switcher t)}))
      :action (plugin-enabled-switcher t)}))
 
 
-(rum/defcs settings
+(rum/defcs ^:large-vars/cleanup-todo settings
   < (rum/local :general ::active)
   < (rum/local :general ::active)
   {:will-mount
   {:will-mount
    (fn [state]
    (fn [state]

+ 1 - 1
src/main/frontend/db/query_dsl.cljs

@@ -141,7 +141,7 @@
      l)
      l)
     @vars))
     @vars))
 
 
-(defn build-query
+(defn ^:large-vars/cleanup-todo build-query
   ([repo e env]
   ([repo e env]
    (build-query repo e (assoc env :vars (atom {})) 0))
    (build-query repo e (assoc env :vars (atom {})) 0))
   ([repo e {:keys [sort-by blocks? sample counter current-filter vars] :as env} level]
   ([repo e {:keys [sort-by blocks? sample counter current-filter vars] :as env} level]

+ 1 - 1
src/main/frontend/db_schema.cljs

@@ -3,7 +3,7 @@
 (defonce version 1)
 (defonce version 1)
 (defonce ast-version 1)
 (defonce ast-version 1)
 ;; A page is a special block, a page can corresponds to multiple files with the same ":block/name".
 ;; A page is a special block, a page can corresponds to multiple files with the same ":block/name".
-(def schema
+(def ^:large-vars/data-var schema
   {:schema/version  {}
   {:schema/version  {}
    :ast/version     {}
    :ast/version     {}
    :db/type         {}
    :db/type         {}

+ 1 - 1
src/main/frontend/extensions/html_parser.cljs

@@ -20,7 +20,7 @@
 
 
                (str (hiccup-without-style hiccup))))
                (str (hiccup-without-style hiccup))))
 
 
-(defn hiccup->doc-inner
+(defn ^:large-vars/cleanup-todo hiccup->doc-inner
   [format hiccup]
   [format hiccup]
   (let [transform-fn (fn [hiccup]
   (let [transform-fn (fn [hiccup]
                        (hiccup->doc-inner format hiccup))
                        (hiccup->doc-inner format hiccup))

+ 4 - 4
src/main/frontend/extensions/pdf/highlights.cljs

@@ -199,7 +199,7 @@
            :data-color color}])
            :data-color color}])
        rects)]))
        rects)]))
 
 
-(rum/defc pdf-highlight-area-region
+(rum/defc ^:large-vars/cleanup-todo pdf-highlight-area-region
   [^js viewer vw-hl hl
   [^js viewer vw-hl hl
    {:keys [show-ctx-tip! upd-hl!]}]
    {:keys [show-ctx-tip! upd-hl!]}]
 
 
@@ -314,7 +314,7 @@
          (:id hl))
          (:id hl))
        ))])
        ))])
 
 
-(rum/defc pdf-highlight-area-selection
+(rum/defc ^:large-vars/cleanup-todo pdf-highlight-area-selection
   [^js viewer {:keys [show-ctx-tip!]}]
   [^js viewer {:keys [show-ctx-tip!]}]
 
 
   (let [^js viewer-clt (.. viewer -viewer -classList)
   (let [^js viewer-clt (.. viewer -viewer -classList)
@@ -439,7 +439,7 @@
      (when (and start-coord end-coord)
      (when (and start-coord end-coord)
        [:div.shadow-rect {:style (calc-pos start-coord end-coord)}])]))
        [:div.shadow-rect {:style (calc-pos start-coord end-coord)}])]))
 
 
-(rum/defc pdf-highlights
+(rum/defc ^:large-vars/cleanup-todo pdf-highlights
   [^js el ^js viewer initial-hls loaded-pages {:keys [set-dirty-hls!]}]
   [^js el ^js viewer initial-hls loaded-pages {:keys [set-dirty-hls!]}]
 
 
   (let [^js doc (.-ownerDocument el)
   (let [^js doc (.-ownerDocument el)
@@ -791,7 +791,7 @@
   (fn [close-fn!]
   (fn [close-fn!]
     (docinfo-display info close-fn!)))
     (docinfo-display info close-fn!)))
 
 
-(rum/defc pdf-toolbar
+(rum/defc ^:large-vars/cleanup-todo pdf-toolbar
   [^js viewer]
   [^js viewer]
   (let [[area-mode? set-area-mode!] (use-atom *area-mode?)
   (let [[area-mode? set-area-mode!] (use-atom *area-mode?)
         [outline-visible?, set-outline-visible!] (rum/use-state false)
         [outline-visible?, set-outline-visible!] (rum/use-state false)

+ 1 - 1
src/main/frontend/format/block.cljs

@@ -501,7 +501,7 @@
         blocks (map (fn [block] (dissoc block :block/anchor)) blocks)]
         blocks (map (fn [block] (dissoc block :block/anchor)) blocks)]
     (with-path-refs blocks)))
     (with-path-refs blocks)))
 
 
-(defn extract-blocks
+(defn ^:large-vars/cleanup-todo extract-blocks
   [blocks content with-id? format]
   [blocks content with-id? format]
   (try
   (try
     (let [encoded-content (utf8/encode content)
     (let [encoded-content (utf8/encode content)

+ 1 - 1
src/main/frontend/fs/nfs.cljs

@@ -63,7 +63,7 @@
         (= (string/trim decrypted-content) (string/trim db-content)))
         (= (string/trim decrypted-content) (string/trim db-content)))
       (p/resolved (= (string/trim disk-content) (string/trim db-content))))))
       (p/resolved (= (string/trim disk-content) (string/trim db-content))))))
 
 
-(defrecord Nfs []
+(defrecord ^:large-vars/cleanup-todo Nfs []
   protocol/Fs
   protocol/Fs
   (mkdir! [_this dir]
   (mkdir! [_this dir]
     (let [parts (->> (string/split dir "/")
     (let [parts (->> (string/split dir "/")

+ 1 - 1
src/main/frontend/handler/editor.cljs

@@ -3003,7 +3003,7 @@
         :else
         :else
         nil))))
         nil))))
 
 
-(defn keyup-handler
+(defn ^:large-vars/cleanup-todo keyup-handler
   [_state input input-id search-timeout]
   [_state input input-id search-timeout]
   (fn [e key-code]
   (fn [e key-code]
     (when-not (util/event-is-composing? e)
     (when-not (util/event-is-composing? e)

+ 1 - 1
src/main/frontend/state.cljs

@@ -17,7 +17,7 @@
             [rum.core :as rum]
             [rum.core :as rum]
             [frontend.mobile.util :as mobile-util]))
             [frontend.mobile.util :as mobile-util]))
 
 
-(defonce state
+(defonce ^:large-vars/data-var state
   (let [document-mode? (or (storage/get :document/mode?) false)
   (let [document-mode? (or (storage/get :document/mode?) false)
        current-graph (let [graph (storage/get :git/current-repo)]
        current-graph (let [graph (storage/get :git/current-repo)]
                        (when graph (ipc/ipc "setCurrentGraph" graph))
                        (when graph (ipc/ipc "setCurrentGraph" graph))

+ 1 - 1
src/test/frontend/db/query_dsl_test.cljs

@@ -94,7 +94,7 @@ last-modified-at:: 1609084800002"}]]
 
 
 (defonce empty-result {:query nil :result nil})
 (defonce empty-result {:query nil :result nil})
 
 
-(deftest test-parse
+(deftest ^:large-vars/cleanup-todo test-parse
   []
   []
   (testing "nil or blank strings should be ignored"
   (testing "nil or blank strings should be ignored"
     (are [x y] (= (q x) y)
     (are [x y] (= (q x) y)