Ragex.Editor.Validator behaviour
(Ragex v0.11.0)
View Source
Validation pipeline orchestration for code editing.
Coordinates validation across different language-specific validators. Automatically selects the appropriate validator based on file extension.
Summary
Callbacks
Callback for language-specific validators.
Functions
Checks if validation is available for a given file or language.
Gets the validator module for a specific language.
Lists all available validators.
Validates code content using the appropriate language validator.
Callbacks
@callback validate(content :: String.t(), opts :: keyword()) :: {:ok, :valid} | {:error, [Ragex.Editor.Types.validation_error()]}
Callback for language-specific validators.
Validators must implement this behavior to participate in the validation pipeline.
Functions
Checks if validation is available for a given file or language.
Examples
iex> Validator.can_validate?(path: "test.ex")
true
iex> Validator.can_validate?(path: "test.unknown")
false
Gets the validator module for a specific language.
Lists all available validators.
Returns a map of language to validator module.
@spec validate( String.t(), keyword() ) :: {:ok, :valid | :no_validator} | {:error, [Ragex.Editor.Types.validation_error()]}
Validates code content using the appropriate language validator.
Parameters
content: Code content to validateopts: Options:path- File path (used for language detection):language- Explicit language override:validator- Explicit validator module override
Returns
{:ok, :valid}if code is valid{:error, errors}if validation fails{:ok, :no_validator}if no validator available for language
Examples
iex> Validator.validate("defmodule Test do\nend", path: "test.ex")
{:ok, :valid}
iex> Validator.validate("defmodule Test", path: "test.ex")
{:error, [%{message: "unexpected end of file", ...}]}