Sfoglia il codice sorgente

fix: ns-docstring and large-var deps lints

Also fixed db-and-file-graphs-separate lint and moved gp-property tests
that should be moved since their source code has moved from frontend
to gp-property
Gabriel Horner 2 anni fa
parent
commit
951e7cc841

+ 42 - 36
deps/graph-parser/src/logseq/graph_parser/property.cljs

@@ -183,6 +183,41 @@
    (and (string? line)
         (common-util/safe-re-find #"^\s*[^ ]+:" line))))
 
+(defn- insert-property-not-org
+  [key* value lines {:keys [front-matter? has-properties? title?]}]
+  (let [exists? (atom false)
+        sym (if front-matter? ": " (str colons " "))
+        new-property-s (str key* sym value)
+        property-f (if front-matter? front-matter-property? simplified-property?)
+        groups (partition-by property-f lines)
+        compose-lines (fn []
+                        (mapcat (fn [lines]
+                                  (if (property-f (first lines))
+                                    (let [lines (doall
+                                                 (mapv (fn [text]
+                                                         (let [[k v] (common-util/split-first sym text)]
+                                                           (if (and k v)
+                                                             (let [key-exists? (= k key)
+                                                                   _ (when key-exists? (reset! exists? true))
+                                                                   v (if key-exists? value v)]
+                                                               (str k sym  (string/trim v)))
+                                                             text)))
+                                                       lines))
+                                          lines (if @exists? lines (conj lines new-property-s))]
+                                      lines)
+                                    lines))
+                                groups))
+        lines (cond
+                has-properties?
+                (compose-lines)
+
+                title?
+                (cons (first lines) (cons new-property-s (rest lines)))
+
+                :else
+                (cons new-property-s lines))]
+    (string/join "\n" lines)))
+
 (defn insert-property
   "Only accept nake content (without any indentation)"
   ([repo format content key value]
@@ -194,10 +229,10 @@
            has-properties? (or (and title?
                                     (or (gp-mldoc/properties? (second ast))
                                         (gp-mldoc/properties? (second
-                                                            (remove
-                                                             (fn [[x _]]
-                                                               (contains? #{"Hiccup" "Raw_Html"} (first x)))
-                                                             ast)))))
+                                                               (remove
+                                                                (fn [[x _]]
+                                                                  (contains? #{"Hiccup" "Raw_Html"} (first x)))
+                                                                ast)))))
                                (gp-mldoc/properties? (first ast)))
            lines (string/split-lines content)
            [title body] (gp-mldoc/get-title&body repo content format)
@@ -238,38 +273,9 @@
                       (string/join "\n" lines))
 
                     (not org?)
-                    (let [exists? (atom false)
-                          sym (if front-matter? ": " (str colons " "))
-                          new-property-s (str key sym value)
-                          property-f (if front-matter? front-matter-property? simplified-property?)
-                          groups (partition-by property-f lines)
-                          compose-lines (fn []
-                                          (mapcat (fn [lines]
-                                                    (if (property-f (first lines))
-                                                      (let [lines (doall
-                                                                   (mapv (fn [text]
-                                                                           (let [[k v] (common-util/split-first sym text)]
-                                                                             (if (and k v)
-                                                                               (let [key-exists? (= k key)
-                                                                                     _ (when key-exists? (reset! exists? true))
-                                                                                     v (if key-exists? value v)]
-                                                                                 (str k sym  (string/trim v)))
-                                                                               text)))
-                                                                         lines))
-                                                            lines (if @exists? lines (conj lines new-property-s))]
-                                                        lines)
-                                                      lines))
-                                                  groups))
-                          lines (cond
-                                  has-properties?
-                                  (compose-lines)
-
-                                  title?
-                                  (cons (first lines) (cons new-property-s (rest lines)))
-
-                                  :else
-                                  (cons new-property-s lines))]
-                      (string/join "\n" lines))
+                    (insert-property-not-org key value lines {:has-properties? has-properties?
+                                                              :title? title?
+                                                              :front-matter? front-matter?})
 
                     :else
                     content)]

+ 117 - 1
deps/graph-parser/test/logseq/graph_parser/property_test.cljs

@@ -1,7 +1,9 @@
 (ns logseq.graph-parser.property-test
-  (:require [cljs.test :refer [are deftest]]
+  (:require [cljs.test :refer [are deftest testing]]
             [logseq.graph-parser.property :as gp-property]))
 
+(def test-db "test-db")
+
 (deftest test->new-properties
   (are [x y] (= (gp-property/->new-properties x) y)
     ":PROPERTIES:\n:foo: bar\n:END:"
@@ -24,3 +26,117 @@
 
     "hello\n:PROPERTIES:\n:foo: bar\n:nice\n:END:\nnice"
     "hello\nfoo:: bar\n:nice\nnice"))
+
+(deftest test-insert-property
+  (are [x y] (= x y)
+    (gp-property/insert-property test-db :org "hello" "a" "b")
+    "hello\n:PROPERTIES:\n:a: b\n:END:"
+
+    (gp-property/insert-property test-db :org "hello" "a" false)
+    "hello\n:PROPERTIES:\n:a: false\n:END:"
+
+    (gp-property/insert-property test-db :org "hello\n:PROPERTIES:\n:a: b\n:END:\n" "c" "d")
+    "hello\n:PROPERTIES:\n:a: b\n:c: d\n:END:"
+
+    (gp-property/insert-property test-db :org "hello\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
+    "hello\n:PROPERTIES:\n:a: b\n:c: d\n:END:\nworld"
+
+    (gp-property/insert-property test-db :org "#+BEGIN_QUOTE
+ hello world
+  #+END_QUOTE" "c" "d")
+    ":PROPERTIES:\n:c: d\n:END:\n#+BEGIN_QUOTE\n hello world\n  #+END_QUOTE"
+
+    (gp-property/insert-property test-db :org "hello
+DEADLINE: <2021-10-25 Mon>
+SCHEDULED: <2021-10-25 Mon>" "a" "b")
+    "hello\nSCHEDULED: <2021-10-25 Mon>\nDEADLINE: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:"
+
+    (gp-property/insert-property test-db :org "hello
+DEADLINE: <2021-10-25 Mon>
+SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\n" "c" "d")
+    "hello\nDEADLINE: <2021-10-25 Mon>\nSCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:c: d\n:END:"
+
+    (gp-property/insert-property test-db :org "hello
+DEADLINE: <2021-10-25 Mon>
+SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
+    "hello\nDEADLINE: <2021-10-25 Mon>\nSCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:c: d\n:END:\nworld"
+
+    (gp-property/insert-property test-db :markdown "hello\na:: b\nworld\n" "c" "d")
+    "hello\na:: b\nc:: d\nworld"
+
+    (gp-property/insert-property test-db :markdown "> quote" "c" "d")
+    "c:: d\n> quote"
+
+    (gp-property/insert-property test-db :markdown "#+BEGIN_QUOTE
+ hello world
+  #+END_QUOTE" "c" "d")
+    "c:: d\n#+BEGIN_QUOTE\n hello world\n  #+END_QUOTE"))
+
+(deftest test-insert-properties
+  (are [x y] (= x y)
+    (gp-property/insert-properties test-db :markdown "" {:foo "bar"})
+    "foo:: bar"
+
+    (gp-property/insert-properties test-db :markdown "" {"foo" "bar"})
+    "foo:: bar"
+
+    (gp-property/insert-properties test-db :markdown "" {"foo space" "bar"})
+    "foo-space:: bar"
+
+    (gp-property/insert-properties test-db :markdown "" {:foo #{"bar" "baz"}})
+    "foo:: [[bar]], [[baz]]"
+
+    (gp-property/insert-properties test-db :markdown "" {:foo ["bar" "bar" "baz"]})
+    "foo:: [[bar]], [[baz]]"
+
+    (gp-property/insert-properties test-db :markdown "a\nb\n" {:foo ["bar" "bar" "baz"]})
+    "a\nfoo:: [[bar]], [[baz]]\nb"
+
+    (gp-property/insert-properties test-db :markdown "" {:foo "\"bar, baz\""})
+    "foo:: \"bar, baz\""
+
+    (gp-property/insert-properties test-db :markdown "abcd\nempty::" {:id "123" :foo "bar"})
+    "abcd\nempty::\nid:: 123\nfoo:: bar"
+
+    (gp-property/insert-properties test-db :markdown "abcd\nempty:: " {:id "123" :foo "bar"})
+    "abcd\nempty:: \nid:: 123\nfoo:: bar"
+
+    (gp-property/insert-properties test-db :markdown "abcd\nempty::" {:id "123"})
+    "abcd\nempty::\nid:: 123"
+
+    (gp-property/insert-properties test-db :markdown "abcd\nempty::\nanother-empty::" {:id "123"})
+    "abcd\nempty::\nanother-empty::\nid:: 123"))
+
+(deftest test-remove-properties
+  (testing "properties with non-blank lines"
+    (are [x y] (= x y)
+      (gp-property/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\n:END:\n")
+      "** hello"
+
+      (gp-property/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\na:b\n:END:\n")
+      "** hello"
+
+      (gp-property/remove-properties :markdown "** hello\nx:: y\na:: b\n")
+      "** hello"
+
+      (gp-property/remove-properties :markdown "** hello\nx:: y\na::b\n")
+      "** hello"))
+
+  (testing "properties with blank lines"
+    (are [x y] (= x y)
+      (gp-property/remove-properties :org "** hello\n:PROPERTIES:\n\n:x: y\n:END:\n")
+      "** hello"
+
+      (gp-property/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\n\na:b\n:END:\n")
+      "** hello"))
+
+  (testing "invalid-properties"
+    (are [x y] (= x y)
+      (gp-property/remove-properties :markdown "hello\nnice\nfoo:: bar")
+      "hello\nnice\nfoo:: bar"
+
+      (gp-property/remove-properties :markdown "hello\nnice\nfoo:: bar\ntest")
+      "hello\nnice\nfoo:: bar\ntest"
+
+      (gp-property/remove-properties :markdown "** hello\nx:: y\n\na:: b\n")
+      "** hello\n\na:: b")))

+ 4 - 1
deps/outliner/bb.edn

@@ -26,4 +26,7 @@
 
  :tasks/config
  {:large-vars
-  {:max-lines-count 55}}}
+  {:max-lines-count 55
+   ;; TODO: Remove this once outliner.core-test is in dep and these
+   ;; fns can be easily refactored
+   :metadata-exceptions #{:large-vars/cleanup-todo}}}}

+ 4 - 3
deps/outliner/src/logseq/outliner/core.cljs

@@ -1,4 +1,5 @@
 (ns logseq.outliner.core
+  "Provides the primary outliner operations and fns"
   (:require [clojure.set :as set]
             [clojure.string :as string]
             [datascript.impl.entity :as de]
@@ -713,7 +714,7 @@
               m' (vec (conj m block))]
           (recur m' (rest blocks)))))))
 
-(defn insert-blocks
+(defn ^:large-vars/cleanup-todo insert-blocks
   "Insert blocks as children (or siblings) of target-node.
   Args:
     `conn`: db connection.
@@ -851,7 +852,7 @@
           (otree/-save new-right-node txs-state conn repo date-formatter)))
       @txs-state)))
 
-(defn- delete-blocks
+(defn- ^:large-vars/cleanup-todo delete-blocks
   "Delete blocks from the tree.
    Args:
     `children?`: whether to replace `blocks'` children too. "
@@ -1003,7 +1004,7 @@
           (move-blocks repo conn blocks right (merge opts {:sibling? sibling?
                                                            :up? up?})))))))
 
-(defn indent-outdent-blocks
+(defn ^:large-vars/cleanup-todo indent-outdent-blocks
   "Indent or outdent `blocks`."
   [repo conn blocks indent? & {:keys [get-first-block-original logical-outdenting?]}]
   {:pre [(seq blocks) (boolean? indent?)]}

+ 1 - 0
deps/outliner/src/logseq/outliner/datascript.cljs

@@ -1,4 +1,5 @@
 (ns logseq.outliner.datascript
+  "Provides fns related to wrapping datascript's transact!"
   (:require [logseq.common.util :as common-util]
             [logseq.common.util.block-ref :as block-ref]
             [logseq.db.sqlite.util :as sqlite-util]

+ 2 - 0
deps/outliner/src/logseq/outliner/transaction.cljc

@@ -1,4 +1,6 @@
 (ns logseq.outliner.transaction
+  "Provides a wrapper around logseq.outliner.datascript/transact! using
+   transient state from logseq.outliner.core"
   #?(:cljs (:require-macros [logseq.outliner.transaction]))
   #?(:cljs (:require [malli.core :as m])))
 

+ 1 - 0
deps/outliner/src/logseq/outliner/tree.cljs

@@ -1,4 +1,5 @@
 (ns logseq.outliner.tree
+  "Provides tree fns and INode protocol"
   (:require [logseq.db :as ldb]
             [clojure.string :as string]
             [logseq.db.frontend.property :as db-property]

+ 1 - 0
deps/outliner/src/logseq/outliner/util.cljs

@@ -1,4 +1,5 @@
 (ns logseq.outliner.util
+  "Util fns for outliner"
   (:require [datascript.impl.entity :as e]
             [logseq.common.util :as common-util]))
 

+ 10 - 1
src/main/frontend/handler/block.cljs

@@ -10,8 +10,10 @@
    [frontend.modules.outliner.ui :as ui-outliner-tx]
    [frontend.state :as state]
    [frontend.util :as util]
+   [frontend.util.drawer :as drawer]
    [goog.dom :as gdom]
    [logseq.graph-parser.block :as gp-block]
+   [logseq.db.sqlite.util :as sqlite-util]
    [frontend.config :as config]
    [frontend.handler.file-based.property.util :as property-util]
    [frontend.handler.property.util :as pu]
@@ -214,6 +216,13 @@
         (mark-last-input-time! repo)
         (util/schedule (fn [] (edit-block-aux repo block content block-node text-range (update opts :retry-times inc))))))))
 
+(defn sanity-block-content
+  [repo format content]
+  (if (sqlite-util/db-based-graph? repo)
+    content
+    (-> (property-util/remove-built-in-properties format content)
+        (drawer/remove-logbook))))
+
 (defn edit-block!
   [block pos block-node & {:keys [custom-content tail-len _direction]
                            :or {tail-len 0}
@@ -246,7 +255,7 @@
 
                          :else
                          (subs content 0 pos))
-            content (property-util/sanity-block-content repo (:block/format block) content)]
+            content (sanity-block-content repo (:block/format block) content)]
         (state/clear-selection!)
         (edit-block-aux repo block content block-node text-range opts)))))
 

+ 2 - 11
src/main/frontend/handler/file_based/property/util.cljs

@@ -8,9 +8,7 @@
             [frontend.format.mldoc :as mldoc]
             [frontend.db :as db]
             [frontend.state :as state]
-            [frontend.util.cursor :as cursor]
-            [logseq.db.sqlite.util :as sqlite-util]
-            [frontend.util.drawer :as drawer]))
+            [frontend.util.cursor :as cursor]))
 
 (defn hidden-properties
   "These are properties hidden from user including built-in ones and ones
@@ -237,11 +235,4 @@
     (if (seq properties-order)
       (keep (fn [k] (when (contains? properties k) [k (get properties k)]))
             (distinct properties-order))
-      properties*)))
-
-(defn sanity-block-content
-  [repo format content]
-  (if (sqlite-util/db-based-graph? repo)
-    content
-    (-> (remove-built-in-properties format content)
-        (drawer/remove-logbook))))
+      properties*)))

+ 0 - 114
src/test/frontend/util/property_test.cljs

@@ -37,40 +37,6 @@
       "* TODO properties demo\n:PROPERTIES:\n\n:END:\n\n\nabcd"
       "* TODO properties demo\nabcd")))
 
-(deftest test-remove-properties
-  (testing "properties with non-blank lines"
-    (are [x y] (= x y)
-      (property-util/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\n:END:\n")
-      "** hello"
-
-      (property-util/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\na:b\n:END:\n")
-      "** hello"
-
-      (property-util/remove-properties :markdown "** hello\nx:: y\na:: b\n")
-      "** hello"
-
-      (property-util/remove-properties :markdown "** hello\nx:: y\na::b\n")
-      "** hello"))
-
-  (testing "properties with blank lines"
-    (are [x y] (= x y)
-      (property-util/remove-properties :org "** hello\n:PROPERTIES:\n\n:x: y\n:END:\n")
-      "** hello"
-
-      (property-util/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\n\na:b\n:END:\n")
-      "** hello"))
-
-  (testing "invalid-properties"
-    (are [x y] (= x y)
-      (property-util/remove-properties :markdown "hello\nnice\nfoo:: bar")
-      "hello\nnice\nfoo:: bar"
-
-      (property-util/remove-properties :markdown "hello\nnice\nfoo:: bar\ntest")
-      "hello\nnice\nfoo:: bar\ntest"
-
-      (property-util/remove-properties :markdown "** hello\nx:: y\n\na:: b\n")
-      "** hello\n\na:: b")))
-
 (deftest test-get-property-keys
   (testing "org mode"
     (are [x y] (= x y)
@@ -87,86 +53,6 @@
         (#'property-util/get-property-keys :markdown "hello\n")
         nil)))
 
-(deftest test-insert-property
-  (are [x y] (= x y)
-    (property-util/insert-property :org "hello" "a" "b")
-    "hello\n:PROPERTIES:\n:a: b\n:END:"
-
-    (property-util/insert-property :org "hello" "a" false)
-    "hello\n:PROPERTIES:\n:a: false\n:END:"
-
-    (property-util/insert-property :org "hello\n:PROPERTIES:\n:a: b\n:END:\n" "c" "d")
-    "hello\n:PROPERTIES:\n:a: b\n:c: d\n:END:"
-
-    (property-util/insert-property :org "hello\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
-    "hello\n:PROPERTIES:\n:a: b\n:c: d\n:END:\nworld"
-
-    (property-util/insert-property :org "#+BEGIN_QUOTE
- hello world
-  #+END_QUOTE" "c" "d")
-    ":PROPERTIES:\n:c: d\n:END:\n#+BEGIN_QUOTE\n hello world\n  #+END_QUOTE"
-
-     (property-util/insert-property :org "hello
-DEADLINE: <2021-10-25 Mon>
-SCHEDULED: <2021-10-25 Mon>" "a" "b")
-    "hello\nSCHEDULED: <2021-10-25 Mon>\nDEADLINE: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:"
-
-    (property-util/insert-property :org "hello
-DEADLINE: <2021-10-25 Mon>
-SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\n" "c" "d")
-    "hello\nDEADLINE: <2021-10-25 Mon>\nSCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:c: d\n:END:"
-
-    (property-util/insert-property :org "hello
-DEADLINE: <2021-10-25 Mon>
-SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
-    "hello\nDEADLINE: <2021-10-25 Mon>\nSCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:c: d\n:END:\nworld"
-
-    (property-util/insert-property :markdown "hello\na:: b\nworld\n" "c" "d")
-    "hello\na:: b\nc:: d\nworld"
-
-    (property-util/insert-property :markdown "> quote" "c" "d")
-    "c:: d\n> quote"
-
-    (property-util/insert-property :markdown "#+BEGIN_QUOTE
- hello world
-  #+END_QUOTE" "c" "d")
-    "c:: d\n#+BEGIN_QUOTE\n hello world\n  #+END_QUOTE"))
-
-(deftest test-insert-properties
-  (are [x y] (= x y)
-    (property-util/insert-properties :markdown "" {:foo "bar"})
-    "foo:: bar"
-
-    (property-util/insert-properties :markdown "" {"foo" "bar"})
-    "foo:: bar"
-
-    (property-util/insert-properties :markdown "" {"foo space" "bar"})
-    "foo-space:: bar"
-
-    (property-util/insert-properties :markdown "" {:foo #{"bar" "baz"}})
-    "foo:: [[bar]], [[baz]]"
-
-    (property-util/insert-properties :markdown "" {:foo ["bar" "bar" "baz"]})
-    "foo:: [[bar]], [[baz]]"
-
-    (property-util/insert-properties :markdown "a\nb\n" {:foo ["bar" "bar" "baz"]})
-    "a\nfoo:: [[bar]], [[baz]]\nb"
-
-    (property-util/insert-properties :markdown "" {:foo "\"bar, baz\""})
-    "foo:: \"bar, baz\""
-
-    (property-util/insert-properties :markdown "abcd\nempty::" {:id "123" :foo "bar"})
-    "abcd\nempty::\nid:: 123\nfoo:: bar"
-
-    (property-util/insert-properties :markdown "abcd\nempty:: " {:id "123" :foo "bar"})
-    "abcd\nempty:: \nid:: 123\nfoo:: bar"
-
-    (property-util/insert-properties :markdown "abcd\nempty::" {:id "123"})
-    "abcd\nempty::\nid:: 123"
-
-    (property-util/insert-properties :markdown "abcd\nempty::\nanother-empty::" {:id "123"})
-    "abcd\nempty::\nanother-empty::\nid:: 123"))
-
 (deftest test-build-properties-str
   (are [x y] (= (#'gp-property/build-properties-str :mardown x) y)
     {:title "a"}