ValidationIssue

Struct ValidationIssue 

Source
pub struct ValidationIssue { /* private fields */ }
Expand description

A single validation issue found in a template.

Each issue contains information about the problem, its severity, and optionally the location where it was found.

Implementations§

Source§

impl ValidationIssue

Source

pub fn new<S: Into<String>>( severity: Severity, category: IssueCategory, message: S, ) -> Self

Create a new validation issue.

§Examples
use tron::validation::{ValidationIssue, Severity, IssueCategory};

let issue = ValidationIssue::new(
    Severity::Warning,
    IssueCategory::Style,
    "Consider using descriptive placeholder names"
);
Source

pub fn with_line(self, line: usize) -> Self

Set the line number where the issue was found.

§Examples
use tron::validation::{ValidationIssue, Severity, IssueCategory};

let issue = ValidationIssue::new(Severity::Error, IssueCategory::Syntax, "Invalid syntax")
    .with_line(5);
Source

pub fn with_column(self, column: usize) -> Self

Set the column number where the issue was found.

Source

pub fn with_suggestion<S: Into<String>>(self, suggestion: S) -> Self

Add a suggestion for fixing the issue.

§Examples
use tron::validation::{ValidationIssue, Severity, IssueCategory};

let issue = ValidationIssue::new(Severity::Warning, IssueCategory::Style, "Short placeholder name")
    .with_suggestion("Consider using a more descriptive name like 'function_name'");
Source

pub fn severity(&self) -> Severity

Get the issue severity.

Examples found in repository?
examples/validation_usage.rs (line 153)
128fn example_multiple_template_validation() -> Result<()> {
129    println!("5. Multiple Template Validation:");
130    
131    let templates = vec![
132        TronTemplate::new("fn @[function_name]@(@[params]@) -> @[return_type]@ { @[body]@ }")?,
133        TronTemplate::new("struct @[n]@ { @[f]@ }")?,  // Short placeholder names
134        TronTemplate::new("Hello @[user_name]@! Welcome to @[application_name]@.")?,  // Good template
135        TronTemplate::new("const @[C]@ = @[value]@;")?,  // Uppercase in placeholder
136    ];
137    
138    let validator = TemplateValidator::new();
139    
140    // Validate each template and collect results
141    for (index, template) in templates.iter().enumerate() {
142        let report = validator.validate(template)?;
143        
144        println!("   Template #{}: {} issue(s)", 
145            index + 1, 
146            report.issues().len()
147        );
148        
149        if report.has_issues() {
150            // Show first few issues
151            for issue in report.issues().iter().take(2) {
152                println!("     - [{}] {}: {}", 
153                    issue.severity(), 
154                    issue.category(),
155                    issue.message()
156                );
157            }
158            if report.issues().len() > 2 {
159                println!("     ... and {} more", report.issues().len() - 2);
160            }
161        } else {
162            println!("     ✓ No issues found");
163        }
164        println!();
165    }
166    
167    // Demonstrate template reference validation
168    println!("   Template Reference Validation:");
169    let template = TronTemplate::new("fn main() { @[body]@ }")?;
170    let template_ref = TronRef::new(template)
171        .with_dependency("unsafe_crate = \"0.1\"");
172    
173    let report = validator.validate_ref(&template_ref)?;
174    println!("   TronRef validation: {} issue(s)", report.issues().len());
175    
176    Ok(())
177}
Source

pub fn category(&self) -> &IssueCategory

Get the issue category.

Examples found in repository?
examples/validation_usage.rs (line 154)
128fn example_multiple_template_validation() -> Result<()> {
129    println!("5. Multiple Template Validation:");
130    
131    let templates = vec![
132        TronTemplate::new("fn @[function_name]@(@[params]@) -> @[return_type]@ { @[body]@ }")?,
133        TronTemplate::new("struct @[n]@ { @[f]@ }")?,  // Short placeholder names
134        TronTemplate::new("Hello @[user_name]@! Welcome to @[application_name]@.")?,  // Good template
135        TronTemplate::new("const @[C]@ = @[value]@;")?,  // Uppercase in placeholder
136    ];
137    
138    let validator = TemplateValidator::new();
139    
140    // Validate each template and collect results
141    for (index, template) in templates.iter().enumerate() {
142        let report = validator.validate(template)?;
143        
144        println!("   Template #{}: {} issue(s)", 
145            index + 1, 
146            report.issues().len()
147        );
148        
149        if report.has_issues() {
150            // Show first few issues
151            for issue in report.issues().iter().take(2) {
152                println!("     - [{}] {}: {}", 
153                    issue.severity(), 
154                    issue.category(),
155                    issue.message()
156                );
157            }
158            if report.issues().len() > 2 {
159                println!("     ... and {} more", report.issues().len() - 2);
160            }
161        } else {
162            println!("     ✓ No issues found");
163        }
164        println!();
165    }
166    
167    // Demonstrate template reference validation
168    println!("   Template Reference Validation:");
169    let template = TronTemplate::new("fn main() { @[body]@ }")?;
170    let template_ref = TronRef::new(template)
171        .with_dependency("unsafe_crate = \"0.1\"");
172    
173    let report = validator.validate_ref(&template_ref)?;
174    println!("   TronRef validation: {} issue(s)", report.issues().len());
175    
176    Ok(())
177}
Source

pub fn message(&self) -> &str

Get the issue message.

Examples found in repository?
examples/validation_usage.rs (line 118)
93fn example_security_validation() -> Result<()> {
94    println!("4. Security Validation:");
95    
96    // Template with potential security issues
97    let template = TronTemplate::new(
98        r#"
99function processData() {
100    eval(@[user_code]@);
101    var password = "@[user_password]@";
102    return "<script>alert('XSS');</script>";
103}
104"#
105    )?;
106    
107    let validator = TemplateValidator::new();
108    let report = validator.validate(&template)?;
109    
110    println!("   Template with security concerns:");
111    println!("   {}", report);
112    
113    // Show only security issues
114    let security_issues = report.issues_by_category(&IssueCategory::Security);
115    if !security_issues.is_empty() {
116        println!("   Security-specific issues:");
117        for (i, issue) in security_issues.iter().enumerate() {
118            println!("     {}. {}", i + 1, issue.message());
119            if let Some(suggestion) = issue.suggestion() {
120                println!("        Suggestion: {}", suggestion);
121            }
122        }
123    }
124    
125    Ok(())
126}
127
128fn example_multiple_template_validation() -> Result<()> {
129    println!("5. Multiple Template Validation:");
130    
131    let templates = vec![
132        TronTemplate::new("fn @[function_name]@(@[params]@) -> @[return_type]@ { @[body]@ }")?,
133        TronTemplate::new("struct @[n]@ { @[f]@ }")?,  // Short placeholder names
134        TronTemplate::new("Hello @[user_name]@! Welcome to @[application_name]@.")?,  // Good template
135        TronTemplate::new("const @[C]@ = @[value]@;")?,  // Uppercase in placeholder
136    ];
137    
138    let validator = TemplateValidator::new();
139    
140    // Validate each template and collect results
141    for (index, template) in templates.iter().enumerate() {
142        let report = validator.validate(template)?;
143        
144        println!("   Template #{}: {} issue(s)", 
145            index + 1, 
146            report.issues().len()
147        );
148        
149        if report.has_issues() {
150            // Show first few issues
151            for issue in report.issues().iter().take(2) {
152                println!("     - [{}] {}: {}", 
153                    issue.severity(), 
154                    issue.category(),
155                    issue.message()
156                );
157            }
158            if report.issues().len() > 2 {
159                println!("     ... and {} more", report.issues().len() - 2);
160            }
161        } else {
162            println!("     ✓ No issues found");
163        }
164        println!();
165    }
166    
167    // Demonstrate template reference validation
168    println!("   Template Reference Validation:");
169    let template = TronTemplate::new("fn main() { @[body]@ }")?;
170    let template_ref = TronRef::new(template)
171        .with_dependency("unsafe_crate = \"0.1\"");
172    
173    let report = validator.validate_ref(&template_ref)?;
174    println!("   TronRef validation: {} issue(s)", report.issues().len());
175    
176    Ok(())
177}
Source

pub fn line(&self) -> Option<usize>

Get the line number if available.

Source

pub fn column(&self) -> Option<usize>

Get the column number if available.

Source

pub fn suggestion(&self) -> Option<&str>

Get the suggestion if available.

Examples found in repository?
examples/validation_usage.rs (line 119)
93fn example_security_validation() -> Result<()> {
94    println!("4. Security Validation:");
95    
96    // Template with potential security issues
97    let template = TronTemplate::new(
98        r#"
99function processData() {
100    eval(@[user_code]@);
101    var password = "@[user_password]@";
102    return "<script>alert('XSS');</script>";
103}
104"#
105    )?;
106    
107    let validator = TemplateValidator::new();
108    let report = validator.validate(&template)?;
109    
110    println!("   Template with security concerns:");
111    println!("   {}", report);
112    
113    // Show only security issues
114    let security_issues = report.issues_by_category(&IssueCategory::Security);
115    if !security_issues.is_empty() {
116        println!("   Security-specific issues:");
117        for (i, issue) in security_issues.iter().enumerate() {
118            println!("     {}. {}", i + 1, issue.message());
119            if let Some(suggestion) = issue.suggestion() {
120                println!("        Suggestion: {}", suggestion);
121            }
122        }
123    }
124    
125    Ok(())
126}

Trait Implementations§

Source§

impl Clone for ValidationIssue

Source§

fn clone(&self) -> ValidationIssue

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ValidationIssue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ValidationIssue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.