瀏覽代碼

fix: lint warnings in graph_parser

Tienson Qin 3 年之前
父節點
當前提交
c376c408e0

+ 1 - 1
deps/graph-parser/package.json

@@ -6,7 +6,7 @@
     "@logseq/nbb-logseq": "^0.7.133"
   },
   "dependencies": {
-    "mldoc": "^1.3.9"
+    "mldoc": "^1.4.6"
   },
   "scripts": {
     "test": "nbb-logseq -cp src:test:../db/src -m logseq.graph-parser.nbb-test-runner/run-tests"

+ 2 - 3
deps/graph-parser/src/logseq/graph_parser/block.cljs

@@ -177,7 +177,7 @@
          distinct)))
 
 (defn extract-properties
-  [format properties user-config]
+  [properties user-config]
   (when (seq properties)
     (let [properties (seq properties)
           page-refs (get-page-ref-names-from-properties properties user-config)
@@ -495,7 +495,6 @@
 (defn- with-pre-block-if-exists
   [blocks body pre-block-properties encoded-content {:keys [supported-formats db date-formatter user-config]}]
   (let [first-block (first blocks)
-        format (or (:block/format first-block) :markdown)
         first-block-start-pos (get-in first-block [:block/meta :start_pos])
 
         ;; Add pre-block
@@ -613,7 +612,7 @@
                   (recur headings (rest blocks) timestamps' properties body))
 
                 (gp-property/properties-ast? block)
-                (let [properties (extract-properties format (second block) user-config)]
+                (let [properties (extract-properties (second block) user-config)]
                   (recur headings (rest blocks) timestamps properties body))
 
                 (heading-block? block)

+ 1 - 2
deps/graph-parser/src/logseq/graph_parser/extract.cljc

@@ -160,8 +160,7 @@
           _ (when verbose (println "Parsing start: " file))
           ast (gp-mldoc/->edn content (gp-mldoc/default-config format
                                         ;; {:parse_outline_only? true}
-                                        )
-                              user-config)]
+                                        ))]
       (when verbose (println "Parsing finished: " file))
       (let [first-block (ffirst ast)
             properties (let [properties (and (gp-property/properties-ast? first-block)

+ 1 - 14
deps/graph-parser/src/logseq/graph_parser/mldoc.cljc

@@ -10,7 +10,6 @@
             [cljs-bean.core :as bean]
             [logseq.graph-parser.utf8 :as utf8]
             [clojure.string :as string]
-            [linked.core :as linked]
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.config :as gp-config]))
 
@@ -99,22 +98,10 @@
               [block pos-meta])
             [block pos-meta])) ast)))
 
-(defn- ->vec
-  [s]
-  (if (string? s) [s] s))
-
-(defn- ->vec-concat
-  [& coll]
-  (->> (map ->vec coll)
-       (remove nil?)
-       (apply concat)
-       (distinct)))
-
 (defn collect-page-properties
   [ast config]
   (when (seq ast)
     (let [original-ast ast
-          ast (map first ast)           ; without position meta
           directive? (fn [[item _]] (= "directive" (string/lower-case (first item))))
           grouped-ast (group-by directive? original-ast)
           [properties-ast other-ast] [(->> (get grouped-ast true)
@@ -131,7 +118,7 @@
         original-ast))))
 
 (defn ->edn
-  [content config _config-state]
+  [content config]
   (if (string? content)
     (try
       (if (string/blank? content)

+ 2 - 8
deps/graph-parser/src/logseq/graph_parser/text.cljs

@@ -5,8 +5,7 @@
             [clojure.set :as set]
             [logseq.graph-parser.mldoc :as gp-mldoc]
             [logseq.graph-parser.util :as gp-util]
-            [logseq.graph-parser.property :as gp-property]
-            [logseq.graph-parser.util.page-ref :as page-ref :refer [right-brackets]]))
+            [logseq.graph-parser.util.page-ref :as page-ref]))
 
 (defn get-file-basename
   [path]
@@ -95,12 +94,7 @@
     (re-find #"^\d+$" v)
     (parse-long v)))
 
-(def ^:private page-ref-or-tag-re
-  (re-pattern (str "#?" (page-ref/->page-ref-re-str "(.*?)") "|"
-                   ;; Don't capture punctuation at end of a tag
-                   "#([\\S]+[^\\s.!,])")))
-
-(defn- extract-refs-from-mldoc-ast
+(defn extract-refs-from-mldoc-ast
   [v]
   (->> v
        (remove gp-mldoc/ast-link?)

+ 6 - 8
deps/graph-parser/test/logseq/graph_parser/block_test.cljs

@@ -3,7 +3,7 @@
             [cljs.test :refer [deftest are testing is]]))
 
 (deftest test-extract-properties
-  (are [x y] (= (:properties (gp-block/extract-properties :markdown x {})) y)
+  (are [x y] (= (:properties (gp-block/extract-properties x {})) y)
        ;; Built-in properties
        [["background-color" "#000000"]] {:background-color "#000000"}
        [["alias" "name/with space"]] {:alias #{"name/with space"}}
@@ -31,7 +31,7 @@
 
   (testing "page-refs"
     (are [x y] (= (vec (:page-refs
-                        (gp-block/extract-properties :markdown x {:property-pages/enabled? true}))) y)
+                        (gp-block/extract-properties x {:property-pages/enabled? true}))) y)
          [["year" "1000"]] ["year"]
          [["year" "\"1000\""]] ["year"]
          [["year" "1000"] ["month" "12"]] ["year" "month"]
@@ -43,29 +43,27 @@
 
 
     (are [x y] (= (vec (:page-refs
-                        (gp-block/extract-properties :markdown x {:property-pages/enabled? false}))) y)
+                        (gp-block/extract-properties x {:property-pages/enabled? false}))) y)
          [["year" "1000"]] []
          [["year" "1000"] ["month" "12"]] []
          [["foo" "[[bar]] test"]] ["bar" "test"])
 
     (is (= ["year"]
            (:page-refs
-            (gp-block/extract-properties :markdown
-                                         [["year" "1000"] ["month" "12"]]
+            (gp-block/extract-properties [["year" "1000"] ["month" "12"]]
                                          {:property-pages/enabled? true
                                           :property-pages/excludelist #{:month :day}})))
         ":property-pages/exclude-list excludes specified properties")
 
     (is (= ["year"]
            (:page-refs
-            (gp-block/extract-properties :markdown
-                                         [["year" "1000"]]
+            (gp-block/extract-properties [["year" "1000"]]
                                          {})))
         "Default to enabled when :property-pages/enabled? is not in config")
 
     (is (= ["foo" "bar"]
            (:page-refs
-            (gp-block/extract-properties :markdown
+            (gp-block/extract-properties
                                          ;; tags is linkable and background-color is not
                                          [["tags" "foo, bar"] ["background-color" "#008000"]]
                                          {:property-pages/enabled? true})))

+ 6 - 7
deps/graph-parser/test/logseq/graph_parser/mldoc_test.cljs

@@ -51,7 +51,7 @@
           {:start_pos 0, :end_pos 15}]
          (first (gp-mldoc/->edn "```
 : hello
-```" md-config {})))
+```" md-config)))
       "Basic src example")
 
   (is (= [["Src"
@@ -64,12 +64,12 @@
   hello
   world
   ```
-" md-config {})))
+" md-config)))
       "Src example with leading whitespace"))
 
 (deftest md-properties-test
   (are [x y] (= [["Properties" y] nil]
-                (first (gp-mldoc/->edn x md-config {})))
+                (first (gp-mldoc/->edn x md-config)))
 
        ;; comma separates values
        "property:: foo, bar"
@@ -96,11 +96,11 @@
              :ordered false}]]
           {:start_pos 0, :end_pos 17}]
          (first (gp-mldoc/->edn "term
-: definition" md-config {})))))
+: definition" md-config)))))
 
 (defn- parse-properties
   [text]
-  (->> (gp-mldoc/->edn text (gp-mldoc/default-config :org) {})
+  (->> (gp-mldoc/->edn text (gp-mldoc/default-config :org))
        (filter #(= "Properties" (ffirst %)))
        ffirst
        second))
@@ -130,8 +130,7 @@ body"
                                                 :org :markdown)]
                                    [path
                                     (gp-mldoc/->edn content
-                                                    (gp-mldoc/default-config format)
-                                                    {})])))
+                                                    (gp-mldoc/default-config format))])))
                           (into {}))]
     (is (= {"CommentBlock" 1,
             "Custom" 41,

+ 3 - 3
deps/graph-parser/test/logseq/graph_parser/text_test.cljs

@@ -1,5 +1,5 @@
 (ns logseq.graph-parser.text-test
-  (:require [cljs.test :refer [are deftest testing is]]
+  (:require [cljs.test :refer [are deftest testing]]
             [logseq.graph-parser.text :as text]))
 
 (deftest test-get-page-name
@@ -61,7 +61,7 @@
 
 (deftest test-parse-property
   (testing "parse-property"
-    (are [k v y] (= (text/parse-property k v {}) y)
+    (are [k v y] (= (text/parse-property k v [] {}) y)
       :tags "foo" "foo"
       :tags "foo, bar" #{"foo" "bar"}
       :tags "foo,bar" #{"foo" "bar"}
@@ -73,7 +73,7 @@
       :tags "[[foo [[bar]]]]" #{"foo [[bar]]"}
       :tags "[[foo [[bar]]]], baz" #{"baz" "foo [[bar]]"}))
   (testing "parse-property with quoted strings"
-    (are [k v y] (= (text/parse-property k v {}) y)
+    (are [k v y] (= (text/parse-property k v [] {}) y)
       :tags "\"foo, bar\"" "\"foo, bar\""
       :tags "\"[[foo]], [[bar]]\"" "\"[[foo]], [[bar]]\""
       :tags "baz, \"[[foo]], [[bar]]\"" #{"baz"})))

+ 1 - 2
src/main/frontend/format/mldoc.cljs

@@ -2,7 +2,6 @@
   "Mldoc code needed by app but not graph-parser"
   (:require [clojure.string :as string]
             [frontend.format.protocol :as protocol]
-            [frontend.state :as state]
             [goog.object :as gobj]
             [lambdaisland.glogi :as log]
             ["mldoc" :as mldoc :refer [Mldoc]]
@@ -53,7 +52,7 @@
 (defn ->edn
   "Wrapper around gp-mldoc/->edn which provides config state"
   [content config]
-  (gp-mldoc/->edn content config (state/get-config)))
+  (gp-mldoc/->edn content config))
 
 (defrecord MldocMode []
   protocol/Format