Skip to content

Drop DataType::Result + impl Type for Result #416

Drop DataType::Result + impl Type for Result

Drop DataType::Result + impl Type for Result #416

GitHub Actions / clippy succeeded Jul 13, 2024 in 3s

clippy

275 warnings

Details

Results

Message level Amount
Internal compiler error 0
Error 0
Warning 275
Note 0
Help 0

Versions

  • rustc 1.79.0 (129f3b996 2024-06-10)
  • cargo 1.79.0 (ffa9cf99a 2024-06-03)
  • clippy 0.1.79 (129f3b9 2024-06-10)

Annotations

Check warning on line 643 in specta-zod/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

`panic` should not be present in production code

warning: `panic` should not be present in production code
   --> specta-zod/src/lib.rs:643:22
    |
643 |                 _ => panic!("unhandled literal type!"),
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#panic
    = note: requested on the command line with `-W clippy::panic`

Check warning on line 121 in specta-zod/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

this expression always evaluates to true

warning: this expression always evaluates to true
   --> specta-zod/src/lib.rs:121:47
    |
121 |     let prefix = match start_with_newline && !comments.is_empty() {
    |                                               ^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#const_is_empty
    = note: `-W clippy::const-is-empty` implied by `-W clippy::all`
    = help: to override `-W clippy::all` add `#[allow(clippy::const_is_empty)]`

Check warning on line 1 in specta-zod/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

package `specta-zod` is missing `package.readme` metadata

warning: package `specta-zod` is missing `package.readme` metadata
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata

Check warning on line 1 in specta-zod/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

package `specta-util` is missing `package.readme` metadata

warning: package `specta-util` is missing `package.readme` metadata
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata

Check warning on line 1 in specta-zod/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

package `specta-typescript` is missing `package.readme` metadata

warning: package `specta-typescript` is missing `package.readme` metadata
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata

Check warning on line 1 in specta-zod/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

package `specta-swift` is missing `package.readme` metadata

warning: package `specta-swift` is missing `package.readme` metadata
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata

Check warning on line 1 in specta-zod/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

package `specta-serde` is missing `package.readme` metadata

warning: package `specta-serde` is missing `package.readme` metadata
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata

Check warning on line 1 in specta-zod/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

package `specta-rust` is missing `package.readme` metadata

warning: package `specta-rust` is missing `package.readme` metadata
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata

Check warning on line 1 in specta-zod/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

package `specta-openapi` is missing `package.readme` metadata

warning: package `specta-openapi` is missing `package.readme` metadata
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata

Check warning on line 1 in specta-zod/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

package `specta-kotlin` is missing `package.readme` metadata

warning: package `specta-kotlin` is missing `package.readme` metadata
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata

Check warning on line 1 in specta-zod/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

package `specta-go` is missing `package.readme` metadata

warning: package `specta-go` is missing `package.readme` metadata
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata

Check warning on line 1 in specta-zod/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

package `specta-datatype-from` is missing `package.readme` metadata

warning: package `specta-datatype-from` is missing `package.readme` metadata
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata

Check warning on line 1 in specta-zod/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

package `specta` is missing `package.readme` metadata

warning: package `specta` is missing `package.readme` metadata
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata
  = note: `-W clippy::cargo-common-metadata` implied by `-W clippy::cargo`
  = help: to override `-W clippy::cargo` add `#[allow(clippy::cargo_common_metadata)]`

Check warning on line 8 in specta-zod/src/context.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

field `0` is never read

warning: field `0` is never read
 --> specta-zod/src/context.rs:8:18
  |
8 |     TypeExtended(Cow<'static, str>, ImplLocation),
  |     ------------ ^^^^^^^^^^^^^^^^^
  |     |
  |     field in this variant
  |
  = note: `#[warn(dead_code)]` on by default
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
  |
8 |     TypeExtended((), ImplLocation),
  |                  ~~

Check warning on line 780 in specta-typescript/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

passing a unit value to a function

warning: passing a unit value to a function
   --> specta-typescript/src/lib.rs:640:5
    |
640 | /     Ok(match &e.repr() {
641 | |         EnumRepr::Untagged => {
642 | |             let mut variants = e
643 | |                 .variants()
...   |
779 | |         }
780 | |     })
    | |______^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
help: move the expression in front of the call and replace it with the unit literal `()`
    |
640 ~     match &e.repr() {
641 +         EnumRepr::Untagged => {
642 +             let mut variants = e
643 +                 .variants()
644 +                 .iter()
645 +                 .filter(|(_, variant)| !variant.skip())
646 +                 .map(|(name, variant)| {
647 +                     Ok(match variant.inner() {
648 +                         EnumVariants::Unit => NULL.to_string(),
649 +                         _ => inner_comments(
650 +                             ctx.clone(),
651 +                             variant.deprecated(),
652 +                             variant.docs(),
653 +                             enum_variant_datatype(
654 +                                 ctx.with(PathItem::Variant(name.clone())),
655 +                                 type_map,
656 +                                 name.clone(),
657 +                                 variant,
658 +                             )?
659 +                             .expect("Invalid Serde type"),
660 +                             true,
661 +                         ),
662 +                     })
663 +                 })
664 +                 .collect::<Result<Vec<_>>>()?;
665 +             variants.dedup();
666 +             s.push_str(&variants.join(" | "));
667 +         }
668 +         repr => {
669 +             let mut variants = e
670 +                 .variants()
671 +                 .iter()
672 +                 .filter(|(_, variant)| !variant.skip())
673 +                 .map(|(variant_name, variant)| {
674 +                     let sanitised_name = sanitise_key(variant_name.clone(), true);
675 + 
676 +                     Ok(inner_comments(
677 +                         ctx.clone(),
678 +                         variant.deprecated(),
679 +                         variant.docs(),
680 +                         match (repr, &variant.inner()) {
681 +                             (EnumRepr::Untagged, _) => unreachable!(),
682 +                             (EnumRepr::Internal { tag }, EnumVariants::Unit) => {
683 +                                 format!("{{ {tag}: {sanitised_name} }}")
684 +                             }
685 +                             (EnumRepr::Internal { tag }, EnumVariants::Unnamed(tuple)) => {
686 +                                 let fields = skip_fields(tuple.fields()).collect::<Vec<_>>();
687 + 
688 +                                 // This field is only required for `{ty}` not `[...]` so we only need to check when there one field
689 +                                 let dont_join_ty = if tuple.fields().len() == 1 {
690 +                                     let (_, ty) = fields.first().expect("checked length above");
691 +                                     validate_type_for_tagged_intersection(
692 +                                         ctx.clone(),
693 +                                         (**ty).clone(),
694 +                                         type_map,
695 +                                     )?
696 +                                 } else {
697 +                                     false
698 +                                 };
699 + 
700 +                                 let mut typ = String::new();
701 + 
702 +                                 unnamed_fields_datatype(ctx.clone(), &fields, type_map, &mut typ)?;
703 + 
704 +                                 if dont_join_ty {
705 +                                     format!("({{ {tag}: {sanitised_name} }})")
706 +                                 } else {
707 +                                     // We wanna be sure `... & ... | ...` becomes `... & (... | ...)`
708 +                                     if typ.contains('|') {
709 +                                         typ = format!("({typ})");
710 +                                     }
711 +                                     format!("({{ {tag}: {sanitised_name} }} & {typ})")
712 +                                 }
713 +                             }
714 +                             (EnumRepr::Internal { tag }, EnumVariants::Named(obj)) => {
715 +                                 let mut fields = vec![format!("{tag}: {sanitised_name}")];
716 + 
717 +                                 for (name, field) in skip_fields_named(obj.fields()) {
718 +                                     let mut other = String::new();
719 +                                     object_field_to_ts(
720 +                                         ctx.with(PathItem::Field(name.clone())),
721 +                                         name.clone(),
722 +                                         field,
723 +                                         type_map,
724 +                                         &mut other,
725 +                                     )?;
726 +                                     fields.push(other);
727 +                                 }
728 + 
729 +                                 format!("{{ {} }}", fields.join("; "))
730 +                             }
731 +                             (EnumRepr::External, EnumVariants::Unit) => sanitised_name.to_string(),
732 +                             (EnumRepr::External, _) => {
733 +                                 let ts_values = enum_variant_datatype(
734 +                                     ctx.with(PathItem::Variant(variant_name.clone())),
735 +                                     type_map,
736 +                                     variant_name.clone(),
737 +                                     variant,
738 +                                 )?;
739 +                                 let sanitised_name = sanitise_key(variant_name.clone(), false);
740 + 
741 +                                 match ts_values {
742 +                                     Some(ts_values) => {
743 +                                         format!("{{ {sanitised_name}: {ts_values} }}")
744 +                                     }
745 +                                     None => format!(r#""{sanitised_name}""#),
746 +                                 }
747 +                             }
748 +                             (EnumRepr::Adjacent { tag, .. }, EnumVariants::Unit) => {
749 +                                 format!("{{ {tag}: {sanitised_name} }}")
750 +                             }
751 +                             (EnumRepr::Adjacent { tag, content }, _) => {
752 +                                 let ts_value = enum_variant_datatype(
753 +                                     ctx.with(PathItem::Variant(variant_name.clone())),
754 +                                     type_map,
755 +                                     variant_name.clone(),
756 +                                     variant,
757 +                                 )?;
758 + 
759 +                                 let mut s = String::new();
760 + 
761 +                                 s.push_str("{ ");
762 + 
763 +                                 write!(s, "{tag}: {sanitised_name}")?;
764 +                                 if let Some(ts_value) = ts_value {
765 +                                     write!(s, "; {content}: {ts_value}")?;
766 +                                 }
767 + 
768 +                                 s.push_str(" }");
769 + 
770 +                                 s
771 +                             }
772 +                         },
773 +                         true,
774 +                     ))
775 +                 })
776 +                 .collect::<Result<Vec<_>>>()?;
777 +             variants.dedup();
778 +             s.push_str(&variants.join(" | "));
779 +         }
780 +     };
781 +     Ok(())
    |

Check warning on line 497 in specta-typescript/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

passing a unit value to a function

warning: passing a unit value to a function
   --> specta-typescript/src/lib.rs:494:24
    |
494 |                   return Ok(match named.tag().as_ref() {
    |  ________________________^
495 | |                     Some(tag) => write!(s, r#"{{ "{tag}": "{key}" }}"#)?,
496 | |                     None => write!(s, "Record<{STRING}, {NEVER}>")?,
497 | |                 });
    | |__________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
help: move the expression in front of the call and replace it with the unit literal `()`
    |
494 ~                 return {
495 +                     match named.tag().as_ref() {
496 +                         Some(tag) => write!(s, r#"{{ "{tag}": "{key}" }}"#)?,
497 +                         None => write!(s, "Record<{STRING}, {NEVER}>")?,
498 +                     };
499 +                     Ok(())
500 ~                 };
    |

Check warning on line 554 in specta-typescript/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

passing a unit value to a function

warning: passing a unit value to a function
   --> specta-typescript/src/lib.rs:482:5
    |
482 | /     Ok(match &strct.fields() {
483 | |         StructFields::Unit => s.push_str(NULL),
484 | |         StructFields::Unnamed(unnamed) => unnamed_fields_datatype(
485 | |             ctx,
...   |
553 | |         }
554 | |     })
    | |______^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
help: move the expression in front of the call and replace it with the unit literal `()`
    |
482 ~     match &strct.fields() {
483 +         StructFields::Unit => s.push_str(NULL),
484 +         StructFields::Unnamed(unnamed) => unnamed_fields_datatype(
485 +             ctx,
486 +             &skip_fields(unnamed.fields()).collect::<Vec<_>>(),
487 +             type_map,
488 +             s,
489 +         )?,
490 +         StructFields::Named(named) => {
491 +             let fields = skip_fields_named(named.fields()).collect::<Vec<_>>();
492 + 
493 +             if fields.is_empty() {
494 +                 return Ok(match named.tag().as_ref() {
495 +                     Some(tag) => write!(s, r#"{{ "{tag}": "{key}" }}"#)?,
496 +                     None => write!(s, "Record<{STRING}, {NEVER}>")?,
497 +                 });
498 +             }
499 + 
500 +             let (flattened, non_flattened): (Vec<_>, Vec<_>) =
501 +                 fields.iter().partition(|(_, (f, _))| f.flatten());
502 + 
503 +             let mut field_sections = flattened
504 +                 .into_iter()
505 +                 .map(|(key, (field, ty))| {
506 +                     let mut s = String::new();
507 +                     datatype_inner(ctx.with(PathItem::Field(key.clone())), ty, type_map, &mut s)
508 +                         .map(|_| {
509 +                             inner_comments(
510 +                                 ctx.clone(),
511 +                                 field.deprecated(),
512 +                                 field.docs(),
513 +                                 format!("({s})"),
514 +                                 true,
515 +                             )
516 +                         })
517 +                 })
518 +                 .collect::<Result<Vec<_>>>()?;
519 + 
520 +             let mut unflattened_fields = non_flattened
521 +                 .into_iter()
522 +                 .map(|(key, field_ref)| {
523 +                     let (field, _) = field_ref;
524 + 
525 +                     let mut other = String::new();
526 +                     object_field_to_ts(
527 +                         ctx.with(PathItem::Field(key.clone())),
528 +                         key.clone(),
529 +                         field_ref,
530 +                         type_map,
531 +                         &mut other,
532 +                     )?;
533 + 
534 +                     Ok(inner_comments(
535 +                         ctx.clone(),
536 +                         field.deprecated(),
537 +                         field.docs(),
538 +                         other,
539 +                         true,
540 +                     ))
541 +                 })
542 +                 .collect::<Result<Vec<_>>>()?;
543 + 
544 +             if let Some(tag) = &named.tag() {
545 +                 unflattened_fields.push(format!("{tag}: \"{key}\""));
546 +             }
547 + 
548 +             if !unflattened_fields.is_empty() {
549 +                 field_sections.push(format!("{{ {} }}", unflattened_fields.join("; ")));
550 +             }
551 + 
552 +             s.push_str(&field_sections.join(" & "));
553 +         }
554 +     };
555 +     Ok(())
    |

Check warning on line 456 in specta-typescript/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

passing a unit value to a function

warning: passing a unit value to a function
   --> specta-typescript/src/lib.rs:423:5
    |
423 | /     Ok(match fields {
424 | |         [(field, ty)] => {
425 | |             let mut v = String::new();
426 | |             datatype_inner(ctx.clone(), ty, type_map, &mut v)?;
...   |
455 | |         }
456 | |     })
    | |______^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
help: move the expression in front of the call and replace it with the unit literal `()`
    |
423 ~     match fields {
424 +         [(field, ty)] => {
425 +             let mut v = String::new();
426 +             datatype_inner(ctx.clone(), ty, type_map, &mut v)?;
427 +             s.push_str(&inner_comments(
428 +                 ctx,
429 +                 field.deprecated(),
430 +                 field.docs(),
431 +                 v,
432 +                 true,
433 +             ));
434 +         }
435 +         fields => {
436 +             s.push('[');
437 + 
438 +             for (i, (field, ty)) in fields.iter().enumerate() {
439 +                 if i != 0 {
440 +                     s.push_str(", ");
441 +                 }
442 + 
443 +                 let mut v = String::new();
444 +                 datatype_inner(ctx.clone(), ty, type_map, &mut v)?;
445 +                 s.push_str(&inner_comments(
446 +                     ctx.clone(),
447 +                     field.deprecated(),
448 +                     field.docs(),
449 +                     v,
450 +                     true,
451 +                 ));
452 +             }
453 + 
454 +             s.push(']');
455 +         }
456 +     };
457 +     Ok(())
    |

Check warning on line 393 in specta-typescript/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> specta-typescript/src/lib.rs:393:28
    |
393 |                 s.push_str(&reference.name());
    |                            ^^^^^^^^^^^^^^^^^ help: change this to: `reference.name()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Check warning on line 391 in specta-typescript/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> specta-typescript/src/lib.rs:391:30
    |
391 |             [] => s.push_str(&reference.name()),
    |                              ^^^^^^^^^^^^^^^^^ help: change this to: `reference.name()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Check warning on line 334 in specta-typescript/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> specta-typescript/src/lib.rs:334:33
    |
334 |             datatype_inner(ctx, &def.ty(), type_map, &mut dt)?;
    |                                 ^^^^^^^^^ help: change this to: `def.ty()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Check warning on line 413 in specta-typescript/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

passing a unit value to a function

warning: passing a unit value to a function
   --> specta-typescript/src/lib.rs:276:5
    |
276 | /     Ok(match &typ {
277 | |         DataType::Any => s.push_str(ANY),
278 | |         DataType::Unknown => s.push_str(UNKNOWN),
279 | |         DataType::Primitive(p) => {
...   |
412 | |         DataType::Generic(ident) => s.push_str(&ident.to_string()),
413 | |     })
    | |______^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
    = note: `-W clippy::unit-arg` implied by `-W clippy::all`
    = help: to override `-W clippy::all` add `#[allow(clippy::unit_arg)]`
help: move the expression in front of the call and replace it with the unit literal `()`
    |
276 ~     match &typ {
277 +         DataType::Any => s.push_str(ANY),
278 +         DataType::Unknown => s.push_str(UNKNOWN),
279 +         DataType::Primitive(p) => {
280 +             let ctx = ctx.with(PathItem::Type(p.to_rust_str().into()));
281 +             let str = match p {
282 +                 primitive_def!(i8 i16 i32 u8 u16 u32 f32 f64) => NUMBER,
283 +                 primitive_def!(usize isize i64 u64 i128 u128) => match ctx.cfg.bigint {
284 +                     BigIntExportBehavior::String => STRING,
285 +                     BigIntExportBehavior::Number => NUMBER,
286 +                     BigIntExportBehavior::BigInt => BIGINT,
287 +                     BigIntExportBehavior::Fail => {
288 +                         return Err(ExportError::BigIntForbidden(ctx.export_path()));
289 +                     }
290 +                     BigIntExportBehavior::FailWithReason(reason) => {
291 +                         return Err(ExportError::Other(ctx.export_path(), reason.to_owned()))
292 +                     }
293 +                 },
294 +                 primitive_def!(String char) => STRING,
295 +                 primitive_def!(bool) => BOOLEAN,
296 +             };
297 + 
298 +             s.push_str(str);
299 +         }
300 +         DataType::Literal(literal) => match literal {
301 +             LiteralType::i8(v) => write!(s, "{v}")?,
302 +             LiteralType::i16(v) => write!(s, "{v}")?,
303 +             LiteralType::i32(v) => write!(s, "{v}")?,
304 +             LiteralType::u8(v) => write!(s, "{v}")?,
305 +             LiteralType::u16(v) => write!(s, "{v}")?,
306 +             LiteralType::u32(v) => write!(s, "{v}")?,
307 +             LiteralType::f32(v) => write!(s, "{v}")?,
308 +             LiteralType::f64(v) => write!(s, "{v}")?,
309 +             LiteralType::bool(v) => write!(s, "{v}")?,
310 +             LiteralType::String(v) => write!(s, r#""{v}""#)?,
311 +             LiteralType::char(v) => write!(s, r#""{v}""#)?,
312 +             LiteralType::None => s.write_str(NULL)?,
313 +             _ => unreachable!(),
314 +         },
315 +         DataType::Nullable(def) => {
316 +             datatype_inner(ctx, def, type_map, s)?;
317 + 
318 +             let or_null = format!(" | {NULL}");
319 +             if !s.ends_with(&or_null) {
320 +                 s.push_str(&or_null);
321 +             }
322 +         }
323 +         DataType::Map(def) => {
324 +             // We use this instead of `Record<K, V>` to avoid issues with circular references.
325 +             s.push_str("{ [key in ");
326 +             datatype_inner(ctx.clone(), def.key_ty(), type_map, s)?;
327 +             s.push_str("]: ");
328 +             datatype_inner(ctx.clone(), def.value_ty(), type_map, s)?;
329 +             s.push_str(" }");
330 +         }
331 +         // We use `T[]` instead of `Array<T>` to avoid issues with circular references.
332 +         DataType::List(def) => {
333 +             let mut dt = String::new();
334 +             datatype_inner(ctx, &def.ty(), type_map, &mut dt)?;
335 + 
336 +             let dt = if (dt.contains(' ') && !dt.ends_with('}'))
337 +                 // This is to do with maintaining order of operations.
338 +                 // Eg `{} | {}` must be wrapped in parens like `({} | {})[]` but `{}` doesn't cause `{}[]` is valid
339 +                 || (dt.contains(' ') && (dt.contains('&') || dt.contains('|')))
340 +             {
341 +                 format!("({dt})")
342 +             } else {
343 +                 dt
344 +             };
345 + 
346 +             if let Some(length) = def.length() {
347 +                 s.push('[');
348 + 
349 +                 for n in 0..length {
350 +                     if n != 0 {
351 +                         s.push_str(", ");
352 +                     }
353 + 
354 +                     s.push_str(&dt);
355 +                 }
356 + 
357 +                 s.push(']');
358 +             } else {
359 +                 write!(s, "{dt}[]")?;
360 +             }
361 +         }
362 +         DataType::Struct(item) => struct_datatype(
363 +             ctx.with(
364 +                 item.sid()
365 +                     .and_then(|sid| type_map.get(*sid))
366 +                     .and_then(|v| v.ext())
367 +                     .map(|v| PathItem::TypeExtended(item.name().clone(), *v.impl_location()))
368 +                     .unwrap_or_else(|| PathItem::Type(item.name().clone())),
369 +             ),
370 +             item.name(),
371 +             item,
372 +             type_map,
373 +             s,
374 +         )?,
375 +         DataType::Enum(item) => {
376 +             let mut ctx = ctx.clone();
377 +             let cfg = ctx.cfg.clone().bigint(BigIntExportBehavior::Number);
378 +             if item.skip_bigint_checks() {
379 +                 ctx.cfg = &cfg;
380 +             }
381 + 
382 +             enum_datatype(
383 +                 ctx.with(PathItem::Variant(item.name().clone())),
384 +                 item,
385 +                 type_map,
386 +                 s,
387 +             )?
388 +         }
389 +         DataType::Tuple(tuple) => s.push_str(&tuple_datatype(ctx, tuple, type_map)?),
390 +         DataType::Reference(reference) => match &reference.generics()[..] {
391 +             [] => s.push_str(&reference.name()),
392 +             generics => {
393 +                 s.push_str(&reference.name());
394 +                 s.push('<');
395 + 
396 +                 for (i, (_, v)) in generics.iter().enumerate() {
397 +                     if i != 0 {
398 +                         s.push_str(", ");
399 +                     }
400 + 
401 +                     datatype_inner(
402 +                         ctx.with(PathItem::Type(reference.name().clone())),
403 +                         v,
404 +                         type_map,
405 +                         s,
406 +                     )?;
407 +                 }
408 + 
409 +                 s.push('>');
410 +             }
411 +         },
412 +         DataType::Generic(ident) => s.push_str(&ident.to_string()),
413 +     };
414 +     Ok(())
    |

Check warning on line 220 in specta-typescript/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

using `clone` on type `Option<&NamedDataTypeExt>` which implements the `Copy` trait

warning: using `clone` on type `Option<&NamedDataTypeExt>` which implements the `Copy` trait
   --> specta-typescript/src/lib.rs:220:9
    |
220 |         ext.clone()
    |         ^^^^^^^^^^^ help: try removing the `clone` call: `ext`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
    = note: `-W clippy::clone-on-copy` implied by `-W clippy::all`
    = help: to override `-W clippy::all` add `#[allow(clippy::clone_on_copy)]`

Check warning on line 182 in specta-typescript/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

calling `push_str()` using a single-character string literal

warning: calling `push_str()` using a single-character string literal
   --> specta-typescript/src/lib.rs:182:5
    |
182 |     s.push_str(";");
    |     ^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `s.push(';')`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_add_str

Check warning on line 179 in specta-typescript/src/lib.rs

See this annotation in the file changed.

@github-actions github-actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> specta-typescript/src/lib.rs:179:38
    |
179 |         s.push_str(&datatype(config, &ty, &type_map)?);
    |                                      ^^^ help: change this to: `ty`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow