scanner

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanLiteralKey

func CleanLiteralKey(key string) string

CleanLiteralKey normalizes a scanned literal translation key.

func FullKey

func FullKey(namespace string, key string) string

FullKey combines namespace and key into a display key.

func UsageIdentity

func UsageIdentity(namespace string, key string) string

UsageIdentity returns a stable identity for a namespace and key.

Types

type Confidence

type Confidence string

Confidence indicates how reliable a scanned usage signal is.

const (
	ConfidenceExact  Confidence = "exact"
	ConfidenceHigh   Confidence = "high"
	ConfidenceMedium Confidence = "medium"
	ConfidenceLow    Confidence = "low"
)

Confidence levels for scanner evidence.

type DynamicHint

type DynamicHint struct {
	Namespace  string     `json:"namespace,omitempty"`
	KeyPattern string     `json:"keyPattern,omitempty"`
	FilePath   string     `json:"file"`
	Line       int        `json:"line"`
	Column     int        `json:"column"`
	Snippet    string     `json:"snippet"`
	Pattern    string     `json:"pattern"`
	Confidence Confidence `json:"confidence"`
	Message    string     `json:"message"`
}

DynamicHint describes a likely dynamic translation key usage.

type Evidence

type Evidence struct {
	Namespace  string     `json:"namespace,omitempty"`
	Key        string     `json:"key"`
	FullKey    string     `json:"fullKey"`
	FilePath   string     `json:"file"`
	Line       int        `json:"line"`
	Column     int        `json:"column"`
	Snippet    string     `json:"snippet"`
	Pattern    string     `json:"pattern"`
	Confidence Confidence `json:"confidence"`
}

Evidence describes where a translation usage was found.

type ProgressReporter

type ProgressReporter interface {
	Step(ctx context.Context, message string, current int, total int)
}

ProgressReporter receives scanner progress events.

type Report

type Report struct {
	FilesScanned int           `json:"filesScanned"`
	Files        []SourceFile  `json:"files"`
	Usages       []Usage       `json:"usages"`
	DynamicHints []DynamicHint `json:"dynamicHints,omitzero"`
	Warnings     []string      `json:"warnings,omitzero"`
	GeneratedAt  time.Time     `json:"generatedAt"`
}

Report contains source scan results.

type ScanInput

type ScanInput struct {
	Files     []string         `json:"files,omitzero" jsonschema:"optional project-relative source files to scan"`
	Progress  ProgressReporter `json:"-"`
	BatchSize int              `json:"batchSize,omitzero" jsonschema:"optional progress notification batch size; defaults to 25"`
}

ScanInput configures a source scan.

type Service

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

Service scans source files for translation usage.

func NewService

func NewService(guard *fsutil.Guard, configService *config.Service) *Service

NewService creates a scanner service scoped by guard and configService.

func (*Service) DiscoverSourceFiles

func (s *Service) DiscoverSourceFiles(ctx context.Context, requested []string) ([]SourceFile, error)

DiscoverSourceFiles returns source files to scan.

func (*Service) Latest

func (s *Service) Latest(ctx context.Context) (Report, bool, error)

Latest returns the current subject's most recent scan report, if any.

func (*Service) Scan

func (s *Service) Scan(ctx context.Context, in ScanInput) (Report, error)

Scan scans source files for translation key usage.

type SourceFile

type SourceFile struct {
	Path  string `json:"path"`
	Bytes int    `json:"bytes"`
}

SourceFile describes a scanned source file.

type Usage

type Usage struct {
	Namespace string     `json:"namespace,omitempty"`
	Key       string     `json:"key"`
	FullKey   string     `json:"fullKey"`
	Kind      string     `json:"kind"`
	Evidence  []Evidence `json:"evidence"`
}

Usage describes a detected translation key usage.

Jump to

Keyboard shortcuts

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