pub struct QualityValidator { /* private fields */ }Expand description
Language-specific code quality validator
Orchestrates syntax, type, and lint validation for generated code across all supported target languages.
§Architecture
The validator follows a layered approach:
- Code staging: Writes code to a temporary file with appropriate extension
- Tool execution: Runs language-specific validation tools
- Error parsing: Extracts and structures error messages
- Report generation: Compiles results into a
ValidationReport
§Zero-Copy Design
Code is written to disk once and reused for all validation passes, minimizing I/O overhead. Tools operate directly on the filesystem.
Implementations§
Source§impl QualityValidator
impl QualityValidator
Sourcepub const fn new(language: TargetLanguage) -> Self
pub const fn new(language: TargetLanguage) -> Self
Sourcepub fn validate_syntax(&self, code: &str) -> Result<(), QualityError>
pub fn validate_syntax(&self, code: &str) -> Result<(), QualityError>
Validates syntax by attempting to parse/compile the code
Each language uses its native compiler or parser:
- Python:
python3 -m py_compile - TypeScript:
tsc --noEmit - Ruby:
ruby -c - PHP:
php -l - Rust:
cargo check
§Arguments
code- The source code to validate
§Returns
Ok(())if syntax is validErr(QualityError::ToolNotFound)if the validation tool is unavailableErr(QualityError::ValidationFailed)if syntax errors are foundErr(QualityError::IoError)if file operations fail
§Example
let validator = QualityValidator::new(TargetLanguage::Python);
validator.validate_syntax("x = 1")?;Sourcepub fn validate_types(&self, code: &str) -> Result<(), QualityError>
pub fn validate_types(&self, code: &str) -> Result<(), QualityError>
Validates type correctness using language-specific type checkers
Not all languages support this check; unsupported languages return Ok(()).
Tools used:
- Python:
mypy --strict - TypeScript:
tsc --noEmit - Ruby:
steep check - PHP: Not supported (lint validation covers this)
- Rust:
cargo check
§Arguments
code- The source code to validate
§Returns
Ok(())if types are valid or language doesn’t support type checkingErr(QualityError::ToolNotFound)if the type checker is unavailableErr(QualityError::ValidationFailed)if type errors are foundErr(QualityError::IoError)if file operations fail
§Example
let validator = QualityValidator::new(TargetLanguage::TypeScript);
validator.validate_types("const x: number = 5;")?;Sourcepub fn validate_lint(&self, code: &str) -> Result<(), QualityError>
pub fn validate_lint(&self, code: &str) -> Result<(), QualityError>
Validates code against linting and style standards
Each language enforces its community standards:
- Python:
ruff check - TypeScript:
biome check - Ruby:
rubocop - PHP:
phpstan --level=max - Rust:
cargo clippy -- -D warnings
§Arguments
code- The source code to validate
§Returns
Ok(())if code passes all linting checksErr(QualityError::ToolNotFound)if the linter is unavailableErr(QualityError::ValidationFailed)if linting violations are foundErr(QualityError::IoError)if file operations fail
§Example
let validator = QualityValidator::new(TargetLanguage::Python);
validator.validate_lint("import os\nx = 1")?;Sourcepub fn validate_all(&self, code: &str) -> Result<ValidationReport, QualityError>
pub fn validate_all(&self, code: &str) -> Result<ValidationReport, QualityError>
Runs all validation checks (syntax, types, lint) and returns a comprehensive report
This method executes all three quality gates sequentially and compiles results
into a single ValidationReport. All errors are captured, allowing callers
to see the complete picture of validation failures.
§Arguments
code- The source code to validate
§Returns
Ok(report)with validation resultsErr(QualityError)only if an I/O error occurs; validation failures are captured in the report
§Example
let validator = QualityValidator::new(TargetLanguage::Python);
let report = validator.validate_all("x = 1")?;
if report.is_valid() {
println!("Code is production-ready");
} else {
eprintln!("Found {} validation errors", report.error_count());
}