Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/stackable-versioned-macros/src/attrs/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
24 changes: 16 additions & 8 deletions crates/stackable-versioned-macros/src/codegen/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,26 @@ 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)
format_ident!(
"{}",
ident
.to_string()
.trim_start_matches(DEPRECATED_FIELD_PREFIX)
)
}

/// 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)
}

/// 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))
// NOTE (@Techassi): Currently Clippy only issues a warning for variants
// with underscores in their name. That's why we additionally remove the
// underscore from the ident to use the expected name during code generation.
format_ident!(
"{}",
ident
.to_string()
.trim_start_matches(DEPRECATED_VARIANT_PREFIX)
.trim_start_matches('_')
)
}
7 changes: 7 additions & 0 deletions crates/stackable-versioned/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

## [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

Check failure on line 12 in crates/stackable-versioned/CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

[markdownlint] crates/stackable-versioned/CHANGELOG.md#L12

MD053/link-image-reference-definitions Link and image reference definitions should be needed [Unused link or image reference definition: "#842"] [Context: "[#842]: https://github.com/sta..."]
Raw output
crates/stackable-versioned/CHANGELOG.md:12:1 MD053/link-image-reference-definitions Link and image reference definitions should be needed [Unused link or image reference definition: "#842"] [Context: "[#842]: https://github.com/sta..."]

## [0.1.1] - 2024-07-10

### Added
Expand Down
Loading