detect

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoFiles

func GoFiles(srcRoot string) ([]string, error)

GoFiles discovers every .go file the Go build system would compile under srcRoot, honoring build constraints (//go:build), excluding ignored files (//go:build ignore) and CGO-conditional alternates the host doesn't pick.

Multi-module: walks for go.mod files (skipping vendor/, node_modules/, .git/, and testdata/), then runs packages.Load("./...") in each module directory. Returns relpaths from srcRoot in slash form, deduplicated, sorted lexicographically.

Tests:true is set so _test.go files included in pkg.GoFiles surface in the result — the parser indexes them; omitting them would surface as audit drift between the build oracle and what production parses.

When srcRoot contains no go.mod anywhere, returns an empty slice with no error (the caller's TS/Sol pipelines may still find files there).

Implementation: thin wrapper over GoPackagesMode(srcRoot, ModeFiles) so detect.GoFiles and detect.GoPackages share a single discovery oracle. (B1 introduced GoPackages so the Go parser can access types.Info; this keeps the file-list contract unchanged.)

func GoPackages

func GoPackages(srcRoot string) ([]*packages.Package, error)

GoPackages is shorthand for GoPackagesMode(srcRoot, ModeTypes) — the loaded-with-type-info variant. The Go parser uses this to walk Syntax trees alongside TypesInfo so concurrency analysis can resolve sync.Mutex receivers via types.Object identity rather than fragile name matching.

func GoPackagesMode

func GoPackagesMode(srcRoot string, mode GoPackagesLoadMode) ([]*packages.Package, error)

GoPackagesMode runs packages.Load for every go.mod under srcRoot using the mode bits selected by `mode`. Returns the union of every module's loaded packages in load order. Per-module load failures are returned as errors (consistent with GoFiles' fail-fast behavior on Load errors, in contrast to per-package type-check failures which are tolerated).

Types

type CKGIgnore

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

CKGIgnore is a gitignore-style matcher (no negations, no anchored leading slashes). Patterns ending in "/" match directories. Patterns containing "*" use filepath.Match.

func LoadCKGIgnore

func LoadCKGIgnore(root string) (*CKGIgnore, error)

LoadCKGIgnore reads `.ckgignore` from root. Missing file is OK (returns empty matcher).

func (*CKGIgnore) Match

func (c *CKGIgnore) Match(rel string) bool

Match reports whether the relative path (filepath separator) is ignored.

type GoPackagesLoadMode

type GoPackagesLoadMode int

GoPackagesLoadMode selects how much info packages.Load is asked to produce. ModeFiles is the cheap mode used by GoFiles for discovery only; ModeTypes adds full TypesInfo + Syntax (required by the Go concurrency pass to resolve sync.Mutex receivers — name-only matching produces false positives on user-defined types named "Mutex").

const (
	// ModeFiles loads names + file lists only (cheap, GoFiles fingerprint).
	ModeFiles GoPackagesLoadMode = iota
	// ModeTypes loads everything ModeFiles does plus parsed Syntax,
	// resolved Types, and TypesInfo. ~10x slower on large modules; use
	// only when the consumer needs go/types resolution (concurrency pass).
	ModeTypes
)

type Result

type Result struct {
	Go    []string
	TS    []string
	Sol   []string
	Proto []string
}

Result groups file paths by language. Paths are RELATIVE to the walk root.

func Walk

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

Walk walks root, classifies files by extension, and skips paths matching .ckgignore.

Jump to

Keyboard shortcuts

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