diff --git a/macros/src/attr/struct.rs b/macros/src/attr/struct.rs index 346d5a17..9ebd7758 100644 --- a/macros/src/attr/struct.rs +++ b/macros/src/attr/struct.rs @@ -132,10 +132,8 @@ impl Attr for StructAttr { } } - if !matches!(item, Fields::Named(_)) { - if self.tag.is_some() { - syn_err!("`tag` cannot be used with unit or tuple structs"); - } + if !matches!(item, Fields::Named(_)) && self.tag.is_some() { + syn_err!("`tag` cannot be used with unit or tuple structs"); } Ok(()) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 85c9e91c..00613489 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -249,7 +249,7 @@ impl DerivedTS { let variants = #inline.replace(|x: char| !x.is_numeric() && x != ',', ""); let mut variants = variants .split(',') - .map(|x| isize::from_str_radix(x, 10).ok()) + .map(|x| x.parse().ok()) .peekable(); if variants.peek().is_none() { diff --git a/macros/src/optional.rs b/macros/src/optional.rs index 558290ec..5c43ee13 100644 --- a/macros/src/optional.rs +++ b/macros/src/optional.rs @@ -12,9 +12,11 @@ use crate::attr::FieldAttr; #[derive(Default, Clone, Copy)] pub enum Optional { /// Explicitly marked as optional with `#[ts(optional)]` + #[allow(clippy::enum_variant_names)] Optional { nullable: bool }, /// Explicitly marked as not optional with `#[ts(optional = false)]` + #[allow(clippy::enum_variant_names)] NotOptional, #[default] @@ -82,9 +84,11 @@ pub fn apply( check_that_field_is_option(x); true }}, - nullable - .then(|| field_ty.clone()) - .unwrap_or_else(|| unwrap_option(crate_rename, field_ty)), + if nullable { + field_ty.clone() + } else { + unwrap_option(crate_rename, field_ty) + }, ), // Inherited `#[ts(optional)]` from the struct. // Acts like `#[ts(optional)]` on a field, but does not error on non-`Option` fields. @@ -93,9 +97,11 @@ pub fn apply( parse_quote! { <#field_ty as #crate_rename::TS>::IS_OPTION }, - nullable - .then(|| field_ty.clone()) - .unwrap_or_else(|| unwrap_option(crate_rename, field_ty)), + if nullable { + field_ty.clone() + } else { + unwrap_option(crate_rename, field_ty) + }, ), // no applicable `#[ts(optional)]` attributes _ => { diff --git a/ts-rs/tests/integration/docs.rs b/ts-rs/tests/integration/docs.rs index daf710ab..f4627e4c 100644 --- a/ts-rs/tests/integration/docs.rs +++ b/ts-rs/tests/integration/docs.rs @@ -211,8 +211,7 @@ fn export_b() { fn export_c() { C::export().unwrap(); - let expected_content = if cfg!(feature = "format") { - concat!( + let expected_content = concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n", "/**\n", " * Doc comment.\n", @@ -221,20 +220,7 @@ fn export_c() { " * Testing\n", " */\n", "export type C = Record;\n", - ) - } else { - concat!( - "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n", - "/**\n", - " * Doc comment.\n", - " * Supports new lines.\n", - " *\n", - " * Testing\n", - " */\n", - "export type C = Record;", - "\n", - ) - }; + ); let actual_content = fs::read_to_string(C::default_output_path().unwrap()).unwrap(); @@ -245,8 +231,7 @@ fn export_c() { fn export_d() { D::export().unwrap(); - let expected_content = if cfg!(feature = "format") { - concat!( + let expected_content = concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n", "/**\n", " * Doc comment.\n", @@ -255,20 +240,7 @@ fn export_d() { " * Testing\n", " */\n", "export type D = null;\n", - ) - } else { - concat!( - "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n", - "/**\n", - " * Doc comment.\n", - " * Supports new lines.\n", - " *\n", - " * Testing\n", - " */\n", - "export type D = null;", - "\n", - ) - }; + ); let actual_content = fs::read_to_string(D::default_output_path().unwrap()).unwrap(); assert_eq!(actual_content, expected_content); @@ -278,8 +250,7 @@ fn export_d() { fn export_e() { E::export().unwrap(); - let expected_content = if cfg!(feature = "format") { - concat!( + let expected_content = concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n", "/**\n", " * Doc comment.\n", @@ -288,20 +259,7 @@ fn export_e() { " * Testing\n", " */\n", "export type E = never;\n", - ) - } else { - concat!( - "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n", - "/**\n", - " * Doc comment.\n", - " * Supports new lines.\n", - " *\n", - " * Testing\n", - " */\n", - "export type E = never;", - "\n", - ) - }; + ); let actual_content = fs::read_to_string(E::default_output_path().unwrap()).unwrap(); diff --git a/ts-rs/tests/integration/export_to.rs b/ts-rs/tests/integration/export_to.rs index 83df1e35..f18d661d 100644 --- a/ts-rs/tests/integration/export_to.rs +++ b/ts-rs/tests/integration/export_to.rs @@ -1,3 +1,5 @@ +#![allow(clippy::useless_format)] + use std::path::Path; use ts_rs::TS; diff --git a/ts-rs/tests/integration/generics.rs b/ts-rs/tests/integration/generics.rs index 4140672a..7911ed97 100644 --- a/ts-rs/tests/integration/generics.rs +++ b/ts-rs/tests/integration/generics.rs @@ -1,5 +1,4 @@ #![allow(clippy::box_collection, clippy::enum_variant_names, dead_code)] -#![allow(dead_code)] use std::{ collections::{BTreeMap, HashSet}, diff --git a/ts-rs/tests/integration/self_referential.rs b/ts-rs/tests/integration/self_referential.rs index 0df808b5..4c7e65f1 100644 --- a/ts-rs/tests/integration/self_referential.rs +++ b/ts-rs/tests/integration/self_referential.rs @@ -69,7 +69,7 @@ enum ExternallyTagged { G( Vec, - [&'static ExternallyTagged; 1024], + Box<[&'static ExternallyTagged; 1024]>, HashMap, ), }