mirror of
https://github.com/xazukx/ts-rs.git
synced 2026-08-23 12:58:33 +00:00
refactor: fix clippy lints (#455)
This commit is contained in:
@@ -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(())
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
_ => {
|
||||
|
||||
@@ -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<string, 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 C = Record<string, never>;",
|
||||
"\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();
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![allow(clippy::useless_format)]
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use ts_rs::TS;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#![allow(clippy::box_collection, clippy::enum_variant_names, dead_code)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::{
|
||||
collections::{BTreeMap, HashSet},
|
||||
|
||||
@@ -69,7 +69,7 @@ enum ExternallyTagged {
|
||||
|
||||
G(
|
||||
Vec<ExternallyTagged>,
|
||||
[&'static ExternallyTagged; 1024],
|
||||
Box<[&'static ExternallyTagged; 1024]>,
|
||||
HashMap<String, ExternallyTagged>,
|
||||
),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user