Skip to content

Commit b5d4001

Browse files
fix: improve type heuristic for ecosystem types (#46)
1 parent a5a0eb5 commit b5d4001

File tree

6 files changed

+75
-69
lines changed

6 files changed

+75
-69
lines changed

packages/fortifier-macros/src/validate/type.rs

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,77 @@ const KEYED_CONTAINER_TYPES: [&str; 6] = [
157157
"std::collections::HashMap",
158158
];
159159

160+
/// Ecosystem types.
161+
///
162+
/// De facto standard types.
163+
const ECOSYSTEM_TYPES: [&str; 65] = [
164+
"Date",
165+
"DateTime",
166+
"Days",
167+
"Decimal",
168+
"Duration",
169+
"FixedI8",
170+
"FixedI16",
171+
"FixedI32",
172+
"FixedI64",
173+
"FixedI128",
174+
"FixedU8",
175+
"FixedU16",
176+
"FixedU32",
177+
"FixedU64",
178+
"FixedU128",
179+
"Month",
180+
"Months",
181+
"NaiveDate",
182+
"NaiveDateTime",
183+
"NaiveTime",
184+
"OffsetDateTime",
185+
"OrderedFloat",
186+
"PrimitiveDateTime",
187+
"Regex",
188+
"Time",
189+
"TimeDelta",
190+
"UtcDateTime",
191+
"Uuid",
192+
"Weekday",
193+
"WeekdaySet",
194+
"chrono::Date",
195+
"chrono::DateTime",
196+
"chrono::Days",
197+
"chrono::Duration",
198+
"chrono::Month",
199+
"chrono::Months",
200+
"chrono::NaiveDate",
201+
"chrono::NaiveDateTime",
202+
"chrono::NaiveTime",
203+
"chrono::TimeDelta",
204+
"chrono::Weekday",
205+
"chrono::WeekdaySet",
206+
"fancy_regex::Regex",
207+
"fixed::FixedI8",
208+
"fixed::FixedI16",
209+
"fixed::FixedI32",
210+
"fixed::FixedI64",
211+
"fixed::FixedI128",
212+
"fixed::FixedU8",
213+
"fixed::FixedU16",
214+
"fixed::FixedU32",
215+
"fixed::FixedU64",
216+
"fixed::FixedU128",
217+
"ordered_float::OrderedFloat",
218+
"regex::Regex",
219+
"rust_decimal::Decimal",
220+
"time::Date",
221+
"time::Duration",
222+
"time::Month",
223+
"time::OffsetDateTime",
224+
"time::PrimitiveDateTime",
225+
"time::Time",
226+
"time::UtcDateTime",
227+
"time::Weekday",
228+
"uuid::Uuid",
229+
];
230+
160231
fn path_to_string(path: &Path) -> String {
161232
path.segments
162233
.iter()
@@ -227,10 +298,6 @@ fn should_validate_path(generics: &Generics, path: &Path) -> Option<KnownOrUnkno
227298
let path_string = path_to_string(path);
228299
let path_string = path_string.as_str();
229300

230-
if BUILT_IN_TYPES.contains(&path_string) {
231-
return None;
232-
}
233-
234301
if CONTAINER_TYPES.contains(&path_string)
235302
&& let Some(segment) = path.segments.last()
236303
&& let PathArguments::AngleBracketed(arguments) = &segment.arguments
@@ -266,6 +333,10 @@ fn should_validate_path(generics: &Generics, path: &Path) -> Option<KnownOrUnkno
266333
return None;
267334
}
268335

336+
if BUILT_IN_TYPES.contains(&path_string) || ECOSYSTEM_TYPES.contains(&path_string) {
337+
return None;
338+
}
339+
269340
let path = Punctuated::<PathSegment, PathSep>::from_iter(
270341
path.segments
271342
.iter()

packages/fortifier/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
mod error;
66
mod error_code;
77
mod integrations;
8-
mod types;
98
mod validate;
109
mod validations;
1110

packages/fortifier/src/types.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/fortifier/src/types/chrono.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

packages/fortifier/src/types/decimal.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/fortifier/src/types/uuid.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)