From e16c88028011bfdb799b37a7342ad6e4a86ae3b3 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Wed, 21 Aug 2024 21:43:12 -0400 Subject: [PATCH] enhance(dev): extend fast kondo lint to run across all kondo dirs --- scripts/src/logseq/tasks/dev/lint.clj | 29 +++++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/scripts/src/logseq/tasks/dev/lint.clj b/scripts/src/logseq/tasks/dev/lint.clj index 5db8c975a..6e940b347 100644 --- a/scripts/src/logseq/tasks/dev/lint.clj +++ b/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 []