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

Introduce malli library #17867

Merged
merged 25 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a4ef4c1
Set up Malli
ilmotta Oct 26, 2023
4e7c2f2
Run nix-update-clojure
ilmotta Nov 9, 2023
fbc366f
Use custom reporter to warn developer of schema errors
ilmotta Oct 27, 2023
da101a2
Always transform to schema instances
ilmotta Oct 27, 2023
58378f8
Automatically remove visible schema errors if function is called corr…
ilmotta Oct 27, 2023
15418a8
Improve namespace structure in src/schema/
ilmotta Oct 27, 2023
a4de610
Fix docstring typo
ilmotta Oct 27, 2023
1acfafe
Let function instrumentation be a nop when an error happens
ilmotta Nov 7, 2023
7bdc401
Initialize the app anyway if there are invalid schemas
ilmotta Nov 7, 2023
a871e18
Remove unused macro
ilmotta Nov 7, 2023
e060e09
Remove unnecessary zprint setting
ilmotta Nov 9, 2023
11e931b
Move schema definition to the bottom of the file
ilmotta Nov 9, 2023
3908cad
Get rid of macro wrapper
ilmotta Nov 9, 2023
b83b222
Extract styles to style namespace
ilmotta Nov 9, 2023
b6e5f0f
Use bottom inset (esp. important for iOS)
ilmotta Nov 9, 2023
24be3c1
Rename function and remove unnecessary docstring
ilmotta Nov 9, 2023
c9b62c7
Remove def from refer-clojure
ilmotta Nov 9, 2023
6887e4b
feat: malli error component extra styling/info
clauxx Nov 9, 2023
d007baf
Remove unnecessary docstring
ilmotta Nov 9, 2023
71bb2de
Allow vars to be instrumented with exception checks
ilmotta Nov 9, 2023
f2b3c4d
Short circuit unit tests and print errors correctly
ilmotta Nov 9, 2023
61e6fd0
Refactor: extract function
ilmotta Nov 9, 2023
a782965
Schema README updates
ilmotta Nov 9, 2023
9e351e5
Fix failed test (detected by instrumentation)
ilmotta Nov 13, 2023
c974afc
Move schema before function definition
ilmotta Nov 13, 2023
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
16 changes: 12 additions & 4 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@
:clj-kondo-config {:level :error}
:cond-else {:level :error}
:consistent-alias {:level :error
:aliases {clojure.string string
clojure.set set
clojure.walk walk
taoensso.timbre log}}
:aliases {clojure.set set
clojure.string string
clojure.walk walk
malli.core malli
malli.dev.pretty malli.pretty
malli.dev.virhe malli.virhe
malli.error malli.error
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: I added these aliases because there's a tendency devs would copy from tutorials alias abbreviations like mu to mean malli.util, or me to mean malli.error.

malli.generator malli.generator
malli.transform malli.transform
malli.util malli.util
schema.core schema
taoensso.timbre log}}
:deprecated-namespace {:level :warning}
:docstring-blank {:level :error}
:equals-true {:level :error}
Expand Down
2 changes: 2 additions & 0 deletions .clj-kondo/metosin/malli/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{:lint-as {malli.experimental/defn schema.core/defn}
:linters {:unresolved-symbol {:exclude [(malli.core/=>)]}}}
1 change: 1 addition & 0 deletions .zprintrc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"deftest-sub" :arg1-body
"wait-for" :arg1-body
"with-deps-check" :arg1-body
"schema/=>" :arg1-body
"->" [:noarg1-body
{:list {:constant-pair? false :force-nl? false}
:next-inner-restore [[:list :constant-pair?]]}]
Expand Down
60 changes: 48 additions & 12 deletions nix/deps/clojure/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,20 @@
},

{
"path": "borkdude/edamame/1.1.17/edamame-1.1.17",
"path": "borkdude/dynaload/0.3.5/dynaload-0.3.5",
"host": "https://repo.clojars.org",
"jar": {
"sha1": "9087f7abf0104e0354d7db7fc4576608eac558f4",
"sha256": "1n1872i240lakn4pzsag4grf7bv7lcsipmqllxd9m4k1zp3dgla1"
"sha1": "accd696ba364b850b4d92e38f5a34d0e828a0ad1",
"sha256": "0k62m1f29xfh3cp67w7kcvkp5aj35simi8kf95ycvkmgp76w11q8"
}
},

{
"path": "borkdude/edamame/1.3.23/edamame-1.3.23",
"host": "https://repo.clojars.org",
"jar": {
"sha1": "254d023e97ed438f0f44532b5a06d928d031ede4",
"sha256": "0l7mxza2nimslhg0qh6jp7gmb8sd6l89fk5d1zvzq2xskscq2vly"
}
},

Expand Down Expand Up @@ -81,20 +90,20 @@
},

{
"path": "cider/cider-nrepl/0.29.0/cider-nrepl-0.29.0",
"path": "cider/cider-nrepl/0.25.3/cider-nrepl-0.25.3",
"host": "https://repo.clojars.org",
"jar": {
"sha1": "45f6034b26a14138e74145b7a4059628c0fedcd1",
"sha256": "1dy1l6y8cb8xiqq97a4lf8giyiicq4wfl4s2lxn5fb6614cjxqx2"
"sha1": "5ae0efd9377a5e60c084bdaf4a2ce094f759ce23",
"sha256": "0drxf9nm23i1pcgrkwbcr09msq37csilzww38709add0hz8spjhq"
}
},

{
"path": "cider/piggieback/0.5.2/piggieback-0.5.2",
"path": "cider/piggieback/0.4.1/piggieback-0.4.1",
"host": "https://repo.clojars.org",
"jar": {
"sha1": "ecfd5c286a85db3f059e75c37fca5722d9e26f79",
"sha256": "1ps9yf3cxmlm447hqkidjb5xry90n0wl3jk0jn28fagq31lzylkl"
"sha1": "0a02a3e2ecd7a126ab60d8a44793342f20ced79b",
"sha256": "142vl5np33akcrnn6pksi0rjfsmmi528villxsj6cwcndvybiw4m"
}
},

Expand Down Expand Up @@ -539,6 +548,24 @@
}
},

{
"path": "metosin/malli/0.13.0/malli-0.13.0",
"host": "https://repo.clojars.org",
"jar": {
"sha1": "286c52d26a3a9d613b5f692971bd19c581cdc4b0",
"sha256": "0vaq9d6cln5j4ww302fwlgg7m647cf2j16gs2i1p1d4klbn4jddz"
}
},

{
"path": "mvxcvi/arrangement/2.1.0/arrangement-2.1.0",
"host": "https://repo.clojars.org",
"jar": {
"sha1": "1bc8f3bba7a28de85f319b7d464aa8d955f44918",
"sha256": "1j1rkwrs4wm8zk9v7ilgpnyav5sipdd2bmb83sazh392blw52wpk"
}
},

{
"path": "net/cgrand/macrovich/0.2.1/macrovich-0.2.1",
"host": "https://repo.clojars.org",
Expand Down Expand Up @@ -728,6 +755,15 @@
}
},

{
"path": "org/clojure/test.check/1.1.1/test.check-1.1.1",
"host": "https://repo1.maven.org/maven2",
"jar": {
"sha1": "f33d988fd57bc9c11af1952db81c10f319c91416",
"sha256": "0y2hpkj7zl4yrpsl35ifpdaja5c72b8fpjcnmdgmld9c7cb1hlcl"
}
},

{
"path": "org/clojure/tools.analyzer/1.1.0/tools.analyzer-1.1.0",
"host": "https://repo1.maven.org/maven2",
Expand Down Expand Up @@ -909,11 +945,11 @@
},

{
"path": "refactor-nrepl/refactor-nrepl/3.6.0/refactor-nrepl-3.6.0",
"path": "refactor-nrepl/refactor-nrepl/2.5.0/refactor-nrepl-2.5.0",
"host": "https://repo.clojars.org",
"jar": {
"sha1": "2b3bb82da53b5db9c2b2aa298417816b81d0ed97",
"sha256": "1ysqabmlnghki6x0636zngxza2d83c85276wp9ma9wk183mkv52a"
"sha1": "6bc3441afc94f7ca024e41a864ca75e05df7e207",
"sha256": "0w8hax99y98l53mixxzx2ja0vcnhjv8dnsaz1zj3vqk775ns5w6i"
}
},

Expand Down
12 changes: 8 additions & 4 deletions nix/deps/clojure/deps.list
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ babashka/fs/0.2.16/fs-0.2.16.jar
bidi/bidi/2.1.6/bidi-2.1.6.jar
binaryage/env-config/0.2.2/env-config-0.2.2.jar
binaryage/oops/0.7.2/oops-0.7.2.jar
borkdude/edamame/1.1.17/edamame-1.1.17.jar
borkdude/dynaload/0.3.5/dynaload-0.3.5.jar
borkdude/edamame/1.3.23/edamame-1.3.23.jar
borkdude/sci.impl.reflector/0.0.1/sci.impl.reflector-0.0.1.jar
camel-snake-kebab/camel-snake-kebab/0.4.3/camel-snake-kebab-0.4.3.jar
cheshire/cheshire/5.11.0/cheshire-5.11.0.jar
cider/cider-nrepl/0.29.0/cider-nrepl-0.29.0.jar
cider/piggieback/0.5.2/piggieback-0.5.2.jar
cider/cider-nrepl/0.25.3/cider-nrepl-0.25.3.jar
cider/piggieback/0.4.1/piggieback-0.4.1.jar
clj-kondo/clj-kondo/2023.09.07/clj-kondo-2023.09.07.jar
cljs-bean/cljs-bean/1.9.0/cljs-bean-1.9.0.jar
clout/clout/2.1.2/clout-2.1.2.jar
Expand Down Expand Up @@ -58,6 +59,8 @@ javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar
javax/servlet/servlet-api/2.5/servlet-api-2.5.jar
javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar
medley/medley/0.8.2/medley-0.8.2.jar
metosin/malli/0.13.0/malli-0.13.0.jar
mvxcvi/arrangement/2.1.0/arrangement-2.1.0.jar
net/cgrand/macrovich/0.2.1/macrovich-0.2.1.jar
net/java/dev/jna/jna/5.12.1/jna-5.12.1.jar
nrepl/bencode/1.1.0/bencode-1.1.0.jar
Expand All @@ -79,6 +82,7 @@ org/clojure/data.priority-map/1.1.0/data.priority-map-1.1.0.jar
org/clojure/google-closure-library/0.0-20230227-c7c0a541/google-closure-library-0.0-20230227-c7c0a541.jar
org/clojure/google-closure-library-third-party/0.0-20230227-c7c0a541/google-closure-library-third-party-0.0-20230227-c7c0a541.jar
org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar
org/clojure/test.check/1.1.1/test.check-1.1.1.jar
org/clojure/tools.analyzer/1.1.0/tools.analyzer-1.1.0.jar
org/clojure/tools.analyzer.jvm/1.2.2/tools.analyzer.jvm-1.2.2.jar
org/clojure/tools.cli/1.0.206/tools.cli-1.0.206.jar
Expand All @@ -99,7 +103,7 @@ org/wildfly/common/wildfly-common/1.5.2.Final/wildfly-common-1.5.2.Final.jar
prismatic/schema/1.1.7/schema-1.1.7.jar
reagent/reagent/1.2.0/reagent-1.2.0.jar
re-com/re-com/2.8.0/re-com-2.8.0.jar
refactor-nrepl/refactor-nrepl/3.6.0/refactor-nrepl-3.6.0.jar
refactor-nrepl/refactor-nrepl/2.5.0/refactor-nrepl-2.5.0.jar
re-frame/re-frame/1.3.0/re-frame-1.3.0.jar
re-frisk-remote/re-frisk-remote/1.6.0/re-frisk-remote-1.6.0.jar
re-frisk/sente/1.15.0/sente-1.15.0.jar
Expand Down
20 changes: 18 additions & 2 deletions shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[cljs-bean "1.9.0"]
[com.cognitect/transit-cljs "0.8.280"]
[camel-snake-kebab "0.4.3"]
[metosin/malli "0.13.0"]

;; Dev dependencies
[refactor-nrepl "2.5.0"]
Expand Down Expand Up @@ -50,6 +51,7 @@
:after-load-async status-im2.setup.hot-reload/reload
:build-notify status-im2.setup.hot-reload/build-notify
:preloads [re-frisk-remote.preload
status-im2.setup.schema-preload
;; In order to use component test helpers in the REPL we
;; need to preload namespaces that are not normally required
;; by production code, such as
Expand All @@ -71,6 +73,10 @@
:warnings {:fn-deprecated false}
:closure-defines {re-frame.trace/trace-enabled? true}
:source-map false
;; This seems to be necessary while using the REPL,
;; otherwise sometimes you'll get weird errors when
;; instrumenting functions.
:static-fns false
:infer-externs true}
;; if you want to use a real device, set your local ip
;; in the SHADOW_HOST env variable to make sure that
Expand Down Expand Up @@ -104,13 +110,15 @@
:output-dir "target/test"
:optimizations :simple
:target :node-test
:dev {:devtools {:preloads [status-im2.setup.schema-preload]}}
;; Uncomment line below to `make test-watch` a specific file
;; :ns-regexp "status-im2.subs.messages-test$"
:main status-im.test-runner/main
;; set :ui-driven to true to let shadow-cljs inject node-repl
:ui-driven true
:closure-defines
{status-im2.config/POKT_TOKEN #shadow/env "POKT_TOKEN"
{schema.core/throw-on-error? true
status-im2.config/POKT_TOKEN #shadow/env "POKT_TOKEN"
status-im2.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN"
status-im2.config/OPENSEA_API_KEY #shadow/env "OPENSEA_API_KEY"
status-im2.config/ALCHEMY_ARBITRUM_GOERLI_TOKEN #shadow/env "ALCHEMY_ARBITRUM_GOERLI_TOKEN"
Expand Down Expand Up @@ -139,9 +147,17 @@
:compiler-options {:optimizations :simple
:source-map false}}
:component-test {:target :npm-module
:entries [quo.core-spec status-im2.core-spec]
:entries [;; We need to tell shadow-cljs to compile
;; the preloads namespace because it will
;; be used directly by Jest in the option
;; setupFilesAfterEnv.
status-im2.setup.schema-preload

quo.core-spec
status-im2.core-spec]
:ns-regexp "component-spec$"
:output-dir "component-spec"
:closure-defines {schema.core/throw-on-error? true}
:compiler-options {:warnings-as-errors false
:static-fns false
:infer-externs true}}}}
10 changes: 7 additions & 3 deletions src/quo/components/counter/step/component_spec.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
[quo.components.counter.step.view :as step]
[test-helpers.component :as h]))

(defn render
[component]
(h/render-with-theme-provider component :dark))

(h/describe "step component"
(h/test "default render of step component"
(h/render [step/view {} nil])
(render [step/view {} nil])
(-> (h/expect (h/query-by-label-text :step-counter))
(h/is-truthy)))

(h/test "renders step with a string value"
(h/render [step/view {} "1"])
(render [step/view {} "1"])
(-> (h/expect (h/get-by-text "1"))
(h/is-truthy)))

(h/test "renders step with an integer value"
(h/render [step/view {} 1])
(render [step/view {} 1])
(-> (h/expect (h/get-by-text "1"))
(h/is-truthy))))
23 changes: 20 additions & 3 deletions src/quo/components/counter/step/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@
(:require
[quo.components.counter.step.style :as style]
[quo.components.markdown.text :as text]
[quo.theme :as theme]
quo.theme
[react-native.core :as rn]
[schema.core :as schema]
[utils.number]))

(def ?schema
[:=>
[:catn
[:props
[:map {:closed true}
[:accessibility-label {:optional true} [:maybe :keyword]]
[:customization-color {:optional true} [:maybe :schema.common/customization-color]]
[:in-blur-view? {:optional true} [:maybe :boolean]]
[:theme :schema.common/theme]
[:type {:optional true} [:enum :active :complete :neutral]]]]
[:value [:maybe [:or :string :int]]]]
:any])

(defn- view-internal
[{:keys [type accessibility-label theme in-blur-view? customization-color]} value]
(let [type (or type :neutral)
Expand All @@ -23,6 +37,9 @@
[text/text
{:weight :medium
:size :label
:style {:color (style/text-color type theme)}} label]]))
:style {:color (style/text-color type theme)}}
label]]))

(def view (theme/with-theme view-internal))
(def view
(quo.theme/with-theme
(schema/instrument #'view-internal ?schema)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This is the functional approach with schema/instrument. Notice the need to var quote view-internal. This has been added to the schema guidelines too.

7 changes: 4 additions & 3 deletions src/quo/components/markdown/list/component_spec.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
(h/is-truthy (h/get-by-text "test description")))

(h/test "renders step component when step-number is valid and type is step"
(h/render [list/view
{:type :step
:step-number 1}])
(h/render-with-theme-provider [list/view
{:type :step
:step-number 1}]
:dark)
(h/is-truthy (h/get-by-label-text :step-counter)))

(h/test "renders decription with a context tag component and description after the tag"
Expand Down
2 changes: 1 addition & 1 deletion src/quo/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@

;;;; Counter
(def counter quo.components.counter.counter.view/view)
(def step quo.components.counter.step.view/view)
(def step #'quo.components.counter.step.view/view)

;;;; Dividers
(def divider-label quo.components.dividers.divider-label.view/view)
Expand Down
Loading