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

auto-format all #947

Merged
merged 1 commit into from
Sep 3, 2023
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
4 changes: 2 additions & 2 deletions src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2534,8 +2534,8 @@
(swap! -function-schemas* assoc-in [key ns name] (merge data {:schema (f ?schema), :ns ns, :name name}))
(catch #?(:clj Throwable :cljs :default) ex
(throw (ex-info
(str "Schema error when insrumenting function: " ns "/" name " - " (ex-message ex))
(ex-data ex)))))))
(str "Schema error when insrumenting function: " ns "/" name " - " (ex-message ex))
(ex-data ex)))))))

#?(:clj
(defmacro => [given-sym value]
Expand Down
3 changes: 1 addition & 2 deletions src/malli/dev/cljs.cljc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns malli.dev.cljs
#?(:cljs (:require-macros [malli.dev.cljs]))
#?(:cljs (:require [malli.instrument :as mi]
[malli.core :as m]
#?(:cljs (:require [malli.core :as m]
[malli.dev.pretty :as pretty]))
#?(:clj (:require [cljs.analyzer.api :as ana-api]
[malli.clj-kondo :as clj-kondo]
Expand Down
36 changes: 19 additions & 17 deletions src/malli/dev/cljs_kondo_preload.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,32 @@
"During development sends the clj-kondo config data for all collected functions with malli schemas to the shadow-cljs clojure runtime which writes it to disk."
{:dev/after-load true}
[]
(runtime/relay-msg @client.shared/runtime-ref
{:op ::clj-kondo/write-config
:to env/worker-client-id
:build-id (keyword env/build-id)
:data (clj-kondo/get-kondo-config)})))
(runtime/relay-msg
@client.shared/runtime-ref
{:op ::clj-kondo/write-config
:to env/worker-client-id
:build-id (keyword env/build-id)
:data (clj-kondo/get-kondo-config)})))

;; The following sends the config on first load of the app, the above function handles hot-reloads.

#?(:cljs
(client.shared/add-plugin! ::client #{}
(fn [{:keys [runtime] :as env}]
(api/add-extension runtime ::client
{:on-welcome
(fn [] (send-kondo-config-to-shadow!))
(client.shared/add-plugin!
::client #{}
(fn [{:keys [runtime] :as env}]
(api/add-extension runtime ::client
{:on-welcome
(fn [] (send-kondo-config-to-shadow!))

:on-disconnect
(fn [e])
:on-disconnect
(fn [e])

:on-reconnect
(fn [e] (send-kondo-config-to-shadow!))})
env)
:on-reconnect
(fn [e] (send-kondo-config-to-shadow!))})
env)

(fn [{:keys [runtime]}]
(api/del-extension runtime ::client))))
(fn [{:keys [runtime]}]
(api/del-extension runtime ::client))))

#?(:clj
(defmethod worker/do-relay-msg ::clj-kondo/write-config
Expand Down
2 changes: 1 addition & 1 deletion src/malli/dev/cljs_noop.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

#?(:clj (defmacro stop! []))
#?(:clj (defmacro collect-all! []))
#?(:clj (defmacro start! ([]) ([options])))
#?(:clj (defmacro start! ([]) ([_options])))
#?(:clj (defmacro deregister-function-schemas! []))
34 changes: 17 additions & 17 deletions src/malli/swagger.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@
(or (:responses acc) {})
(for [[status response] v]
[status (cond-> response
(:schema response) (update :schema transform {:type :schema})
true (update :description (fnil identity ""))
true -remove-empty-keys)]))})
(:schema response) (update :schema transform {:type :schema})
true (update :description (fnil identity ""))
true -remove-empty-keys)]))})

(defmethod expand ::parameters [_ v acc _]
(let [old (or (:parameters acc) [])
Expand All @@ -128,20 +128,20 @@
(defn dissoc-non-root-definitions
[{:keys [parameters responses] :as x}]
(cond-> x
parameters (update :parameters
#(mapv (fn [p]
(if (contains? p :schema)
(update p :schema dissoc :definitions)
p))
%))
responses (update :responses
#(reduce-kv (fn [rs k v]
(assoc rs k
(if (contains? v :schema)
(update v :schema
dissoc :definitions)
v)))
{} %))))
parameters (update :parameters
#(mapv (fn [p]
(if (contains? p :schema)
(update p :schema dissoc :definitions)
p))
%))
responses (update :responses
#(reduce-kv (fn [rs k v]
(assoc rs k
(if (contains? v :schema)
(update v :schema
dissoc :definitions)
v)))
{} %))))

(defn expand-qualified-keywords
[x options]
Expand Down
10 changes: 5 additions & 5 deletions test/demo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
[:zip :int]]]])

(comment
(pretty/explain
Adult
{:name "Endy"
:age 17
:home {:zip 33100}}))
(pretty/explain
Adult
{:name "Endy"
:age 17
:home {:zip 33100}}))

(comment
(pretty/explain
Expand Down
26 changes: 13 additions & 13 deletions test/malli/clj_kondo_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
[:nested [:merge
[:map [:id ::id]]
[:map [:price ::price]]]]
[:string-type-enum [:maybe [:enum "b" "c"]]]
[:string-type-enum [:maybe [:enum "b" "c"]]]
[:keyword-type-enum [:enum :a :b]]
[:any-type-enum [:enum :a "b" "c"]]
[:z [:vector [:map-of int? int?]]]]
Expand Down Expand Up @@ -61,26 +61,26 @@
(let [expected-out
{'malli.clj-kondo-test
{'kikka
{:arities {1 {:args [:int],
:ret :int},
:varargs {:args [:int :int {:op :rest, :spec :int}],
:ret :int,
{:arities {1 {:args [:int],
:ret :int},
:varargs {:args [:int :int {:op :rest, :spec :int}],
:ret :int,
:min-arity 2}}}
'siren
{:arities {2 {:args [:ifn :coll], :ret :map}}}}}]
#?(:clj
(is (= expected-out
(-> 'malli.clj-kondo-test
(clj-kondo/collect)
(clj-kondo/linter-config)
(get-in [:linters :type-mismatch :namespaces])))))
(-> 'malli.clj-kondo-test
(clj-kondo/collect)
(clj-kondo/linter-config)
(get-in [:linters :type-mismatch :namespaces])))))

#?(:cljs
(is (= expected-out
(-> 'malli.clj-kondo-test
(clj-kondo/collect-cljs)
(clj-kondo/linter-config)
(get-in [:linters :type-mismatch :namespaces]))))))
(-> 'malli.clj-kondo-test
(clj-kondo/collect-cljs)
(clj-kondo/linter-config)
(get-in [:linters :type-mismatch :namespaces]))))))
(testing "sequential elements"
(is (= {:op :rest :spec :int}
(clj-kondo/transform [:repeat :int])))
Expand Down
62 changes: 32 additions & 30 deletions test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[malli.transform :as mt]
[malli.util :as mu]
#?(:clj [malli.test-macros :refer [when-env]]))
#?(:clj (:import (clojure.lang IFn PersistentArrayMap PersistentHashMap))
#?(:clj (:import (clojure.lang IFn PersistentArrayMap PersistentHashMap))
:cljs (:require-macros [malli.test-macros :refer [when-env]])))

(defn with-schema-forms [result]
Expand Down Expand Up @@ -120,15 +120,16 @@
(is (schema= [[:x nil 'int?] [:y nil 'string?]] (m/eval "(m/children [:map [:x int?] [:y string?]])"))))
#?(:bb nil
:default
(when-env "TEST_SCI"
(testing "with options"
(testing "disabling sci"
(is (= 2 ((m/eval inc {::m/disable-sci true}) 1)))
(is (thrown? #?(:clj Exception, :cljs js/Error) ((m/eval 'inc {::m/disable-sci true}) 1))))
(testing "custom bindings"
(let [f '(fn [schema] (m/form schema))]
(is (thrown? #?(:clj Exception, :cljs js/Error) ((m/eval f) :string)))
(is (= :string ((m/eval f {::m/sci-options {:namespaces {'malli.core {'form m/form}}}}) :string)))))))))
(when-env
"TEST_SCI"
(testing "with options"
(testing "disabling sci"
(is (= 2 ((m/eval inc {::m/disable-sci true}) 1)))
(is (thrown? #?(:clj Exception, :cljs js/Error) ((m/eval 'inc {::m/disable-sci true}) 1))))
(testing "custom bindings"
(let [f '(fn [schema] (m/form schema))]
(is (thrown? #?(:clj Exception, :cljs js/Error) ((m/eval f) :string)))
(is (= :string ((m/eval f {::m/sci-options {:namespaces {'malli.core {'form m/form}}}}) :string)))))))))

(deftest into-schema-test
(is (form= [:map {:closed true} [:x int?]]
Expand Down Expand Up @@ -189,26 +190,27 @@
[string? {:decode/string '{:enter #(str "olipa_" %), :leave #(str % "_avaruus")}}]
"kerran" mt/string-transformer)))

(when-env "TEST_SCI"
(testing "sci not available"
(let [schema (m/schema
[string? {:decode/string '{:enter #(str "olipa_" %), :leave #(str % "_avaruus")}}]
{::m/disable-sci true})]

(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error)
#":malli.core/sci-not-available"
(m/decoder schema mt/string-transformer)))

(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error)
#":malli.core/sci-not-available"
(m/decoder
[string? {:decode/string '{:enter #(str "olipa_" %), :leave #(str % "_avaruus")}}]
{::m/disable-sci true} mt/string-transformer)))

(testing "direct options win"
(is (m/decoder schema {::m/disable-sci false} mt/string-transformer))))))
(when-env
"TEST_SCI"
(testing "sci not available"
(let [schema (m/schema
[string? {:decode/string '{:enter #(str "olipa_" %), :leave #(str % "_avaruus")}}]
{::m/disable-sci true})]

(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error)
#":malli.core/sci-not-available"
(m/decoder schema mt/string-transformer)))

(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error)
#":malli.core/sci-not-available"
(m/decoder
[string? {:decode/string '{:enter #(str "olipa_" %), :leave #(str % "_avaruus")}}]
{::m/disable-sci true} mt/string-transformer)))

(testing "direct options win"
(is (m/decoder schema {::m/disable-sci false} mt/string-transformer))))))

(is (true? (m/validate (over-the-wire schema) 1)))

Expand Down
10 changes: 5 additions & 5 deletions test/malli/demo.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
[x :- :int] (inc x))

(comment
(dev/start!)
(dev/stop!))
(dev/start!)
(dev/stop!))

(comment
(kikka "1")
(kukka 1 2)
(kakka "1"))
(kikka "1")
(kukka 1 2)
(kakka "1"))
55 changes: 28 additions & 27 deletions test/malli/error_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -202,33 +202,34 @@
(assoc-in ['int? :error/message :fi] "NUMERO")
(assoc-in [::m/missing-key :error/message :fi] "PUUTTUVA AVAIN"))})))))))

(when-env "TEST_SCI"
(deftest sci-not-available-test
(testing "sci not available"
(let [schema (m/schema [:string {:error/fn '(constantly "FAIL")}] {::m/disable-sci true})]
(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error)
#":malli.core/sci-not-available"
(-> schema (m/explain ::invalid) (me/with-error-messages))))
(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error)
#":malli.core/sci-not-available"
(-> schema (m/explain ::invalid) (me/humanize))))
(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error)
#":malli.core/sci-not-available"
(-> [:string {:error/fn '(constantly "FAIL")}]
(m/explain ::invalid)
(me/with-error-messages {::m/disable-sci true}))))
(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error)
#":malli.core/sci-not-available"
(-> [:string {:error/fn '(constantly "FAIL")}]
(m/explain ::invalid)
(me/humanize {::m/disable-sci true}))))
(testing "direct options win"
(is (-> schema (m/explain ::invalid) (me/with-error-messages {::m/disable-sci false})))
(is (-> schema (m/explain ::invalid) (me/humanize {::m/disable-sci false}))))))))
(when-env
"TEST_SCI"
(deftest sci-not-available-test
(testing "sci not available"
(let [schema (m/schema [:string {:error/fn '(constantly "FAIL")}] {::m/disable-sci true})]
(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error)
#":malli.core/sci-not-available"
(-> schema (m/explain ::invalid) (me/with-error-messages))))
(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error)
#":malli.core/sci-not-available"
(-> schema (m/explain ::invalid) (me/humanize))))
(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error)
#":malli.core/sci-not-available"
(-> [:string {:error/fn '(constantly "FAIL")}]
(m/explain ::invalid)
(me/with-error-messages {::m/disable-sci true}))))
(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error)
#":malli.core/sci-not-available"
(-> [:string {:error/fn '(constantly "FAIL")}]
(m/explain ::invalid)
(me/humanize {::m/disable-sci true}))))
(testing "direct options win"
(is (-> schema (m/explain ::invalid) (me/with-error-messages {::m/disable-sci false})))
(is (-> schema (m/explain ::invalid) (me/humanize {::m/disable-sci false}))))))))

(deftest composing-with-and-test

Expand Down
10 changes: 5 additions & 5 deletions test/malli/experimental/time_test.cljc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns ^:simple malli.experimental.time-test
(:require [malli.core :as m]
[malli.registry :as mr]
#?(:clj [malli.experimental.time :as time]
#?(:clj [malli.experimental.time :as time]
:cljs [malli.experimental.time :as time
:refer [Duration LocalDate LocalDateTime LocalTime Instant ZonedDateTime OffsetDateTime ZoneId OffsetTime]])
[clojure.test :as t])
Expand Down Expand Up @@ -101,9 +101,9 @@
{:min (. ZonedDateTime parse "2022-12-18T05:40:25.840823567-06:00[America/Chicago]")
:max (. ZonedDateTime parse "2022-12-18T12:10:25.840823567Z[UTC]")}]
(m/validate (. ZonedDateTime parse
"2022-12-18T06:00:25.840823567-06:00[America/Chicago]") {:registry r})))
"2022-12-18T06:00:25.840823567-06:00[America/Chicago]") {:registry r})))
(t/is (not (m/validate :time/zoned-date-time "2022-12-18T12:00:25.840823567Z[UTC]" {:registry r}))))
(t/testing "offset date time"
(t/is (m/validate :time/offset-date-time (. OffsetDateTime parse "2022-12-18T12:00:25.840823567Z") {:registry r}))
(t/is (m/validate :time/offset-date-time (. OffsetDateTime parse "2022-12-18T06:00:25.840823567-06:00") {:registry r}))
(t/is (not (m/validate :time/offset-date-time "2022-12-18T12:00:25.840823567Z" {:registry r})))))
(t/is (m/validate :time/offset-date-time (. OffsetDateTime parse "2022-12-18T12:00:25.840823567Z") {:registry r}))
(t/is (m/validate :time/offset-date-time (. OffsetDateTime parse "2022-12-18T06:00:25.840823567-06:00") {:registry r}))
(t/is (not (m/validate :time/offset-date-time "2022-12-18T12:00:25.840823567Z" {:registry r})))))
Loading