validator

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package validator provides .env file validation against schemas and code usage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasErrors

func HasErrors(results []Result) bool

HasErrors returns true if any result is an error.

func HasWarnings

func HasWarnings(results []Result) bool

HasWarnings returns true if any result is a warning.

func ValidateType

func ValidateType(value string, typ string, constraints map[string]string) error

ValidateType checks if a value conforms to the given type.

Types

type Result

type Result struct {
	Severity Severity `json:"severity"`
	Key      string   `json:"key"`
	Message  string   `json:"message"`
}

Result represents a single validation finding.

func ValidateAgainstCode

func ValidateAgainstCode(vars []envfile.EnvVar, refs []scanner.EnvReference) []Result

ValidateAgainstCode validates env vars against code references.

func ValidateAgainstSchema

func ValidateAgainstSchema(vars []envfile.EnvVar, schema *Schema) []Result

ValidateAgainstSchema validates env vars against a schema.

type Schema

type Schema struct {
	Entries []SchemaEntry
}

Schema represents a parsed .env.schema file.

func ParseSchema

func ParseSchema(path string) (*Schema, error)

ParseSchema reads and parses a .env.schema file.

func ParseSchemaString

func ParseSchemaString(content string) (*Schema, error)

ParseSchemaString parses a schema from a string.

type SchemaEntry

type SchemaEntry struct {
	Key         string
	Type        string
	Required    bool
	Default     string
	Constraints map[string]string
}

SchemaEntry represents a single entry in the .env.schema file.

type Severity

type Severity string

Severity represents the severity of a validation result.

const (
	// SeverityError indicates a required variable is missing or invalid.
	SeverityError Severity = "error"
	// SeverityWarning indicates a potential issue (e.g., unused variable).
	SeverityWarning Severity = "warning"
	// SeverityInfo indicates informational messages.
	SeverityInfo Severity = "info"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL