Browse Source

chore: add workflow for cli linters

Gabriel Horner 3 months ago
parent
commit
f86a7558c8

+ 108 - 0
.github/workflows/cli.yml

@@ -0,0 +1,108 @@
+name: logseq/cli CI
+
+on:
+  # Path filters ensure jobs only kick off if a change is made to cli or
+  # its local dependencies
+  push:
+    branches: [master]
+    paths:
+      - 'deps/cli/**'
+      - '.github/workflows/cli.yml'
+      - '!deps/cli/**.md'
+      # Deps that logseq/cli depends on should trigger this workflow
+      - 'deps/outliner/**'
+      - 'deps/graph-parser/**'
+      - 'deps/db/**'
+      - 'deps/common/**'
+  pull_request:
+    branches: [master]
+    paths:
+      - 'deps/cli/**'
+      - '.github/workflows/cli.yml'
+      - '!deps/cli/**.md'
+      # Deps that logseq/cli depends on should trigger this workflow
+      - 'deps/outliner/**'
+      - 'deps/graph-parser/**'
+      - 'deps/db/**'
+      - 'deps/common/**'
+
+defaults:
+  run:
+    working-directory: deps/cli
+
+env:
+  CLOJURE_VERSION: '1.11.1.1413'
+  # This is the same as 1.8.
+  JAVA_VERSION: '11'
+  # This is the latest node version we can run.
+  NODE_VERSION: '22'
+  BABASHKA_VERSION: '1.0.168'
+
+jobs:
+  test:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+
+      - name: Set up Node
+        uses: actions/setup-node@v3
+        with:
+          node-version: ${{ env.NODE_VERSION }}
+          cache: 'yarn'
+          cache-dependency-path: deps/cli/yarn.lock
+
+      - name: Set up Java
+        uses: actions/setup-java@v3
+        with:
+          distribution: 'zulu'
+          java-version: ${{ env.JAVA_VERSION }}
+
+      # Clojure needed for bb step
+      - name: Set up Clojure
+        uses: DeLaGuardo/[email protected]
+        with:
+          cli: ${{ env.CLOJURE_VERSION }}
+          bb: ${{ env.BABASHKA_VERSION }}
+
+      - name: Fetch yarn deps
+        run: yarn install --frozen-lockfile
+
+      # In this job because it depends on an npm package
+      - name: Load namespaces into nbb-logseq
+        run: bb test:load-all-namespaces-with-nbb .
+
+  lint:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+
+      - name: Set up Java
+        uses: actions/setup-java@v3
+        with:
+          distribution: 'zulu'
+          java-version: ${{ env.JAVA_VERSION }}
+
+      - name: Set up Clojure
+        uses: DeLaGuardo/[email protected]
+        with:
+          cli: ${{ env.CLOJURE_VERSION }}
+          bb: ${{ env.BABASHKA_VERSION }}
+
+      - name: Run clj-kondo lint
+        run: clojure -M:clj-kondo --lint src
+
+      - name: Carve lint for unused vars
+        run: bb lint:carve
+
+      - name: Lint for vars that are too large
+        run: bb lint:large-vars
+
+      - name: Lint for namespaces that aren't documented
+        run: bb lint:ns-docstrings
+
+      - name: Lint for public vars that are private based on usage
+        run: bb lint:minimize-public-vars

+ 30 - 0
deps/cli/bb.edn

@@ -0,0 +1,30 @@
+{:min-bb-version "1.0.168"
+ :deps
+ {logseq/bb-tasks
+  #_{:local/root "../../../bb-tasks"}
+  {:git/url "https://github.com/logseq/bb-tasks"
+   :git/sha "70d3edeb287f5cec7192e642549a401f7d6d4263"}}
+
+ :pods
+ {clj-kondo/clj-kondo {:version "2024.09.27"}}
+
+ :tasks
+ {test:load-all-namespaces-with-nbb
+  logseq.bb-tasks.nbb.test/load-all-namespaces
+
+  lint:large-vars
+  logseq.bb-tasks.lint.large-vars/-main
+
+  lint:carve
+  logseq.bb-tasks.lint.carve/-main
+
+  lint:ns-docstrings
+  logseq.bb-tasks.lint.ns-docstrings/-main
+
+  lint:minimize-public-vars
+  logseq.bb-tasks.lint.minimize-public-vars/-main}
+
+ :tasks/config
+ {:large-vars
+  {:max-lines-count 35
+   :metadata-exceptions #{:large-vars/cleanup-todo}}}}

+ 2 - 2
deps/cli/src/logseq/cli.cljs

@@ -16,13 +16,13 @@
   (println "Usage: logseq [command] [options]\n\nCommands:")
   (println (format-commands {:table table})))
 
-(def table
+(def ^:private table
   [{:cmds ["list"] :fn cli-graph/list-graphs :desc "List graphs"}
    {:cmds ["show"] :fn cli-graph/show-graph :args->opts [:graphs] :desc "Show graph(s) info"
     :coerce {:graphs []}}
    {:cmds []         :fn help}])
 
-(defn -main [& args]
+(defn ^:api -main [& args]
   (cli/dispatch table args {:coerce {:depth :long}}))
 
 #js {:main -main}

+ 1 - 1
deps/cli/src/logseq/cli/commands/graph.cljs

@@ -12,7 +12,7 @@
             [logseq.db.common.sqlite :as common-sqlite]
             [logseq.db.common.sqlite-cli :as sqlite-cli]))
 
-(defn ms->journal-title
+(defn- ms->journal-title
   [ms]
   (date-time-util/format (tc/from-long ms) "MMM do, yyyy"))
 

+ 1 - 1
deps/cli/src/logseq/cli/common/graph.cljs

@@ -7,7 +7,7 @@
             [logseq.common.config :as common-config]
             [logseq.common.graph :as common-graph]))
 
-(defn graph-name->path
+(defn- graph-name->path
   [graph-name]
   (when graph-name
     (-> graph-name