diff --git a/crates/stackable-versioned-macros/src/attrs/variant.rs b/crates/stackable-versioned-macros/src/attrs/variant.rs index 557e082e4..cb831e52b 100644 --- a/crates/stackable-versioned-macros/src/attrs/variant.rs +++ b/crates/stackable-versioned-macros/src/attrs/variant.rs @@ -52,7 +52,8 @@ impl VariantAttributes { .iter() .all(|r| r.from.is_case(Case::Pascal)) { - errors.push(Error::custom("renamed variants must use PascalCase")); + errors + .push(Error::custom("renamed variants must use PascalCase").with_span(&self.ident)); } errors.finish()?; diff --git a/crates/stackable-versioned-macros/src/codegen/common/mod.rs b/crates/stackable-versioned-macros/src/codegen/common/mod.rs index 93668e768..2f416a88a 100644 --- a/crates/stackable-versioned-macros/src/codegen/common/mod.rs +++ b/crates/stackable-versioned-macros/src/codegen/common/mod.rs @@ -58,18 +58,24 @@ pub(crate) fn format_container_from_ident(ident: &Ident) -> Ident { /// /// See [`DEPRECATED_FIELD_PREFIX`]. pub(crate) fn remove_deprecated_field_prefix(ident: &Ident) -> Ident { - remove_ident_prefix(ident, DEPRECATED_FIELD_PREFIX) + let ident = ident.to_string(); + let ident = ident.trim_start_matches(DEPRECATED_FIELD_PREFIX); + + format_ident!("{ident}") } /// Removes the deprecated prefix from a variant ident. /// /// See [`DEPRECATED_VARIANT_PREFIX`]. pub(crate) fn remove_deprecated_variant_prefix(ident: &Ident) -> Ident { - remove_ident_prefix(ident, DEPRECATED_VARIANT_PREFIX) -} + // NOTE (@Techassi): Currently Clippy only issues a warning for variants + // with underscores in their name. That's why we additionally remove the + // leading underscore from the ident to use the expected name during code + // generation. + let ident = ident.to_string(); + let ident = ident + .trim_start_matches(DEPRECATED_VARIANT_PREFIX) + .trim_start_matches('_'); -/// Removes the provided prefix from an ident and returns the newly created -/// ident. -pub(crate) fn remove_ident_prefix(ident: &Ident, prefix: &str) -> Ident { - format_ident!("{}", ident.to_string().trim_start_matches(prefix)) + format_ident!("{ident}") } diff --git a/crates/stackable-versioned/CHANGELOG.md b/crates/stackable-versioned/CHANGELOG.md index e65e620ad..764e01445 100644 --- a/crates/stackable-versioned/CHANGELOG.md +++ b/crates/stackable-versioned/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Fixed + +- Report variant rename validation error at the correct span and trim underscores + from variants not using PascalCase (#[842]). + +[#842]: https://github.com/stackabletech/operator-rs/pull/842 + ## [0.1.1] - 2024-07-10 ### Added