From 14a507f4cd03bb28eab5a3e53fd7fc8266c10440 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Tue, 20 Aug 2024 10:08:36 -0400 Subject: [PATCH] enhance(dev): run lint fix with an option Linters are read only by default. Lang lint can be fixed by passing `--fix`. We don't want CI or inexperienced contributors fixing files accidentally. Also move deps to bb.edn as putting them inline leads to quirky/buggy tasks listing and autocompleting as they pause when fetching an inlined dep --- bb.edn | 1 + docs/contributing-to-translations.md | 2 ++ scripts/src/logseq/tasks/lang.clj | 16 +++++++--------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/bb.edn b/bb.edn index de3276f5a8..0c202959c6 100644 --- a/bb.edn +++ b/bb.edn @@ -2,6 +2,7 @@ :deps {metosin/malli {:mvn/version "0.16.1"} + borkdude/rewrite-edn {:mvn/version "0.4.8"} logseq/bb-tasks #_{:local/root "../bb-tasks"} {:git/url "https://github.com/logseq/bb-tasks" diff --git a/docs/contributing-to-translations.md b/docs/contributing-to-translations.md index 8d8c1a0969..c052ab6aac 100644 --- a/docs/contributing-to-translations.md +++ b/docs/contributing-to-translations.md @@ -102,6 +102,8 @@ you'll need to ensure it doesn't fail. Mistakes that it catches: [lang.clj](https://github.com/logseq/logseq/blob/master/scripts/src/logseq/tasks/lang.clj) for your language with a list of duplicated entries e.g. `:nb-NO #{:port ...}`. +Nonexistent entries can be removed by running `bb lang:validate-translations --fix`. + ## Add a Language To add a new language: diff --git a/scripts/src/logseq/tasks/lang.clj b/scripts/src/logseq/tasks/lang.clj index 928a5734b2..5a91e5634f 100644 --- a/scripts/src/logseq/tasks/lang.clj +++ b/scripts/src/logseq/tasks/lang.clj @@ -7,11 +7,7 @@ [babashka.cli :as cli] [babashka.process :refer [shell]] [babashka.fs :as fs] - [babashka.deps :as deps])) - -(deps/add-deps '{:deps {borkdude/rewrite-edn {:mvn/version "0.4.8"}}}) -(require '[borkdude.rewrite-edn :as r]) - + [borkdude.rewrite-edn :as r])) (defn- get-dicts [] @@ -147,7 +143,7 @@ "This validation checks to see that translations done by (t ...) are equal to the ones defined for the default :en lang. This catches translations that have been added in UI but don't have an entry or translations no longer used in the UI" - [] + [{:keys [fix?]}] (let [actual-dicts (->> (shell {:out :string} ;; This currently assumes all ui translations ;; use (t and src/main. This can easily be @@ -174,7 +170,9 @@ (when (seq expected-only) (println "\nThese translation keys are invalid because they are not used in the UI:") (task-util/print-table (map #(hash-map :invalid-key %) expected-only)) - (delete-not-used-key-from-dict-file expected-only)) + (when fix? + (delete-not-used-key-from-dict-file expected-only) + (println "These invalid keys have been removed."))) (System/exit 1))))) (def allowed-duplicates @@ -230,7 +228,7 @@ (defn validate-translations "Runs multiple translation validations that fail fast if one of them is invalid" - [] + [& args] (validate-non-default-languages) - (validate-ui-translations-are-used) + (validate-ui-translations-are-used {:fix? (contains? (set args) "--fix")}) (validate-languages-dont-have-duplicates))