Skip to main content

ass_core/analysis/styles/validation/
issue.rs

1//! Style validation issue type and constructors.
2//!
3//! Provides [`StyleValidationIssue`], a description of a single style
4//! validation problem with severity, affected field, and optional fix
5//! suggestion.
6
7use alloc::string::{String, ToString};
8
9use super::ValidationSeverity;
10
11/// Style validation issue with context and suggestions
12#[derive(Debug, Clone)]
13pub struct StyleValidationIssue {
14    /// Issue severity level
15    pub severity: ValidationSeverity,
16    /// Human-readable issue description
17    pub message: String,
18    /// Style field that caused the issue
19    pub field: String,
20    /// Optional suggested fix or improvement
21    pub suggestion: Option<String>,
22}
23
24impl StyleValidationIssue {
25    /// Create new validation issue
26    #[must_use]
27    pub fn new(
28        severity: ValidationSeverity,
29        field: &str,
30        message: &str,
31        suggestion: Option<&str>,
32    ) -> Self {
33        Self {
34            severity,
35            message: message.to_string(),
36            field: field.to_string(),
37            suggestion: suggestion.map(ToString::to_string),
38        }
39    }
40
41    /// Create error-level issue
42    #[must_use]
43    pub fn error(field: &str, message: &str) -> Self {
44        Self::new(ValidationSeverity::Error, field, message, None)
45    }
46
47    /// Create warning-level issue
48    #[must_use]
49    pub fn warning(field: &str, message: &str) -> Self {
50        Self::new(ValidationSeverity::Warning, field, message, None)
51    }
52
53    /// Create info-level issue with suggestion
54    #[must_use]
55    pub fn info_with_suggestion(field: &str, message: &str, suggestion: &str) -> Self {
56        Self::new(ValidationSeverity::Info, field, message, Some(suggestion))
57    }
58}