kkinnear/zprint

[IDEA] Apply sorting (or other options) only to some key of a map

Closed this issue · 2 comments

Hi Kim, I have another use case for this idea you had in another issue.

It is basically the formatting of the following bb.edn:

;;!zprint {:map {:key-order [:paths :deps :tasks] :respect-bl? false}}
{:paths ["scripts"]
 :deps {}
 :min-bb-version "0.4.0"
 :tasks {deps {:doc "Download the project dependencies." :task (clojure "-P" "-M:test")}
         check {:doc "Check the code for problems." :depends [lint-check fmt-check]}
         lint-check {:doc "Check code linting." :task (shell "scripts/lint-clj.sh check")}
         fmt-check {:doc "Check code formatting." :task (shell "scripts/format-clj.sh check")}
         fmt-fix {:doc "Fix code formatting." :task (shell "scripts/format-clj.sh fix")}
         test {:doc "Run the test suite." :task (clojure "-M:test" "--fail-fast" "unit")}
         test-watch {:doc "Test files while watching the file system for changes."
                     :task (clojure "-M:test" "--fail-fast" "--watch" "unit")}}}

It would be awesome if I could apply options like :sort? or :justify? only to the :tasks key.
Not a big deal but I figured we should have a first class issue for tracking the idea.

Thanks as always for your work on zprint!

Hello! If I understand your idea, I think what you are asking for is already available as {:map {:key-value-options ...}}.

For example, I'm turning off sorting, and then re-enabling sorting only for things under the :tasks key.

(czprint i267a {:parse-string? true :map {:sort? false :key-value-options {:tasks {:map {:sort? true}}}}})
{:paths ["scripts"],
 :deps {},
 :min-bb-version "0.4.0",
 :tasks {check {:depends [lint-check fmt-check],
                :doc "Check the code for problems."},
         deps {:doc "Download the project dependencies.",
               :task (clojure "-P" "-M:test")},
         fmt-check {:doc "Check code formatting.",
                    :task (shell "scripts/format-clj.sh check")},
         fmt-fix {:doc "Fix code formatting.",
                  :task (shell "scripts/format-clj.sh fix")},
         lint-check {:doc "Check code linting.",
                     :task (shell "scripts/lint-clj.sh check")},
         test {:doc "Run the test suite.",
               :task (clojure "-M:test" "--fail-fast" "unit")},
         test-watch {:doc
                       "Test files while watching the file system for changes.",
                     :task (clojure "-M:test" "--fail-fast" "--watch" "unit")}}

Here it is with :justify? true:

(czprint i267a {:parse-string? true :map {:sort? false :key-value-options {:tasks {:map {:sort? true :justify? true}}}}})
{:paths ["scripts"],
 :deps {},
 :min-bb-version "0.4.0",
 :tasks {check      {:depends [lint-check fmt-check],
                     :doc     "Check the code for problems."},
         deps       {:doc  "Download the project dependencies.",
                     :task (clojure "-P" "-M:test")},
         fmt-check  {:doc  "Check code formatting.",
                     :task (shell "scripts/format-clj.sh check")},
         fmt-fix    {:doc  "Fix code formatting.",
                     :task (shell "scripts/format-clj.sh fix")},
         lint-check {:doc  "Check code linting.",
                     :task (shell "scripts/lint-clj.sh check")},
         test       {:doc  "Run the test suite.",
                     :task (clojure "-M:test" "--fail-fast" "unit")},
         test-watch {:doc
                       "Test files while watching the file system for changes.",
                     :task (clojure "-M:test" "--fail-fast" "--watch" "unit")}}}

I hope that does what you want. Thanks for asking!

Well it works like a charm! I must have missed it, closing this and thank you 😄