Skip to content

some random stuff

some random stuff #424

GitHub Actions / clippy succeeded Jul 31, 2024 in 5s

clippy

289 warnings

Details

Results

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

Versions

  • rustc 1.80.0 (051478957 2024-07-21)
  • cargo 1.80.0 (376290515 2024-07-16)
  • clippy 0.1.80 (0514789 2024-07-21)

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 11 in Cargo.toml

See this annotation in the file changed.

@github-actions github-actions / clippy

lint group `cargo` has the same priority (-1) as a lint

warning: lint group `cargo` has the same priority (-1) as a lint
  --> Cargo.toml:11:1
   |
11 | cargo = { level = "warn", priority = -1 }
   | ^^^^^
12 | unwrap_used = { level = "warn", priority = -1 }
   | ----------- has the same priority as this lint
   |
   = note: the order of the lints in the table is ignored by Cargo
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#lint_groups_priority
help: to have lints override the group set `cargo` to a lower priority
   |
11 | cargo = { level = "warn", priority = -2 }
   |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check warning on line 10 in Cargo.toml

See this annotation in the file changed.

@github-actions github-actions / clippy

lint group `all` has the same priority (-1) as a lint

warning: lint group `all` has the same priority (-1) as a lint
  --> Cargo.toml:10:1
   |
10 | all = { level = "warn", priority = -1 }
   | ^^^
11 | cargo = { level = "warn", priority = -1 }
12 | unwrap_used = { level = "warn", priority = -1 }
   | ----------- has the same priority as this lint
   |
   = note: the order of the lints in the table is ignored by Cargo
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#lint_groups_priority
   = note: `-W clippy::lint-groups-priority` implied by `-W clippy::all`
   = help: to override `-W clippy::all` add `#[allow(clippy::lint_groups_priority)]`
help: to have lints override the group set `all` to a lower priority
   |
10 | all = { level = "warn", priority = -2 }
   |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Check warning on line 495 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:492:24
    |
492 |                   return Ok(match named.tag().as_ref() {
    |  ________________________^
493 | |                     Some(tag) => write!(s, r#"{{ "{tag}": "{key}" }}"#)?,
494 | |                     None => write!(s, "Record<{STRING}, {NEVER}>")?,
495 | |                 });
    | |__________________^
    |
    = 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 `()`
    |
492 ~                 return {
493 +                     match named.tag().as_ref() {
494 +                         Some(tag) => write!(s, r#"{{ "{tag}": "{key}" }}"#)?,
495 +                         None => write!(s, "Record<{STRING}, {NEVER}>")?,
496 +                     };
497 +                     Ok(())
498 ~                 };
    |

Check warning on line 557 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:480:5
    |
480 | /     Ok(match &strct.fields() {
481 | |         StructFields::Unit => s.push_str(NULL),
482 | |         StructFields::Unnamed(unnamed) => unnamed_fields_datatype(
483 | |             ctx,
...   |
556 | |         }
557 | |     })
    | |______^
    |
    = 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 `()`
    |
480 ~     match &strct.fields() {
481 +         StructFields::Unit => s.push_str(NULL),
482 +         StructFields::Unnamed(unnamed) => unnamed_fields_datatype(
483 +             ctx,
484 +             &skip_fields(unnamed.fields()).collect::<Vec<_>>(),
485 +             type_map,
486 +             s,
487 +         )?,
488 +         StructFields::Named(named) => {
489 +             let fields = skip_fields_named(named.fields()).collect::<Vec<_>>();
490 + 
491 +             if fields.is_empty() {
492 +                 return Ok(match named.tag().as_ref() {
493 +                     Some(tag) => write!(s, r#"{{ "{tag}": "{key}" }}"#)?,
494 +                     None => write!(s, "Record<{STRING}, {NEVER}>")?,
495 +                 });
496 +             }
497 + 
498 +             let (flattened, non_flattened): (Vec<_>, Vec<_>) =
499 +                 fields.iter().partition(|(_, (f, _))| f.flatten());
500 + 
501 +             let mut field_sections = flattened
502 +                 .into_iter()
503 +                 .map(|(key, (field, ty))| {
504 +                     let mut s = String::new();
505 +                     datatype_inner(
506 +                         ctx.with(PathItem::Field(key.clone())),
507 +                         &FunctionResultVariant::Value(ty.clone()),
508 +                         type_map,
509 +                         &mut s,
510 +                     )
511 +                     .map(|_| {
512 +                         inner_comments(
513 +                             ctx.clone(),
514 +                             field.deprecated(),
515 +                             field.docs(),
516 +                             format!("({s})"),
517 +                             true,
518 +                         )
519 +                     })
520 +                 })
521 +                 .collect::<Result<Vec<_>>>()?;
522 + 
523 +             let mut unflattened_fields = non_flattened
524 +                 .into_iter()
525 +                 .map(|(key, field_ref)| {
526 +                     let (field, _) = field_ref;
527 + 
528 +                     let mut other = String::new();
529 +                     object_field_to_ts(
530 +                         ctx.with(PathItem::Field(key.clone())),
531 +                         key.clone(),
532 +                         field_ref,
533 +                         type_map,
534 +                         &mut other,
535 +                     )?;
536 + 
537 +                     Ok(inner_comments(
538 +                         ctx.clone(),
539 +                         field.deprecated(),
540 +                         field.docs(),
541 +                         other,
542 +                         true,
543 +                     ))
544 +                 })
545 +                 .collect::<Result<Vec<_>>>()?;
546 + 
547 +             if let Some(tag) = &named.tag() {
548 +                 unflattened_fields.push(format!("{tag}: \"{key}\""));
549 +             }
550 + 
551 +             if !unflattened_fields.is_empty() {
552 +                 field_sections.push(format!("{{ {} }}", unflattened_fields.join("; ")));
553 +             }
554 + 
555 +             s.push_str(&field_sections.join(" & "));
556 +         }
557 +     };
558 +     Ok(())
    |

Check warning on line 448 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:405:5
    |
405 | /     Ok(match fields {
406 | |         [(field, ty)] => {
407 | |             let mut v = String::new();
408 | |             datatype_inner(
...   |
447 | |         }
448 | |     })
    | |______^
    |
    = 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 `()`
    |
405 ~     match fields {
406 +         [(field, ty)] => {
407 +             let mut v = String::new();
408 +             datatype_inner(
409 +                 ctx.clone(),
410 +                 &FunctionResultVariant::Value((*ty).clone()),
411 +                 type_map,
412 +                 &mut v,
413 +             )?;
414 +             s.push_str(&inner_comments(
415 +                 ctx,
416 +                 field.deprecated(),
417 +                 field.docs(),
418 +                 v,
419 +                 true,
420 +             ));
421 +         }
422 +         fields => {
423 +             s.push('[');
424 + 
425 +             for (i, (field, ty)) in fields.iter().enumerate() {
426 +                 if i != 0 {
427 +                     s.push_str(", ");
428 +                 }
429 + 
430 +                 let mut v = String::new();
431 +                 datatype_inner(
432 +                     ctx.clone(),
433 +                     &FunctionResultVariant::Value((*ty).clone()),
434 +                     type_map,
435 +                     &mut v,
436 +                 )?;
437 +                 s.push_str(&inner_comments(
438 +                     ctx.clone(),
439 +                     field.deprecated(),
440 +                     field.docs(),
441 +                     v,
442 +                     true,
443 +                 ));
444 +             }
445 + 
446 +             s.push(']');
447 +         }
448 +     };
449 +     Ok(())
    |

Check warning on line 375 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:375:28
    |
375 |                 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 373 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:373:30
    |
373 |             [] => 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
    = note: `-W clippy::needless-borrow` implied by `-W clippy::all`
    = help: to override `-W clippy::all` add `#[allow(clippy::needless_borrow)]`

Check warning on line 395 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:238:5
    |
238 | /     Ok(match &typ {
239 | |         DataType::Any => s.push_str(ANY),
240 | |         DataType::Unknown => s.push_str(UNKNOWN),
241 | |         DataType::Primitive(p) => {
...   |
394 | |         DataType::Generic(ident) => s.push_str(&ident.to_string()),
395 | |     })
    | |______^
    |
    = 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 `()`
    |
238 ~     match &typ {
239 +         DataType::Any => s.push_str(ANY),
240 +         DataType::Unknown => s.push_str(UNKNOWN),
241 +         DataType::Primitive(p) => {
242 +             let ctx = ctx.with(PathItem::Type(p.to_rust_str().into()));
243 +             let str = match p {
244 +                 primitive_def!(i8 i16 i32 u8 u16 u32 f32 f64) => NUMBER,
245 +                 primitive_def!(usize isize i64 u64 i128 u128) => match ctx.cfg.bigint {
246 +                     BigIntExportBehavior::String => STRING,
247 +                     BigIntExportBehavior::Number => NUMBER,
248 +                     BigIntExportBehavior::BigInt => BIGINT,
249 +                     BigIntExportBehavior::Fail => {
250 +                         return Err(ExportError::BigIntForbidden(ctx.export_path()));
251 +                     }
252 +                     BigIntExportBehavior::FailWithReason(reason) => {
253 +                         return Err(ExportError::Other(ctx.export_path(), reason.to_owned()))
254 +                     }
255 +                 },
256 +                 primitive_def!(String char) => STRING,
257 +                 primitive_def!(bool) => BOOLEAN,
258 +             };
259 + 
260 +             s.push_str(str);
261 +         }
262 +         DataType::Literal(literal) => match literal {
263 +             LiteralType::i8(v) => write!(s, "{v}")?,
264 +             LiteralType::i16(v) => write!(s, "{v}")?,
265 +             LiteralType::i32(v) => write!(s, "{v}")?,
266 +             LiteralType::u8(v) => write!(s, "{v}")?,
267 +             LiteralType::u16(v) => write!(s, "{v}")?,
268 +             LiteralType::u32(v) => write!(s, "{v}")?,
269 +             LiteralType::f32(v) => write!(s, "{v}")?,
270 +             LiteralType::f64(v) => write!(s, "{v}")?,
271 +             LiteralType::bool(v) => write!(s, "{v}")?,
272 +             LiteralType::String(v) => write!(s, r#""{v}""#)?,
273 +             LiteralType::char(v) => write!(s, r#""{v}""#)?,
274 +             LiteralType::None => s.write_str(NULL)?,
275 +             _ => unreachable!(),
276 +         },
277 +         DataType::Nullable(def) => {
278 +             datatype_inner(
279 +                 ctx,
280 +                 &FunctionResultVariant::Value((**def).clone()),
281 +                 type_map,
282 +                 s,
283 +             )?;
284 + 
285 +             let or_null = format!(" | {NULL}");
286 +             if !s.ends_with(&or_null) {
287 +                 s.push_str(&or_null);
288 +             }
289 +         }
290 +         DataType::Map(def) => {
291 +             // We use this instead of `Record<K, V>` to avoid issues with circular references.
292 +             s.push_str("{ [key in ");
293 +             datatype_inner(
294 +                 ctx.clone(),
295 +                 &FunctionResultVariant::Value(def.key_ty().clone()),
296 +                 type_map,
297 +                 s,
298 +             )?;
299 +             s.push_str("]: ");
300 +             datatype_inner(
301 +                 ctx.clone(),
302 +                 &FunctionResultVariant::Value(def.value_ty().clone()),
303 +                 type_map,
304 +                 s,
305 +             )?;
306 +             s.push_str(" }");
307 +         }
308 +         // We use `T[]` instead of `Array<T>` to avoid issues with circular references.
309 +         DataType::List(def) => {
310 +             let mut dt = String::new();
311 +             datatype_inner(
312 +                 ctx,
313 +                 &FunctionResultVariant::Value(def.ty().clone()),
314 +                 type_map,
315 +                 &mut dt,
316 +             )?;
317 + 
318 +             let dt = if (dt.contains(' ') && !dt.ends_with('}'))
319 +                 // This is to do with maintaining order of operations.
320 +                 // Eg `{} | {}` must be wrapped in parens like `({} | {})[]` but `{}` doesn't cause `{}[]` is valid
321 +                 || (dt.contains(' ') && (dt.contains('&') || dt.contains('|')))
322 +             {
323 +                 format!("({dt})")
324 +             } else {
325 +                 dt
326 +             };
327 + 
328 +             if let Some(length) = def.length() {
329 +                 s.push('[');
330 + 
331 +                 for n in 0..length {
332 +                     if n != 0 {
333 +                         s.push_str(", ");
334 +                     }
335 + 
336 +                     s.push_str(&dt);
337 +                 }
338 + 
339 +                 s.push(']');
340 +             } else {
341 +                 write!(s, "{dt}[]")?;
342 +             }
343 +         }
344 +         DataType::Struct(item) => struct_datatype(
345 +             ctx.with(
346 +                 item.sid()
347 +                     .and_then(|sid| type_map.get(*sid))
348 +                     .and_then(|v| v.ext())
349 +                     .map(|v| PathItem::TypeExtended(item.name().clone(), *v.impl_location()))
350 +                     .unwrap_or_else(|| PathItem::Type(item.name().clone())),
351 +             ),
352 +             item.name(),
353 +             item,
354 +             type_map,
355 +             s,
356 +         )?,
357 +         DataType::Enum(item) => {
358 +             let mut ctx = ctx.clone();
359 +             let cfg = ctx.cfg.clone().bigint(BigIntExportBehavior::Number);
360 +             if item.skip_bigint_checks() {
361 +                 ctx.cfg = &cfg;
362 +             }
363 + 
364 +             enum_datatype(
365 +                 ctx.with(PathItem::Variant(item.name().clone())),
366 +                 item,
367 +                 type_map,
368 +                 s,
369 +             )?
370 +         }
371 +         DataType::Tuple(tuple) => s.push_str(&tuple_datatype(ctx, tuple, type_map)?),
372 +         DataType::Reference(reference) => match &reference.generics()[..] {
373 +             [] => s.push_str(&reference.name()),
374 +             generics => {
375 +                 s.push_str(&reference.name());
376 +                 s.push('<');
377 + 
378 +                 for (i, (_, v)) in generics.iter().enumerate() {
379 +                     if i != 0 {
380 +                         s.push_str(", ");
381 +                     }
382 + 
383 +                     datatype_inner(
384 +                         ctx.with(PathItem::Type(reference.name().clone())),
385 +                         &FunctionResultVariant::Value(v.clone()),
386 +                         type_map,
387 +                         s,
388 +                     )?;
389 +                 }
390 + 
391 +                 s.push('>');
392 +             }
393 +         },
394 +         DataType::Generic(ident) => s.push_str(&ident.to_string()),
395 +     };
396 +     Ok(())
    |

Check warning on line 146 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:146:9
    |
146 |         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 1 in specta-typescript/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