Skip to main content

QualityValidator

Struct QualityValidator 

Source
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:

  1. Code staging: Writes code to a temporary file with appropriate extension
  2. Tool execution: Runs language-specific validation tools
  3. Error parsing: Extracts and structures error messages
  4. 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

Source

pub const fn new(language: TargetLanguage) -> Self

Creates a new quality validator for the specified language

§Arguments
  • language - The target language for validation
§Example
let validator = QualityValidator::new(TargetLanguage::Python);
Source

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 valid
  • Err(QualityError::ToolNotFound) if the validation tool is unavailable
  • Err(QualityError::ValidationFailed) if syntax errors are found
  • Err(QualityError::IoError) if file operations fail
§Example
let validator = QualityValidator::new(TargetLanguage::Python);
validator.validate_syntax("x = 1")?;
Source

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 checking
  • Err(QualityError::ToolNotFound) if the type checker is unavailable
  • Err(QualityError::ValidationFailed) if type errors are found
  • Err(QualityError::IoError) if file operations fail
§Example
let validator = QualityValidator::new(TargetLanguage::TypeScript);
validator.validate_types("const x: number = 5;")?;
Source

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 checks
  • Err(QualityError::ToolNotFound) if the linter is unavailable
  • Err(QualityError::ValidationFailed) if linting violations are found
  • Err(QualityError::IoError) if file operations fail
§Example
let validator = QualityValidator::new(TargetLanguage::Python);
validator.validate_lint("import os\nx = 1")?;
Source

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 results
  • Err(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());
}

Trait Implementations§

Source§

impl Debug for QualityValidator

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more