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
This commit is contained in:
Gabriel Horner
2024-08-20 10:08:36 -04:00
parent 21b55fabad
commit 14a507f4cd
3 changed files with 10 additions and 9 deletions

1
bb.edn
View File

@@ -2,6 +2,7 @@
:deps :deps
{metosin/malli {metosin/malli
{:mvn/version "0.16.1"} {:mvn/version "0.16.1"}
borkdude/rewrite-edn {:mvn/version "0.4.8"}
logseq/bb-tasks logseq/bb-tasks
#_{:local/root "../bb-tasks"} #_{:local/root "../bb-tasks"}
{:git/url "https://github.com/logseq/bb-tasks" {:git/url "https://github.com/logseq/bb-tasks"

View File

@@ -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 [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 ...}`. 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 ## Add a Language
To add a new language: To add a new language:

View File

@@ -7,11 +7,7 @@
[babashka.cli :as cli] [babashka.cli :as cli]
[babashka.process :refer [shell]] [babashka.process :refer [shell]]
[babashka.fs :as fs] [babashka.fs :as fs]
[babashka.deps :as deps])) [borkdude.rewrite-edn :as r]))
(deps/add-deps '{:deps {borkdude/rewrite-edn {:mvn/version "0.4.8"}}})
(require '[borkdude.rewrite-edn :as r])
(defn- get-dicts (defn- get-dicts
[] []
@@ -147,7 +143,7 @@
"This validation checks to see that translations done by (t ...) are equal to "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 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" 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} (let [actual-dicts (->> (shell {:out :string}
;; This currently assumes all ui translations ;; This currently assumes all ui translations
;; use (t and src/main. This can easily be ;; use (t and src/main. This can easily be
@@ -174,7 +170,9 @@
(when (seq expected-only) (when (seq expected-only)
(println "\nThese translation keys are invalid because they are not used in the UI:") (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)) (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))))) (System/exit 1)))))
(def allowed-duplicates (def allowed-duplicates
@@ -230,7 +228,7 @@
(defn validate-translations (defn validate-translations
"Runs multiple translation validations that fail fast if one of them is invalid" "Runs multiple translation validations that fail fast if one of them is invalid"
[] [& args]
(validate-non-default-languages) (validate-non-default-languages)
(validate-ui-translations-are-used) (validate-ui-translations-are-used {:fix? (contains? (set args) "--fix")})
(validate-languages-dont-have-duplicates)) (validate-languages-dont-have-duplicates))