From bc18661c90ff9bbb410017d0349eb4a6d2b113aa Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Wed, 21 Aug 2024 13:33:01 -0400 Subject: [PATCH] enhance(dev): Add fast kondo lint for dev --- bb.edn | 3 +++ docs/dev-practices.md | 6 ++++-- scripts/src/logseq/tasks/dev/lint.clj | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/bb.edn b/bb.edn index 0c202959c6..96bf36f6f0 100644 --- a/bb.edn +++ b/bb.edn @@ -152,6 +152,9 @@ lint:dev logseq.tasks.dev.lint/dev + lint:kondo-git-changes + logseq.tasks.dev.lint/kondo-git-changes + lint:large-vars logseq.bb-tasks.lint.large-vars/-main diff --git a/docs/dev-practices.md b/docs/dev-practices.md index 1f25bc9452..856f8812ea 100644 --- a/docs/dev-practices.md +++ b/docs/dev-practices.md @@ -14,11 +14,13 @@ bb lint:dev To lint: ```sh -clojure -M:clj-kondo --parallel --lint src --cache false +clojure -M:clj-kondo --parallel --lint src ``` We lint our Clojure(Script) code with https://github.com/clj-kondo/clj-kondo/. If you need to configure specific linters, see [this documentation](https://github.com/clj-kondo/clj-kondo/blob/master/doc/linters.md). Where possible, a global linting configuration is used and namespace specific configuration is avoided. +For engineers, there is a faster version of this command that only checks files that you have changed: `bb lint:kondo-git-changes`. + There are outstanding linting items that are currently ignored to allow linting the rest of the codebase in CI. These outstanding linting items should be addressed at some point: * Comments starting with `TODO:lint` @@ -313,7 +315,7 @@ We strive to use explicit names that are self explanatory so that our codebase i ### Babashka tasks -There are a number of bb tasks under `dev:` for developers. Some useful ones to +There are a number of bb tasks under `dev:` for development. Some useful ones to point out: * `dev:validate-repo-config-edn` - Validate a repo config.edn diff --git a/scripts/src/logseq/tasks/dev/lint.clj b/scripts/src/logseq/tasks/dev/lint.clj index 4ebd1b5858..5db8c975ad 100644 --- a/scripts/src/logseq/tasks/dev/lint.clj +++ b/scripts/src/logseq/tasks/dev/lint.clj @@ -21,6 +21,20 @@ (println cmd) (shell cmd))) +(defn kondo-git-changes + "Run clj-kondo only for files that git diff detects as changed and unstaged" + [] + (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.")))) + (defn- validate-frontend-not-in-worker [] (let [res (shell {:out :string}