Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mask valid values by default with malli.dev.pretty/explain #738

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/malli/dev/pretty.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
:width 100
:colors v/-dark-colors
:unknown (fn [x] (when (m/schema? x) (m/form x)))
:throwing-fn-top-level-ns-names ["malli" "clojure"]}
:throwing-fn-top-level-ns-names ["malli" "clojure" "malli"]
::me/mask-valid-values '...}
options))))

(defn -errors [explanation printer]
Expand All @@ -30,14 +31,13 @@
;; formatters
;;

(defmethod v/-format ::m/explain [_ _ explanation printer]
(let [{:keys [schema value]} explanation]
{:body
[:group
(-block "Errors:" (v/-visit (me/humanize explanation) printer) printer) :break :break
(-block "Value:" (v/-visit value printer) printer) :break :break
(-block "Schema:" (v/-visit schema printer) printer) :break :break
(-block "More information:" (-link "https://cljdoc.org/d/metosin/malli/CURRENT" printer) printer)]}))
(defmethod v/-format ::m/explain [_ _ {:keys [schema] :as explanation} printer]
{:body
[:group
(-block "Value:" (v/-visit (me/error-value explanation printer) printer) printer) :break :break
(-block "Errors:" (v/-visit (me/humanize explanation) printer) printer) :break :break
(-block "Schema:" (v/-visit schema printer) printer) :break :break
(-block "More information:" (-link "https://cljdoc.org/d/metosin/malli/CURRENT" printer) printer)]})

(defmethod v/-format ::m/invalid-input [_ _ {:keys [args input fn-name]} printer]
{:body
Expand Down
9 changes: 2 additions & 7 deletions src/malli/dev/virhe.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
:print-length *print-length*
:print-level *print-level*
:print-meta *print-meta*}]
(map->EdnPrinter (cond->> options defaults (merge defaults))))))
(map->EdnPrinter (cond-> defaults options (merge options))))))

(defn -pprint
([x] (-pprint x (-printer)))
Expand Down Expand Up @@ -158,12 +158,7 @@
(-color :text body printer))

(defn -section [title location body printer]
[:group
(-title title location printer)
:break :break
body
:break :break
(-footer printer)])
[:group (-title title location printer) :break :break body :break :break (-footer printer)])

;;
;; formatting
Expand Down
18 changes: 18 additions & 0 deletions test/demo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,21 @@
{:name "Endy"
:age 17
:home {:zip 33100}}))

(comment
(pretty/explain
[:map
[:id :int]
[:tags [:set :keyword]]
[:address [:map
[:street :string]
[:city :string]
[:zip :int]
[:lonlat [:tuple :double :double]]]]]
{:id "123"
:EXTRA "KEY"
:tags #{:artesan "coffee" :garden}
:address {:street "Ahlmanintie 29"
:city "Tampere"
:zip 33100
:lonlat [61.4858322, 23.7832851]}}))