TaskValidator.Validators.ValidatorPipeline (TaskValidator v0.9.5)

View Source

Provides a pipeline for running multiple validators on tasks in priority order.

This module coordinates the execution of validator modules, ensuring they run in the correct order based on their priority values and providing aggregated validation results.

Usage

validators = [
  TaskValidator.Validators.IdValidator,
  TaskValidator.Validators.StatusValidator,
  TaskValidator.Validators.SectionValidator
]

context = %{
  config: TaskValidator.Config.get_all(),
  all_tasks: task_list.tasks,
  references: task_list.references
}

result = ValidatorPipeline.validate_task(task, validators, context)

Priority Ordering

Validators are automatically sorted by priority (highest first) before execution. This ensures that fundamental validations (like ID format) run before more complex validations that might depend on basic task structure.

Error Aggregation

All validation errors and warnings from all validators are collected and returned in a single ValidationResult. This provides complete feedback about all validation issues rather than stopping at the first error.

Early Exit

If a validator returns a critical error (severity: :critical), the pipeline stops execution and returns immediately. This prevents cascading failures when fundamental validation fails.

Summary

Functions

Gets the default set of validators for task validation.

Validates a task using multiple validators in priority order.

Validates multiple tasks using the same set of validators.

Functions

default_validators()

@spec default_validators() :: [module()]

Gets the default set of validators for task validation.

Returns the core validators that should be run for most validation scenarios. The validators are automatically sorted by priority when used in validate_task/3.

validate_task(task, validators, context)

Validates a task using multiple validators in priority order.

Parameters

  • task - The Task struct to validate
  • validators - List of validator modules that implement ValidatorBehaviour
  • context - Map containing validation context (config, all_tasks, etc.)

Returns

  • ValidationResult.t() - Aggregated results from all validators

validate_tasks(tasks, validators, context)

Validates multiple tasks using the same set of validators.

This is a convenience function for validating all tasks in a task list with the same validator configuration.

Parameters

  • tasks - List of Task structs to validate
  • validators - List of validator modules
  • context - Map containing validation context

Returns

  • ValidationResult.t() - Aggregated results from all task validations