Skip to content

fix(stackable-versioned): Validation error reporting #842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 13 additions & 7 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,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}")
}
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