Просмотр исходного кода

enhance(dev): extend fast kondo lint to run across all kondo dirs

Gabriel Horner 1 год назад
Родитель
Сommit
e16c880280
1 измененных файлов с 18 добавлено и 11 удалено
  1. 18 11
      scripts/src/logseq/tasks/dev/lint.clj

+ 18 - 11
scripts/src/logseq/tasks/dev/lint.clj

@@ -22,18 +22,25 @@
     (shell cmd)))
 
 (defn kondo-git-changes
-  "Run clj-kondo only for files that git diff detects as changed and unstaged"
+  "Run clj-kondo across dirs and only for files that git diff detects as unstaged changes"
   []
-  (let [files (->> (shell {:out :string} "git diff --name-only")
-                   :out
-                   string/split-lines
-                   (filter #(string/starts-with? % "src")))]
-    (if (seq files)
-      (let [cmd (str "clj-kondo --lint " (string/join " " files))
-            _ (println cmd)
-            res (apply shell {:continue :true} "clj-kondo --lint" files)]
-        (System/exit (:exit res)))
-      (println "No files have changed to lint."))))
+  (let [kondo-dirs ["src" "deps/common" "deps/db" "deps/graph-parser" "deps/outliner" "deps/publishing"]
+        dir-regex (re-pattern (str "^(" (string/join "|" kondo-dirs) ")"))
+        dir-to-files (->> (shell {:out :string} "git diff --name-only")
+                          :out
+                          string/split-lines
+                          (group-by #(first (re-find dir-regex %)))
+                          ;; remove files that aren't in a kondo dir
+                          ((fn [x] (dissoc x nil))))]
+    (if (seq dir-to-files)
+        (doseq [[dir* files*] dir-to-files]
+          (let [dir (if (= dir* "src") "." dir*)
+                files (mapv #(string/replace-first % (str dir "/") "") files*)
+                cmd (str "cd " dir " && clj-kondo --lint " (string/join " " files))
+               _ (println cmd)
+               res (apply shell {:dir dir :continue :true} "clj-kondo --lint" files)]
+           (when (pos? (:exit res)) (System/exit (:exit res)))))
+        (println "No files have changed to lint."))))
 
 (defn- validate-frontend-not-in-worker
   []