From f70b689de71b094f19fe2ba7e196e7dca791d60c Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:50:58 -0800 Subject: [PATCH 01/17] point leptos to fork --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 19aef48..bc5608b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ indexmap = "2" inner = "0" itertools = "~0.12" js-sys = "~0.3" -leptos = { version = "~0.5" } +leptos = { git = "https://github.com/tlowerison/leptos", rev = "ea2b167" } leptos_router = "~0.5" num-bigint = { version = "~0.4", default-features = false } paste = "~1" From 91ff5fde507804ebe46033668e22694bc9c7cb44 Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:56:46 -0800 Subject: [PATCH 02/17] point leptos_router to fork --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index bc5608b..4ea03d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ inner = "0" itertools = "~0.12" js-sys = "~0.3" leptos = { git = "https://github.com/tlowerison/leptos", rev = "ea2b167" } -leptos_router = "~0.5" +leptos_router = { git = "https://github.com/tlowerison/leptos", rev = "ea2b167" } num-bigint = { version = "~0.4", default-features = false } paste = "~1" prettyplease = "0.2" From 7dae8b1cccf97cd7227bede62c42378ae1bef889 Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Fri, 1 Dec 2023 12:43:29 -0800 Subject: [PATCH 03/17] point leptos to upstream after PR merge --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4ea03d9..d7f8e7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,8 +29,8 @@ indexmap = "2" inner = "0" itertools = "~0.12" js-sys = "~0.3" -leptos = { git = "https://github.com/tlowerison/leptos", rev = "ea2b167" } -leptos_router = { git = "https://github.com/tlowerison/leptos", rev = "ea2b167" } +leptos = { git = "https://github.com/leptos-rs/leptos", rev = "ed61ea9" } +leptos_router = { git = "https://github.com/leptos-rs/leptos", rev = "ed61ea9" } num-bigint = { version = "~0.4", default-features = false } paste = "~1" prettyplease = "0.2" From b5e83a2367ae0e644f6ef9004e65b12e30d3e189 Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Thu, 14 Dec 2023 17:00:08 -0800 Subject: [PATCH 04/17] change default formats for chrono config objects; add additional test in Form macro confirming use of custom config is correctly placed --- .gitignore | 1 + core/src/form_component/impls/misc.rs | 13 +- proc_macros/core/src/form.rs | 206 +++++++++++++++++++++++++- 3 files changed, 215 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 16d5636..f55ba0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target Cargo.lock .DS_Store +rust-toolchain.toml diff --git a/core/src/form_component/impls/misc.rs b/core/src/form_component/impls/misc.rs index dbce871..fcd014c 100644 --- a/core/src/form_component/impls/misc.rs +++ b/core/src/form_component/impls/misc.rs @@ -86,33 +86,38 @@ pub mod chrono { #[derive(Clone, Debug)] pub struct NaiveDateConfig { + /// defaults to `"%F"` pub format: &'static str, } #[derive(Clone, Debug)] pub struct NaiveDateTimeConfig { + /// defaults to `"%FT%T"` pub format: &'static str, } #[derive(Clone, Debug)] pub struct FixedOffsetDateTimeConfig { + /// defaults to `"%+"` pub format: &'static str, } #[derive(Clone, Debug)] pub struct UtcDateTimeConfig { + /// defaults to `"%+"` pub format: &'static str, } #[derive(Clone, Debug)] pub struct LocalDateTimeConfig { + /// defaults to `"%FT%T"` pub format: &'static str, } impl Default for NaiveDateConfig { fn default() -> Self { - Self { format: "%x" } + Self { format: "%F" } } } impl Default for NaiveDateTimeConfig { fn default() -> Self { - Self { format: "%c" } + Self { format: "%FT%T" } } } impl Default for FixedOffsetDateTimeConfig { @@ -122,12 +127,12 @@ pub mod chrono { } impl Default for UtcDateTimeConfig { fn default() -> Self { - Self { format: "%c" } + Self { format: "%+" } } } impl Default for LocalDateTimeConfig { fn default() -> Self { - Self { format: "%c" } + Self { format: "%FT%T" } } } diff --git a/proc_macros/core/src/form.rs b/proc_macros/core/src/form.rs index 28c2d55..12e3a4b 100644 --- a/proc_macros/core/src/form.rs +++ b/proc_macros/core/src/form.rs @@ -354,7 +354,7 @@ pub fn derive_form(tokens: TokenStream) -> Result { let class = field.class.clone().or_else(|| field_class.clone()).map(StringExpr::with_oco(&leptos_krate)).into_iter(); let style = field.style.clone().or_else(|| field_style.clone()).map(StringExpr::with_oco(&leptos_krate)).into_iter(); - let config = field.config.clone() .unwrap_or_else(|| parse2(quote!( + let config = field.config.clone().unwrap_or_else(|| parse2(quote!( <#field_ty as #leptos_form_krate::FormField<#field_el_ty>>::Config::default() )).unwrap()); @@ -2963,4 +2963,208 @@ mod test { Ok(()) } + + #[test] + fn custom_config_is_correctly_provided() -> Result<(), Error> { + let leptos_form_krate = quote!(::leptos_form); + let leptos_krate = quote!(#leptos_form_krate::internal::leptos); + let leptos_router_krate = quote!(#leptos_form_krate::internal::leptos_router); + let wasm_bindgen_krate = quote!(#leptos_form_krate::internal::wasm_bindgen); + + let input = quote!( + #[derive(Form)] + #[form(component(action = "/api/my-form-data"))] + pub struct MyFormData { + #[form(config = #leptos_form_krate::NaiveDateTimeConfig { format: "%FT%T" })] + pub created_at: chrono::NaiveDateTime, + } + ); + + let expected = quote!( + #[derive(Clone, Copy, Debug)] + pub struct __MyFormDataSignal { + pub created_at: ::El>>::Signal, + } + + #[derive(Clone, Debug, Default)] + pub struct __MyFormDataConfig { + pub created_at: ::El>>::Config, + } + + impl ::core::convert::AsRef<__MyFormDataSignal> for __MyFormDataSignal { + fn as_ref(&self) -> &Self { + self + } + } + + impl ::core::convert::AsMut<__MyFormDataSignal> for __MyFormDataSignal { + fn as_mut(&mut self) -> &mut Self { + self + } + } + + impl #leptos_form_krate::DefaultHtmlElement for MyFormData { + type El = #leptos_krate::View; + } + + impl #leptos_form_krate::FormField<#leptos_krate::View> for MyFormData { + type Config = __MyFormDataConfig; + type Signal = __MyFormDataSignal; + fn default_signal(config: &Self::Config, initial: Option) -> Self::Signal { + match initial { + Some(initial) => { + __MyFormDataSignal { + created_at: ::El, + >>::default_signal(&config.created_at, Some(initial.created_at)), + } + } + None => { + __MyFormDataSignal { + created_at: ::El, + >>::default_signal(&config.created_at, None), + } + } + } + } + fn is_initial_value(signal: &Self::Signal) -> bool { + true && ::El>>::is_initial_value(&signal.created_at) + } + fn into_signal(self, config: &Self::Config, initial: Option) -> Self::Signal { + match initial { + Some(initial) => { + __MyFormDataSignal { + created_at: ::El, + >>::into_signal( + self.created_at, + &config.created_at, + Some(initial.created_at), + ), + } + } + None => { + __MyFormDataSignal { + created_at: ::El, + >>::into_signal(self.created_at, &config.created_at, None), + } + } + } + } + fn try_from_signal(signal: Self::Signal, config: &Self::Config) -> Result { + Ok(MyFormData { + created_at: ::El>>::try_from_signal(signal.created_at, &config.created_at)?, + }) + } + fn recurse(signal: &Self::Signal) { + ::El, + >>::recurse(&signal.created_at); + } + fn reset_initial_value(signal: &Self::Signal) { + ::El>>::reset_initial_value(&signal.created_at); + } + } + + impl #leptos_form_krate::FormComponent<#leptos_krate::View> for MyFormData { + #[allow(unused_imports)] + fn render(props: #leptos_form_krate::RenderProps) -> impl #leptos_krate::IntoView { + use #leptos_form_krate::FormField; + use #leptos_krate::{IntoAttribute, IntoView}; + + let _created_at_id = #leptos_form_krate::format_form_id(props.id.as_ref(), #leptos_krate::Oco::Borrowed("created-at")); + let _created_at_name = #leptos_form_krate::format_form_name(props.name.as_ref(), "created_at"); + let _created_at_props = #leptos_form_krate::RenderProps::builder() + .id(_created_at_id.clone()) + .name(_created_at_name.clone()) + .field_changed_class(props.field_changed_class.clone()) + .signal(props.signal.created_at.clone()) + .config(#leptos_form_krate::NaiveDateTimeConfig { format: "%FT%T" }) + .build(); + + let _created_at_error = move || ::El>>::with_error( + &_created_at_props.signal, + |error| match error { + Some(form_error) => { + let error = format!("{form_error}"); + #leptos_krate::IntoView::into_view(#leptos_krate::view! { {error} }) + }, + None => #leptos_krate::View::default(), + }, + ); + let ty = <::std::marker::PhantomData<(chrono::NaiveDateTime, ::El)> as Default>::default(); + let _created_at_view = #leptos_krate::view! { }; + + #leptos_krate::view! { + + } + } + } + + pub use leptos_form_component_my_form_data::*; + mod leptos_form_component_my_form_data { + use super::*; + use #leptos_krate::IntoView; + use #wasm_bindgen_krate::{closure::Closure, JsCast, UnwrapThrowExt,}; + #[allow(unused_imports)] + #[#leptos_krate::component] + pub fn MyFormData( + mut initial: MyFormData, + #[prop(optional, into)] + top: Option<#leptos_form_krate::components::LeptosFormChildren>, + #[prop(optional, into)] + bottom: Option<#leptos_form_krate::components::LeptosFormChildren>, + ) -> impl IntoView { + use #leptos_form_krate::{FormField, components::FormSubmissionHandler}; + use #leptos_krate::{IntoAttribute, IntoView, SignalGet, SignalUpdate, SignalWith,}; + use #wasm_bindgen_krate::UnwrapThrowExt; + use #leptos_router_krate::Form; + use ::std::rc::Rc; + let config = __MyFormDataConfig { + created_at: #leptos_form_krate::NaiveDateTimeConfig { + format: "%FT%T", + }, + }; + let signal = #leptos_krate::create_rw_signal( + #leptos_form_krate::RenderProps::builder() + .id(None) + .name("") + .signal(initial.clone().into_signal(&config, Some(initial.clone()))) + .config(config.clone()) + .build(), + ); + let _had_reset_called = #leptos_krate::create_rw_signal(false); + let parse_error_handler = |err: #leptos_form_krate::FormError| { + #leptos_krate::logging::debug_warn!("{err}") + }; + let ty = <::std::marker::PhantomData< + (MyFormData, #leptos_krate::View), + > as Default>::default(); + #leptos_krate::view! { + < Form action = "/api/my-form-data" > { top.map(| x | (x.0)()) } { move || + #leptos_krate::view! { < FormField props =signal.get() ty + = ty / > } } { bottom.map(| x | (x.0) ()) } < / Form > + } + } + } + ); + + let output = derive_form(input)?; + + let expected = cleanup(&expected); + let output = cleanup(&output); + + let expected = pretty(expected)?; + let output = pretty(output)?; + + assert_eq!(expected, output); + + Ok(()) + } } From 2e6239b71ce0de1fc5269362bf4d33770305de78 Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Thu, 14 Dec 2023 17:46:46 -0800 Subject: [PATCH 05/17] replace derived Default implementation for Form type Config structs with a custom Default implementation which correctly uses custom field config values provided through the Form macro --- proc_macros/core/src/form.rs | 68 +++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/proc_macros/core/src/form.rs b/proc_macros/core/src/form.rs index 12e3a4b..2ea17c2 100644 --- a/proc_macros/core/src/form.rs +++ b/proc_macros/core/src/form.rs @@ -881,7 +881,7 @@ pub fn derive_form(tokens: TokenStream) -> Result { pound_token: Default::default(), style: syn::AttrStyle::Outer, bracket_token: Default::default(), - meta: parse2(quote!(derive(Clone, Debug, Default)))?, + meta: parse2(quote!(derive(Clone, Debug)))?, }], vis: syn::Visibility::Public(Default::default()), struct_token: Default::default(), @@ -907,6 +907,12 @@ pub fn derive_form(tokens: TokenStream) -> Result { #config_struct_def + impl Default for #config_ty { + fn default() -> Self { + Self { #(#field_axs: #configs,)* } + } + } + impl ::core::convert::AsRef<#signal_ty> for #signal_ty { fn as_ref(&self) -> &Self { self @@ -2014,7 +2020,7 @@ mod test { pub count: ::El>>::Signal, } - #[derive(Clone, Debug, Default)] + #[derive(Clone, Debug)] pub struct __MyFormDataConfig { pub id: ::El>>::Config, pub slug: ::El>>::Config, @@ -2022,6 +2028,17 @@ mod test { pub count: ::El>>::Config, } + impl Default for __MyFormDataConfig { + fn default() -> Self { + Self { + id: ::El>>::Config::default(), + slug: ::El>>::Config::default(), + created_at: ::El>>::Config::default(), + count: ::El>>::Config::default(), + } + } + } + impl ::core::convert::AsRef<__MyFormDataSignal> for __MyFormDataSignal { fn as_ref(&self) -> &Self { self @@ -2312,12 +2329,21 @@ mod test { pub zz: ::El>>::Signal, } - #[derive(Clone, Debug, Default)] + #[derive(Clone, Debug)] pub struct __MyFormDataConfig { pub abc_123: ::El>>::Config, pub zz: ::El>>::Config, } + impl Default for __MyFormDataConfig { + fn default() -> Self { + Self { + abc_123: ::El>>::Config::default(), + zz: ::El>>::Config::default(), + } + } + } + impl ::core::convert::AsRef<__MyFormDataSignal> for __MyFormDataSignal { fn as_ref(&self) -> &Self { self @@ -2513,11 +2539,19 @@ mod test { pub ayo: ::El>>::Signal, } - #[derive(Clone, Debug, Default)] + #[derive(Clone, Debug)] pub struct __MyFormDataConfig { pub ayo: ::El>>::Config, } + impl Default for __MyFormDataConfig { + fn default() -> Self { + Self { + ayo: ::El>>::Config::default(), + } + } + } + impl ::core::convert::AsRef<__MyFormDataSignal> for __MyFormDataSignal { fn as_ref(&self) -> &Self { self @@ -2729,11 +2763,19 @@ mod test { pub ayo: ::El>>::Signal, } - #[derive(Clone, Debug, Default)] + #[derive(Clone, Debug)] pub struct __MyFormDataConfig { pub ayo: ::El>>::Config, } + impl Default for __MyFormDataConfig { + fn default() -> Self { + Self { + ayo: ::El>>::Config::default(), + } + } + } + impl ::core::convert::AsRef<__MyFormDataSignal> for __MyFormDataSignal { fn as_ref(&self) -> &Self { self @@ -2975,7 +3017,7 @@ mod test { #[derive(Form)] #[form(component(action = "/api/my-form-data"))] pub struct MyFormData { - #[form(config = #leptos_form_krate::NaiveDateTimeConfig { format: "%FT%T" })] + #[form(config = #leptos_form_krate::NaiveDateTimeConfig { format: "%c" })] pub created_at: chrono::NaiveDateTime, } ); @@ -2986,11 +3028,19 @@ mod test { pub created_at: ::El>>::Signal, } - #[derive(Clone, Debug, Default)] + #[derive(Clone, Debug)] pub struct __MyFormDataConfig { pub created_at: ::El>>::Config, } + impl Default for __MyFormDataConfig { + fn default() -> Self { + Self { + created_at: #leptos_form_krate::NaiveDateTimeConfig { format: "%c" } + } + } + } + impl ::core::convert::AsRef<__MyFormDataSignal> for __MyFormDataSignal { fn as_ref(&self) -> &Self { self @@ -3081,7 +3131,7 @@ mod test { .name(_created_at_name.clone()) .field_changed_class(props.field_changed_class.clone()) .signal(props.signal.created_at.clone()) - .config(#leptos_form_krate::NaiveDateTimeConfig { format: "%FT%T" }) + .config(#leptos_form_krate::NaiveDateTimeConfig { format: "%c" }) .build(); let _created_at_error = move || ::El>>::with_error( @@ -3128,7 +3178,7 @@ mod test { use ::std::rc::Rc; let config = __MyFormDataConfig { created_at: #leptos_form_krate::NaiveDateTimeConfig { - format: "%FT%T", + format: "%c", }, }; let signal = #leptos_krate::create_rw_signal( From 9cd435b8ed077525ab95a791147fb96142520a9a Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Thu, 14 Dec 2023 18:47:31 -0800 Subject: [PATCH 06/17] remove incorrect short circuit in Option's implementation of FormField::try_from_signal when the current value was equivalent to the initial value -- fixes bug which skipped serializing optional form fields into local storage --- core/src/cache.rs | 2 +- core/src/form_component/mod.rs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/core/src/cache.rs b/core/src/cache.rs index a1714f9..80b4853 100644 --- a/core/src/cache.rs +++ b/core/src/cache.rs @@ -56,7 +56,7 @@ impl SerdeSerializer for SerdeJson { } #[cfg(feature = "cache-local-storage")] -impl, T> Cache for LocalStorage { +impl> Cache for LocalStorage { type Error = CS::Error; fn get_item(&self, key: &str) -> impl Future, CS::Error>> + Send { use wasm_bindgen::UnwrapThrowExt; diff --git a/core/src/form_component/mod.rs b/core/src/form_component/mod.rs index 02c5b1e..56700ac 100644 --- a/core/src/form_component/mod.rs +++ b/core/src/form_component/mod.rs @@ -162,10 +162,7 @@ where } } fn try_from_signal(signal: Self::Signal, config: &Self::Config) -> Result { - match Self::is_initial_value(&signal) { - true => Ok(None), - false => Ok(Some(T::try_from_signal(signal, config)?)), - } + Ok(Some(T::try_from_signal(signal, config)?)) } fn recurse(signal: &Self::Signal) { T::recurse(signal) From 807c98bde43b695110a3d74f230c60f25fc82d95 Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Thu, 14 Dec 2023 23:00:15 -0800 Subject: [PATCH 07/17] add FormField::is_default_value method which is now used where is_initial_value used to be used when computing as FormField<..>>::try_from_signal --- core/src/form_component/impls/collections.rs | 3 +++ core/src/form_component/impls/misc.rs | 26 +++++++++++++++----- core/src/form_component/impls/num.rs | 13 +++++++--- core/src/form_component/impls/str.rs | 13 +++++++--- core/src/form_component/mod.rs | 14 +++++++++-- proc_macros/core/src/form.rs | 24 ++++++++++++++++++ 6 files changed, 79 insertions(+), 14 deletions(-) diff --git a/core/src/form_component/impls/collections.rs b/core/src/form_component/impls/collections.rs index 4ba5a43..9939f51 100644 --- a/core/src/form_component/impls/collections.rs +++ b/core/src/form_component/impls/collections.rs @@ -155,6 +155,9 @@ where .collect::>() })) } + fn is_default_value(signal: &Self::Signal) -> bool { + signal.value.with(|value| value.is_empty()) + } fn is_initial_value(signal: &Self::Signal) -> bool { signal.initial.with(|initial| { signal.value.with(|value| match initial.as_ref() { diff --git a/core/src/form_component/impls/misc.rs b/core/src/form_component/impls/misc.rs index fcd014c..0ec2adf 100644 --- a/core/src/form_component/impls/misc.rs +++ b/core/src/form_component/impls/misc.rs @@ -20,6 +20,9 @@ mod uuid { fn default_signal(config: &Self::Config, initial: Option) -> Self::Signal { FormFieldSignal::new_with_default_value(initial.map(|x| x.to_string())) } + fn is_default_value(signal: &Self::Signal) -> bool { + signal.value.with(|value| value.is_empty()) + } fn is_initial_value(signal: &Self::Signal) -> bool { signal.value.with(|value| { signal.initial.with(|initial| match initial { @@ -62,9 +65,13 @@ mod uuid { name={props.name} on:input=move |ev| props.signal.value.update(|value| *value = event_target_value(&ev)) on:change=move |_| { - if let Err(form_error) = >>::try_from_signal(props.signal, &props.config) { - props.signal.error.update(|error| *error = Some(form_error)); - } else if props.signal.error.with_untracked(|error| error.is_some()) { + if !props.is_optional || !>>::is_default_value(&props.signal) { + if let Err(form_error) = >>::try_from_signal(props.signal, &props.config) { + props.signal.error.update(|error| *error = Some(form_error)); + } else if props.signal.error.with_untracked(|error| error.is_some()) { + props.signal.error.update(|error| *error = None); + } + } else { props.signal.error.update(|error| *error = None); } } @@ -153,6 +160,9 @@ pub mod chrono { fn default_signal(config: &Self::Config, initial: Option) -> Self::Signal { FormFieldSignal::new_with_default_value(initial.map(|x| x.format(config.format).to_string())) } + fn is_default_value(signal: &Self::Signal) -> bool { + signal.value.with(|value| value.is_empty()) + } fn is_initial_value(signal: &Self::Signal) -> bool { signal.value.with(|value| signal.initial.with(|initial| match initial { Some(initial) => initial == value, @@ -186,9 +196,13 @@ pub mod chrono { name={props.name} on:input=move |ev| props.signal.value.update(|value| *value = event_target_value(&ev)) on:change=move |_| { - if let Err(form_error) = >>::try_from_signal(props.signal, &props.config) { - props.signal.error.update(|error| *error = Some(form_error)); - } else if props.signal.error.with_untracked(|error| error.is_some()) { + if !props.is_optional || !Self::is_default_value(&props.signal) { + if let Err(form_error) = >>::try_from_signal(props.signal, &props.config) { + props.signal.error.update(|error| *error = Some(form_error)); + } else if props.signal.error.with_untracked(|error| error.is_some()) { + props.signal.error.update(|error| *error = None); + } + } else { props.signal.error.update(|error| *error = None); } } diff --git a/core/src/form_component/impls/num.rs b/core/src/form_component/impls/num.rs index f9914d8..0665ff3 100644 --- a/core/src/form_component/impls/num.rs +++ b/core/src/form_component/impls/num.rs @@ -16,6 +16,9 @@ macro_rules! num_impl { fn default_signal(_: &Self::Config, initial: Option) -> Self::Signal { FormFieldSignal::new_with_default_value(initial.map(|x| x.to_string())) } + fn is_default_value(signal: &Self::Signal) -> bool { + signal.value.with(|value| value.is_empty()) + } fn is_initial_value(signal: &Self::Signal) -> bool { signal.value.with(|value| signal.initial.with(|initial| match initial { Some(initial) => initial == value, @@ -53,9 +56,13 @@ macro_rules! num_impl { on:keydown=num_impl!(@prevent_invalid_keystrokes value $($($type)?)?) on:input=move |ev| props.signal.value.update(|value| *value = event_target_value(&ev)) on:change=move |_| { - if let Err(form_error) = >>::try_from_signal(props.signal, &props.config) { - props.signal.error.update(|error| *error = Some(form_error)); - } else if props.signal.error.with_untracked(|error| error.is_some()) { + if !props.is_optional || !>>::is_default_value(&props.signal) { + if let Err(form_error) = >>::try_from_signal(props.signal, &props.config) { + props.signal.error.update(|error| *error = Some(form_error)); + } else if props.signal.error.with_untracked(|error| error.is_some()) { + props.signal.error.update(|error| *error = None); + } + } else { props.signal.error.update(|error| *error = None); } } diff --git a/core/src/form_component/impls/str.rs b/core/src/form_component/impls/str.rs index a4b6838..f7b9f6d 100644 --- a/core/src/form_component/impls/str.rs +++ b/core/src/form_component/impls/str.rs @@ -22,6 +22,9 @@ macro_rules! str_impl { fn default_signal(_: &Self::Config, initial: Option) -> Self::Signal { FormFieldSignal::new_with_default_value(initial.map(|x| x.to_string())) } + fn is_default_value(signal: &Self::Signal) -> bool { + signal.value.with(|value| value.is_empty()) + } fn is_initial_value(signal: &Self::Signal) -> bool { signal.value.with(|value| signal.initial.with(|initial| { match initial { @@ -58,9 +61,13 @@ macro_rules! str_impl { name={props.name} on:input=move |ev| props.signal.value.update(|value| *value = event_target_value(&ev)) on:change=move |_| { - if let Err(form_error) = >>::try_from_signal(props.signal, &props.config) { - props.signal.error.update(|error| *error = Some(form_error)); - } else if props.signal.error.with_untracked(|error| error.is_some()) { + if !props.is_optional || !>>::is_default_value(&props.signal) { + if let Err(form_error) = >>::try_from_signal(props.signal, &props.config) { + props.signal.error.update(|error| *error = Some(form_error)); + } else if props.signal.error.with_untracked(|error| error.is_some()) { + props.signal.error.update(|error| *error = None); + } + } else { props.signal.error.update(|error| *error = None); } } diff --git a/core/src/form_component/mod.rs b/core/src/form_component/mod.rs index 56700ac..4cab9c0 100644 --- a/core/src/form_component/mod.rs +++ b/core/src/form_component/mod.rs @@ -34,6 +34,7 @@ pub trait FormField: Sized { type Signal: Clone + 'static; fn default_signal(config: &Self::Config, initial: Option) -> Self::Signal; + fn is_default_value(signal: &Self::Signal) -> bool; fn is_initial_value(signal: &Self::Signal) -> bool; fn into_signal(self, config: &Self::Config, initial: Option) -> Self::Signal; fn try_from_signal(signal: Self::Signal, config: &Self::Config) -> Result; @@ -74,6 +75,8 @@ pub struct RenderProps { pub style: Option>, #[builder(default)] pub field_changed_class: Option>, + #[builder(default)] + pub is_optional: bool, pub signal: T, pub config: Config, } @@ -152,6 +155,9 @@ where fn default_signal(config: &Self::Config, initial: Option) -> Self::Signal { T::default_signal(config, initial.flatten()) } + fn is_default_value(signal: &Self::Signal) -> bool { + T::is_default_value(signal) + } fn is_initial_value(signal: &Self::Signal) -> bool { T::is_initial_value(signal) } @@ -162,7 +168,10 @@ where } } fn try_from_signal(signal: Self::Signal, config: &Self::Config) -> Result { - Ok(Some(T::try_from_signal(signal, config)?)) + match Self::is_default_value(&signal) { + true => Ok(None), + false => Ok(Some(T::try_from_signal(signal, config)?)), + } } fn recurse(signal: &Self::Signal) { T::recurse(signal) @@ -182,7 +191,8 @@ impl FormComponent for Option where T: FormComponent, { - fn render(props: RenderProps) -> impl IntoView { + fn render(mut props: RenderProps) -> impl IntoView { + props.is_optional = true; T::render(props) } } diff --git a/proc_macros/core/src/form.rs b/proc_macros/core/src/form.rs index 2ea17c2..3bd89fb 100644 --- a/proc_macros/core/src/form.rs +++ b/proc_macros/core/src/form.rs @@ -943,6 +943,11 @@ pub fn derive_form(tokens: TokenStream) -> Result { }, } } + fn is_default_value(signal: &Self::Signal) -> bool { + true #(&& + <#field_tys as #leptos_form_krate::FormField<#field_el_tys>>::is_default_value(&signal.#field_axs) + )* + } fn is_initial_value(signal: &Self::Signal) -> bool { true #(&& <#field_tys as #leptos_form_krate::FormField<#field_el_tys>>::is_initial_value(&signal.#field_axs) @@ -2094,6 +2099,12 @@ mod test { } } } + fn is_default_value(signal: &Self::Signal) -> bool { + true && ::El>>::is_default_value(&signal.id) && + ::El>>::is_default_value(&signal.slug) && + ::El>>::is_default_value(&signal.created_at) && + ::El>>::is_default_value(&signal.count) + } fn is_initial_value(signal: &Self::Signal) -> bool { true && ::El>>::is_initial_value(&signal.id) && ::El>>::is_initial_value(&signal.slug) && @@ -2388,6 +2399,10 @@ mod test { } } } + fn is_default_value(signal: &Self::Signal) -> bool { + true && ::El>>::is_default_value(&signal.abc_123) && + ::El>>::is_default_value(&signal.zz) + } fn is_initial_value(signal: &Self::Signal) -> bool { true && ::El>>::is_initial_value(&signal.abc_123) && ::El>>::is_initial_value(&signal.zz) @@ -2582,6 +2597,9 @@ mod test { }, } } + fn is_default_value(signal: &Self::Signal) -> bool { + true && ::El>>::is_default_value(&signal.ayo) + } fn is_initial_value(signal: &Self::Signal) -> bool { true && ::El>>::is_initial_value(&signal.ayo) } @@ -2814,6 +2832,9 @@ mod test { } } } + fn is_default_value(signal: &Self::Signal) -> bool { + true && ::El>>::is_default_value(&signal.ayo) + } fn is_initial_value(signal: &Self::Signal) -> bool { true && ::El>>::is_initial_value(&signal.ayo) } @@ -3078,6 +3099,9 @@ mod test { } } } + fn is_default_value(signal: &Self::Signal) -> bool { + true && ::El>>::is_default_value(&signal.created_at) + } fn is_initial_value(signal: &Self::Signal) -> bool { true && ::El>>::is_initial_value(&signal.created_at) } From fa27c9e6e16df42ccda3d1b28e43f52da05f328c Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Thu, 14 Dec 2023 23:40:21 -0800 Subject: [PATCH 08/17] fix: corrected behavior in FormFieldSignal::has_changed when no initial value is set has_changed now compares the current value to the default value of the internal type of the signal when the initial value in the signal is None also removed the potentially confusing FormField::is_initial_value method which is no longer used --- core/src/form_component/impls/collections.rs | 15 ------------ core/src/form_component/impls/misc.rs | 14 ------------ core/src/form_component/impls/num.rs | 6 ----- core/src/form_component/impls/str.rs | 8 ------- core/src/form_component/mod.rs | 12 ++++------ proc_macros/core/src/form.rs | 24 -------------------- 6 files changed, 4 insertions(+), 75 deletions(-) diff --git a/core/src/form_component/impls/collections.rs b/core/src/form_component/impls/collections.rs index 9939f51..b1946f1 100644 --- a/core/src/form_component/impls/collections.rs +++ b/core/src/form_component/impls/collections.rs @@ -158,21 +158,6 @@ where fn is_default_value(signal: &Self::Signal) -> bool { signal.value.with(|value| value.is_empty()) } - fn is_initial_value(signal: &Self::Signal) -> bool { - signal.initial.with(|initial| { - signal.value.with(|value| match initial.as_ref() { - Some(initial) => { - let no_keys_changed = value.len() == initial.len() - && value.last().map(|item| item.0) == initial.last().map(|item| item.0); - if !no_keys_changed { - return false; - } - value.iter().all(|(_, item)| T::is_initial_value(&item.signal)) - } - None => value.is_empty(), - }) - }) - } fn into_signal(self, config: &Self::Config, initial: Option) -> Self::Signal { let has_initial = initial.is_some(); let mut initial = initial diff --git a/core/src/form_component/impls/misc.rs b/core/src/form_component/impls/misc.rs index 0ec2adf..37837a6 100644 --- a/core/src/form_component/impls/misc.rs +++ b/core/src/form_component/impls/misc.rs @@ -23,14 +23,6 @@ mod uuid { fn is_default_value(signal: &Self::Signal) -> bool { signal.value.with(|value| value.is_empty()) } - fn is_initial_value(signal: &Self::Signal) -> bool { - signal.value.with(|value| { - signal.initial.with(|initial| match initial { - Some(initial) => initial == value, - None => value.is_empty(), - }) - }) - } fn into_signal(self, _: &Self::Config, initial: Option) -> Self::Signal { FormFieldSignal::new(self.to_string(), initial.map(|x| x.to_string())) } @@ -163,12 +155,6 @@ pub mod chrono { fn is_default_value(signal: &Self::Signal) -> bool { signal.value.with(|value| value.is_empty()) } - fn is_initial_value(signal: &Self::Signal) -> bool { - signal.value.with(|value| signal.initial.with(|initial| match initial { - Some(initial) => initial == value, - None => value.is_empty(), - })) - } fn into_signal(self, config: &Self::Config, initial: Option) -> Self::Signal { FormFieldSignal::new(self.format(config.format).to_string(), initial.map(|initial| initial.format(config.format).to_string())) } diff --git a/core/src/form_component/impls/num.rs b/core/src/form_component/impls/num.rs index 0665ff3..7032e30 100644 --- a/core/src/form_component/impls/num.rs +++ b/core/src/form_component/impls/num.rs @@ -19,12 +19,6 @@ macro_rules! num_impl { fn is_default_value(signal: &Self::Signal) -> bool { signal.value.with(|value| value.is_empty()) } - fn is_initial_value(signal: &Self::Signal) -> bool { - signal.value.with(|value| signal.initial.with(|initial| match initial { - Some(initial) => initial == value, - None => value.is_empty(), - })) - } fn into_signal(self, _: &Self::Config, initial: Option) -> Self::Signal { FormFieldSignal::new(self.to_string(), initial.map(|x| x.to_string())) } diff --git a/core/src/form_component/impls/str.rs b/core/src/form_component/impls/str.rs index f7b9f6d..8fd4222 100644 --- a/core/src/form_component/impls/str.rs +++ b/core/src/form_component/impls/str.rs @@ -25,14 +25,6 @@ macro_rules! str_impl { fn is_default_value(signal: &Self::Signal) -> bool { signal.value.with(|value| value.is_empty()) } - fn is_initial_value(signal: &Self::Signal) -> bool { - signal.value.with(|value| signal.initial.with(|initial| { - match initial { - Some(initial) => initial == value, - None => value.is_empty(), - } - })) - } fn into_signal(self, _: &Self::Config, initial: Option) -> Self::Signal { FormFieldSignal::new(self.to_string(), initial.map(|x| x.to_string())) } diff --git a/core/src/form_component/mod.rs b/core/src/form_component/mod.rs index 4cab9c0..9a0bae1 100644 --- a/core/src/form_component/mod.rs +++ b/core/src/form_component/mod.rs @@ -35,7 +35,6 @@ pub trait FormField: Sized { fn default_signal(config: &Self::Config, initial: Option) -> Self::Signal; fn is_default_value(signal: &Self::Signal) -> bool; - fn is_initial_value(signal: &Self::Signal) -> bool; fn into_signal(self, config: &Self::Config, initial: Option) -> Self::Signal; fn try_from_signal(signal: Self::Signal, config: &Self::Config) -> Result; fn recurse(signal: &Self::Signal); @@ -92,7 +91,7 @@ pub struct FormFieldSignal { pub error: RwSignal>, } -impl RenderProps, Config> { +impl RenderProps, Config> { pub fn class_signal(&self) -> RwSignal>> { let signal = self.signal; let class = self.class.clone(); @@ -130,12 +129,12 @@ impl RenderProps FormFieldSignal { +impl FormFieldSignal { pub fn has_changed(&self) -> bool { self.value.with(|value| { self.initial.with(|initial| match initial { Some(initial) => *initial != *value, - None => true, + None => value != &T::default(), }) }) } @@ -158,9 +157,6 @@ where fn is_default_value(signal: &Self::Signal) -> bool { T::is_default_value(signal) } - fn is_initial_value(signal: &Self::Signal) -> bool { - T::is_initial_value(signal) - } fn into_signal(self, config: &Self::Config, initial: Option) -> Self::Signal { match self { Some(value) => T::into_signal(value, config, initial.flatten()), @@ -208,7 +204,7 @@ impl Default for FormFieldSignal { } } -impl FormFieldSignal { +impl FormFieldSignal { fn new(value: T, initial: Option) -> Self { Self { value: create_rw_signal(value), diff --git a/proc_macros/core/src/form.rs b/proc_macros/core/src/form.rs index 3bd89fb..eccbfe5 100644 --- a/proc_macros/core/src/form.rs +++ b/proc_macros/core/src/form.rs @@ -948,11 +948,6 @@ pub fn derive_form(tokens: TokenStream) -> Result { <#field_tys as #leptos_form_krate::FormField<#field_el_tys>>::is_default_value(&signal.#field_axs) )* } - fn is_initial_value(signal: &Self::Signal) -> bool { - true #(&& - <#field_tys as #leptos_form_krate::FormField<#field_el_tys>>::is_initial_value(&signal.#field_axs) - )* - } fn into_signal(self, #config_var_ident: &Self::Config, initial: Option) -> Self::Signal { match initial { Some(initial) => #signal_ty { @@ -2105,12 +2100,6 @@ mod test { ::El>>::is_default_value(&signal.created_at) && ::El>>::is_default_value(&signal.count) } - fn is_initial_value(signal: &Self::Signal) -> bool { - true && ::El>>::is_initial_value(&signal.id) && - ::El>>::is_initial_value(&signal.slug) && - ::El>>::is_initial_value(&signal.created_at) && - ::El>>::is_initial_value(&signal.count) - } fn into_signal(self, config: &Self::Config, initial: Option) -> Self::Signal { match initial { Some(initial) => { @@ -2403,10 +2392,6 @@ mod test { true && ::El>>::is_default_value(&signal.abc_123) && ::El>>::is_default_value(&signal.zz) } - fn is_initial_value(signal: &Self::Signal) -> bool { - true && ::El>>::is_initial_value(&signal.abc_123) && - ::El>>::is_initial_value(&signal.zz) - } fn into_signal(self, config: &Self::Config, initial: Option) -> Self::Signal { match initial { Some(initial) => { @@ -2600,9 +2585,6 @@ mod test { fn is_default_value(signal: &Self::Signal) -> bool { true && ::El>>::is_default_value(&signal.ayo) } - fn is_initial_value(signal: &Self::Signal) -> bool { - true && ::El>>::is_initial_value(&signal.ayo) - } fn into_signal(self, config: &Self::Config, initial: Option) -> Self::Signal { match initial { Some(initial) => { @@ -2835,9 +2817,6 @@ mod test { fn is_default_value(signal: &Self::Signal) -> bool { true && ::El>>::is_default_value(&signal.ayo) } - fn is_initial_value(signal: &Self::Signal) -> bool { - true && ::El>>::is_initial_value(&signal.ayo) - } fn into_signal(self, config: &Self::Config, initial: Option) -> Self::Signal { match initial { Some(initial) => { @@ -3102,9 +3081,6 @@ mod test { fn is_default_value(signal: &Self::Signal) -> bool { true && ::El>>::is_default_value(&signal.created_at) } - fn is_initial_value(signal: &Self::Signal) -> bool { - true && ::El>>::is_initial_value(&signal.created_at) - } fn into_signal(self, config: &Self::Config, initial: Option) -> Self::Signal { match initial { Some(initial) => { From 32d37206ec6d46b72c6fa0c2767fd5a997662e35 Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Thu, 14 Dec 2023 23:51:19 -0800 Subject: [PATCH 09/17] convert clippy warnings to errors in pre-commit hook to mimic pre-push hook behavior --- .pre-commit-config.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 98a8852..2bb3ea7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -77,6 +77,9 @@ repos: - --fix - --allow-dirty - --allow-staged + - -- + - -D + - warnings language: system types: [file] files: (\.rs|Cargo\.toml)$ From 9be03d1fea5e686e3ecdadf8557b86277197a2f2 Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Thu, 28 Dec 2023 15:12:57 -0800 Subject: [PATCH 10/17] move CI toolchain to stable --- .github/workflows/continuous_integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index 51ad882..cc57ae1 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -17,7 +17,7 @@ jobs: - name: Install Rust toolchain uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2023-11-01 + toolchain: stable components: clippy,rustfmt - uses: Swatinem/rust-cache@v2 From 93e9438ef7480886d02ee5263a1a0d82e0aacc58 Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:54:49 -0800 Subject: [PATCH 11/17] chore: bump leptos versions to 0.6.0-beta --- Cargo.toml | 4 ++-- proc_macros/docs/Form/README.md | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7f8e7a..8e0d468 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,8 +29,8 @@ indexmap = "2" inner = "0" itertools = "~0.12" js-sys = "~0.3" -leptos = { git = "https://github.com/leptos-rs/leptos", rev = "ed61ea9" } -leptos_router = { git = "https://github.com/leptos-rs/leptos", rev = "ed61ea9" } +leptos = "0.6.0-beta" +leptos_router = "0.6.0-beta" num-bigint = { version = "~0.4", default-features = false } paste = "~1" prettyplease = "0.2" diff --git a/proc_macros/docs/Form/README.md b/proc_macros/docs/Form/README.md index 0116f4d..7fab2b2 100644 --- a/proc_macros/docs/Form/README.md +++ b/proc_macros/docs/Form/README.md @@ -63,12 +63,16 @@ An action can be specified one of two ways: - a path to a server function specified in a particular way: ```rust mod my_mod { - #[derive(Clone, Debug, leptos_form::Form, serde::Deserialize, serde::Serialize)] + use leptos::{server, ServerFnError}; + use leptos_form::Form; + use serde::{Deserialize, Serialize}; + + #[derive(Clone, Debug, Deserialize, Form, Serialize)] #[form(component(action = my_server_fn(my_data)))] struct MyForm {} - #[leptos::server] - async fn my_server_fn(my_data: MyForm) -> Result<(), leptos::ServerFnError> { + #[server] + async fn my_server_fn(my_data: MyForm) -> Result<(), ServerFnError> { Ok(()) } } From 90c44732fd26dda4b754dbe50c4d37b1b3a67da9 Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Sun, 21 Jan 2024 18:00:56 -0800 Subject: [PATCH 12/17] chore!: bump version to 0.2.0-alpha --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8e0d468..cb99c95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ resolver = "2" [workspace.package] # update the internal crate versions when updating this workspace version -version = "0.1.8" +version = "0.2.0-alpha" edition = "2021" rust-version = "1.75.0" authors = ["Trey Lowerison <19714082+tlowerison@users.noreply.github.com>"] @@ -15,9 +15,9 @@ keywords = ["leptos", "form", "derive-macros", "ui"] [workspace.dependencies] # internal to this workspace -leptos_form_core = { version = "=0.1.8", path = "core" } -leptos_form_proc_macros = { version = "=0.1.8", path = "proc_macros" } -leptos_form_proc_macros_core = { version = "=0.1.8", path = "proc_macros/core" } +leptos_form_core = { version = "=0.2.0-alpha", path = "core" } +leptos_form_proc_macros = { version = "=0.2.0-alpha", path = "proc_macros" } +leptos_form_proc_macros_core = { version = "=0.2.0-alpha", path = "proc_macros/core" } bigdecimal = "~0.4" chrono = { version = "0", features = ["std"] } From cd7cd2b4aefd8331d710e755e71d13a0ffd51e87 Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Sun, 21 Jan 2024 18:03:18 -0800 Subject: [PATCH 13/17] chore: change version to 0.2.0-beta --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cb99c95..908e467 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ resolver = "2" [workspace.package] # update the internal crate versions when updating this workspace version -version = "0.2.0-alpha" +version = "0.2.0-beta" edition = "2021" rust-version = "1.75.0" authors = ["Trey Lowerison <19714082+tlowerison@users.noreply.github.com>"] @@ -15,9 +15,9 @@ keywords = ["leptos", "form", "derive-macros", "ui"] [workspace.dependencies] # internal to this workspace -leptos_form_core = { version = "=0.2.0-alpha", path = "core" } -leptos_form_proc_macros = { version = "=0.2.0-alpha", path = "proc_macros" } -leptos_form_proc_macros_core = { version = "=0.2.0-alpha", path = "proc_macros/core" } +leptos_form_core = { version = "=0.2.0-beta", path = "core" } +leptos_form_proc_macros = { version = "=0.2.0-beta", path = "proc_macros" } +leptos_form_proc_macros_core = { version = "=0.2.0-beta", path = "proc_macros/core" } bigdecimal = "~0.4" chrono = { version = "0", features = ["std"] } From 9bf2a7da22739d841384324e2bfd8d79d943e374 Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Mon, 22 Jan 2024 15:15:16 -0800 Subject: [PATCH 14/17] chore: prevent cargo doc from failing CI pipeline --- .pre-commit-config.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2bb3ea7..6aa40d1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -118,12 +118,14 @@ repos: entry: sh args: - -c - - "RUSTDOCFLAGS=\"-D warnings\" cargo doc --all-features" + # `|| true` prevents this stage from breaking the pre-commit if fails + - "RUSTDOCFLAGS=\"-D warnings\" cargo doc --all-features || true" language: system types: [file] files: (\.md|\.rs|Cargo\.toml)$ exclude: (CHANGELOG|DEVELOPMENT)\.md$ pass_filenames: false + verbose: true - id: cargo-test name: cargo-test From 2184adabe98ae62bcbb833439fa43d53a7281d0d Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Mon, 22 Jan 2024 15:26:06 -0800 Subject: [PATCH 15/17] chore: temporarily disable cargo doc in pre-commit until server_fn's documentation is building --- .pre-commit-config.yaml | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6aa40d1..e5dd99b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -111,21 +111,19 @@ repos: types: [rust] args: ["--"] - - id: cargo-doc - name: cargo-doc - description: ensure cargo doc builds - stages: [push] - entry: sh - args: - - -c - # `|| true` prevents this stage from breaking the pre-commit if fails - - "RUSTDOCFLAGS=\"-D warnings\" cargo doc --all-features || true" - language: system - types: [file] - files: (\.md|\.rs|Cargo\.toml)$ - exclude: (CHANGELOG|DEVELOPMENT)\.md$ - pass_filenames: false - verbose: true + # - id: cargo-doc + # name: cargo-doc + # description: ensure cargo doc builds + # stages: [push] + # entry: sh + # args: + # - -c + # - "RUSTDOCFLAGS=\"-D warnings\" cargo doc --all-features" + # language: system + # types: [file] + # files: (\.md|\.rs|Cargo\.toml)$ + # exclude: (CHANGELOG|DEVELOPMENT)\.md$ + # pass_filenames: false - id: cargo-test name: cargo-test From bd53f9c2cb35f41d6529527dfc4d86943bd07d6a Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Mon, 22 Jan 2024 15:47:15 -0800 Subject: [PATCH 16/17] chore: remove rustflags and rustdocflags on cargo test pre-commit --- .pre-commit-config.yaml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e5dd99b..3897ab1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -129,15 +129,10 @@ repos: name: cargo-test description: run all tests stages: [push] - entry: sh + entry: cargo args: - - -c - - | - CARGO_INCREMENTAL="0" \ - RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests" \ - RUSTDOCFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests" \ - cargo test \ - --all-features + - test + - --all-features language: system types: [file] files: (\.md|\.rs|Cargo\.toml)$ From 1463701f8fa69ace8c7e481b9595fc46c5da9982 Mon Sep 17 00:00:00 2001 From: Trey Lowerison <19714082+tlowerison@users.noreply.github.com> Date: Mon, 22 Jan 2024 16:01:17 -0800 Subject: [PATCH 17/17] chore: disable codecov temporarily --- .github/workflows/continuous_integration.yml | 28 ++++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index cc57ae1..e562fa4 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -42,17 +42,17 @@ jobs: - run: pre-commit run --all-files --hook-stage push - - name: rust-grcov - uses: actions-rs/grcov@v0.1 - - - name: Codecov - uses: codecov/codecov-action@v4-beta - continue-on-error: true - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - with: - # Repository upload token - get it from codecov.io. Required only for private repositories - # token: # optional - # Specify whether the Codecov output should be verbose - verbose: true - fail_ci_if_error: false + # - name: rust-grcov + # uses: actions-rs/grcov@v0.1 + + # - name: Codecov + # uses: codecov/codecov-action@v4-beta + # continue-on-error: true + # env: + # CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + # with: + # # Repository upload token - get it from codecov.io. Required only for private repositories + # # token: # optional + # # Specify whether the Codecov output should be verbose + # verbose: true + # fail_ci_if_error: false