Skip to content

Commit 79252b2

Browse files
fix(stackable-versioned): Validation error reporting (#842)
* fix: Report variant name validation error at the correct span * fix: Remove leading underscore for variant not using PascalCase * chore: Update changelog * chore: Update PR link in changelog * style: Update format_ident call * chore: Apply suggestion Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> * chore: Apply suggestions This snuck in because rust-analyzer doesn't remove trailing commas the same way it does for the format! macro. Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> --------- Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
1 parent cee9bd5 commit 79252b2

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

crates/stackable-versioned-macros/src/attrs/variant.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ impl VariantAttributes {
5252
.iter()
5353
.all(|r| r.from.is_case(Case::Pascal))
5454
{
55-
errors.push(Error::custom("renamed variants must use PascalCase"));
55+
errors
56+
.push(Error::custom("renamed variants must use PascalCase").with_span(&self.ident));
5657
}
5758

5859
errors.finish()?;

crates/stackable-versioned-macros/src/codegen/common/mod.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,24 @@ pub(crate) fn format_container_from_ident(ident: &Ident) -> Ident {
5858
///
5959
/// See [`DEPRECATED_FIELD_PREFIX`].
6060
pub(crate) fn remove_deprecated_field_prefix(ident: &Ident) -> Ident {
61-
remove_ident_prefix(ident, DEPRECATED_FIELD_PREFIX)
61+
let ident = ident.to_string();
62+
let ident = ident.trim_start_matches(DEPRECATED_FIELD_PREFIX);
63+
64+
format_ident!("{ident}")
6265
}
6366

6467
/// Removes the deprecated prefix from a variant ident.
6568
///
6669
/// See [`DEPRECATED_VARIANT_PREFIX`].
6770
pub(crate) fn remove_deprecated_variant_prefix(ident: &Ident) -> Ident {
68-
remove_ident_prefix(ident, DEPRECATED_VARIANT_PREFIX)
69-
}
71+
// NOTE (@Techassi): Currently Clippy only issues a warning for variants
72+
// with underscores in their name. That's why we additionally remove the
73+
// leading underscore from the ident to use the expected name during code
74+
// generation.
75+
let ident = ident.to_string();
76+
let ident = ident
77+
.trim_start_matches(DEPRECATED_VARIANT_PREFIX)
78+
.trim_start_matches('_');
7079

71-
/// Removes the provided prefix from an ident and returns the newly created
72-
/// ident.
73-
pub(crate) fn remove_ident_prefix(ident: &Ident, prefix: &str) -> Ident {
74-
format_ident!("{}", ident.to_string().trim_start_matches(prefix))
80+
format_ident!("{ident}")
7581
}

crates/stackable-versioned/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Fixed
8+
9+
- Report variant rename validation error at the correct span and trim underscores
10+
from variants not using PascalCase (#[842]).
11+
12+
[#842]: https://github.com/stackabletech/operator-rs/pull/842
13+
714
## [0.1.1] - 2024-07-10
815

916
### Added

0 commit comments

Comments
 (0)