class ValidateTransformation

Transformation that validates rules for DNS blockers. Uses AGTree for robust parsing and validation. Removes invalid rules and their preceding comments.

Constructors

new
ValidateTransformation(
allowIp?: boolean,
logger?: ILogger,
)

Creates a new ValidateTransformation

Properties

readonly
name: string

Human-readable name of the transformation

The transformation type identifier

protected
readonly
allowIp: boolean

Whether IP addresses are allowed in rules

private
optional
currentSourceName: string

Current source name for error tracking

Last validation report (from most recent executeSync call)

Methods

private
addValidationError(
errors: IValidationError[],
ruleText: string,
message: string,
details?: string,
ast?: AnyRule,
lineNumber?: number,
): void

Add a validation error to the provided errors array

executeSync(rules: string[]): string[]

Executes the validation transformation synchronously.

Get the validation report from the most recent executeSync call

private
isCommentOrEmpty(
ast: AnyRule | null,
ruleText: string,
): boolean

Check if the parsed rule is a comment or empty.

protected
isValidParsedRule(
ast: AnyRule | null,
ruleText: string,
lineNumber: number | undefined,
errors: IValidationError[],
): boolean

Validates a parsed rule using the AST.

setSourceName(sourceName: string | undefined): void

Set the current source name for error tracking

protected
validateHostRule(
rule: HostRule,
ruleText: string,
lineNumber: number | undefined,
errors: IValidationError[],
): boolean

Validates a /etc/hosts rule using AGTree AST.

protected
validateHostname(
hostname: string,
ruleText: string,
hasLimitModifier: boolean,
lineNumber: number | undefined,
errors: IValidationError[],
): boolean

Validates a hostname for the blocklist.

protected
validateNetworkRule(
rule: NetworkRule,
ruleText: string,
lineNumber: number | undefined,
errors: IValidationError[],
): boolean

Validates an adblock-style network rule using AGTree AST.