Parcourir la source

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
Gabriel Horner il y a 1 an
Parent
commit
14a507f4cd
3 fichiers modifiés avec 10 ajouts et 9 suppressions
  1. 1 0
      bb.edn
  2. 2 0
      docs/contributing-to-translations.md
  3. 7 9
      scripts/src/logseq/tasks/lang.clj

+ 1 - 0
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"

+ 2 - 0
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:

+ 7 - 9
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))