Help us shape the future of Go! Take the 2026 Go Developer Survey

detect

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package detect provides file discovery for Vela extraction pipelines.

It walks a directory tree recursively, collecting files while filtering out generated artefacts and dependency directories using a three-layer strategy:

  1. Tech-detected defaults — opinionated per-stack ignore rules applied whenever a stack manifest (package.json, go.mod, etc.) is found.
  2. .gitignore — standard git ignore rules found at each directory level.
  3. .velignore — vela-specific overrides with the same syntax as .gitignore, evaluated last so they take precedence over .gitignore and tech defaults.

Rules are scoped to the directory that contains the ignore file, and inherited by all subdirectories — matching git's own behaviour.

Usage:

result, err := detect.Files("/path/to/project")
for _, f := range result.Files {
    fmt.Println(f.RelPath)
}

Package detect handles file discovery and filtering for Vela extraction. It implements gitignore-compatible pattern matching without external dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect(root string, exts []string) ([]string, error)

Collect walks root and returns the absolute paths of all non-ignored files whose extension is in exts. If exts is empty, all files are returned.

func DefaultIgnorePatterns added in v1.1.0

func DefaultIgnorePatterns(t Tech) []string

DefaultIgnorePatterns returns the built-in ignore patterns for a tech stack. These cover generated artefacts, build outputs, and dependency directories that are never useful for knowledge-graph extraction.

func EnsureVelignore

func EnsureVelignore(root string) (string, error)

EnsureVelignore creates a .velignore file at root with sensible defaults if one does not already exist. Returns the created path and nil on creation, or empty string and nil if the file already existed.

Types

type FileEntry added in v1.1.0

type FileEntry struct {
	AbsPath string
	RelPath string // relative to the root passed to Walk
}

FileEntry represents a single discovered file.

func WalkDir added in v1.1.0

func WalkDir(root string) ([]FileEntry, error)

WalkDir is a convenience function that creates a Walker and calls Walk.

type IgnoreList added in v1.1.0

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

IgnoreList holds compiled patterns from a single .gitignore / .velignore file. Patterns are scoped to the directory that contains the ignore file.

func LoadIgnoreFile added in v1.1.0

func LoadIgnoreFile(dir, filename string) (*IgnoreList, error)

LoadIgnoreFile parses a .gitignore or .velignore file rooted at dir. Returns nil, nil if the file does not exist.

func NewIgnoreList added in v1.1.0

func NewIgnoreList(root string, lines []string) *IgnoreList

NewIgnoreList builds an IgnoreList from raw pattern strings. Useful for embedding built-in tech defaults without needing a file.

func (*IgnoreList) Ignored added in v1.1.0

func (il *IgnoreList) Ignored(absPath string, isDir bool) bool

Ignored reports whether absPath should be excluded. isDir must be true when absPath refers to a directory.

type Result added in v1.1.0

type Result struct {
	// Files contains every file that passed all ignore filters.
	Files []FileEntry

	// Root is the absolute path that was walked.
	Root string
}

Result holds the output of a detection pass.

func Files added in v1.1.0

func Files(root string) (*Result, error)

Files walks root and returns all non-ignored files. This is the primary entry point for callers outside this package.

type Tech added in v1.1.0

type Tech int

Tech represents a detected technology stack in a directory.

const (
	TechUnknown Tech = iota
	TechNode         // package.json present
	TechGo           // go.mod present
	TechPython       // pyproject.toml | setup.py | requirements.txt
	TechRust         // Cargo.toml
	TechJava         // pom.xml | build.gradle
)

func DetectTech added in v1.1.0

func DetectTech(dir string) Tech

DetectTech returns the primary tech stack detected in dir by checking for well-known manifest files. Only checks the given directory — not recursive.

func (Tech) String added in v1.1.0

func (t Tech) String() string

String returns human-readable tech name.

type Walker added in v1.1.0

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

Walker walks a directory tree, collecting files while respecting:

  1. Per-directory .gitignore files (gitignore spec, loaded at each dir)
  2. Per-directory .velignore files (override / complement .gitignore)
  3. Tech-detected default ignore rules (applied at any dir where a manifest is found)

Ignore rules compose — a file is excluded if ANY active IgnoreList marks it ignored. .velignore has highest priority (evaluated last), matching gitignore precedence semantics.

func NewWalker added in v1.1.0

func NewWalker(root string) (*Walker, error)

NewWalker creates a Walker rooted at root.

func (*Walker) Walk added in v1.1.0

func (w *Walker) Walk() ([]FileEntry, error)

Walk traverses the tree and returns all non-ignored files.

Jump to

Keyboard shortcuts

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