errors

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LevenshteinDistance

func LevenshteinDistance(s1, s2 string) int

LevenshteinDistance calculates the edit distance between two strings. This is the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other.

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector aggregates multiple errors during validation. It handles deduplication, sorting, and limiting the number of errors returned.

func NewCollector

func NewCollector() *Collector

NewCollector creates a new error collector with no limit.

func NewCollectorWithLimit

func NewCollectorWithLimit(maxErrors int) *Collector

NewCollectorWithLimit creates a new error collector with a maximum error limit. Once the limit is reached, additional errors are counted but not stored.

func (*Collector) Add

func (c *Collector) Add(err domain.DecoError)

Add adds an error to the collector. Duplicate errors (same code + location) are automatically deduplicated.

func (*Collector) AddBatch

func (c *Collector) AddBatch(errs []domain.DecoError)

AddBatch adds multiple errors at once.

func (*Collector) Count

func (c *Collector) Count() int

Count returns the total number of unique errors added to the collector. This may be higher than len(Errors()) if deduplication or truncation occurred.

func (*Collector) Errors

func (c *Collector) Errors() []domain.DecoError

Errors returns all collected errors, sorted by location. Sorting order: file (alphabetically), line (numerically), column (numerically). Errors without location come last.

func (*Collector) HasErrors

func (c *Collector) HasErrors() bool

HasErrors returns true if any errors have been collected.

func (*Collector) Reset

func (c *Collector) Reset()

Reset clears all collected errors.

func (*Collector) Truncated

func (c *Collector) Truncated() bool

Truncated returns true if the collector hit its error limit. This means some errors were counted but not stored.

type Suggester

type Suggester struct {
	// contains filtered or unexported fields
}

Suggester generates "did you mean?" suggestions for typos.

func NewSuggester

func NewSuggester() *Suggester

NewSuggester creates a new suggestion engine with default settings.

func (*Suggester) FormatSuggestion

func (s *Suggester) FormatSuggestion(input string, candidates []string) string

FormatSuggestion creates a formatted error message with suggestions. Returns empty string if no good suggestions are found.

func (*Suggester) Suggest

func (s *Suggester) Suggest(input string, candidates []string) []string

Suggest generates suggestions for the input based on candidates. Returns up to maxSuggestions closest matches within the default threshold.

func (*Suggester) SuggestWithThreshold

func (s *Suggester) SuggestWithThreshold(input string, candidates []string, threshold int) []string

SuggestWithThreshold generates suggestions using a custom distance threshold. Only candidates within the threshold are returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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