detect

package
v0.8.0-beta.26 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package detect walks a project tree and returns the source files worth graphing. It skips dependency/build/cache directories, generated lock files, and anything that looks like it holds secrets (mirrors the Python original's detect.py skip lists and sensitive-file heuristics).

Index

Constants

This section is empty.

Variables

View Source
var SupportedExtensions = map[string]bool{
	".go":       true,
	".js":       true,
	".jsx":      true,
	".mjs":      true,
	".cjs":      true,
	".ts":       true,
	".mts":      true,
	".cts":      true,
	".tsx":      true,
	".tf":       true,
	".tfvars":   true,
	".json":     true,
	".hcl":      true,
	".py":       true,
	".rs":       true,
	".c":        true,
	".h":        true,
	".cpp":      true,
	".cc":       true,
	".cxx":      true,
	".hpp":      true,
	".hh":       true,
	".hxx":      true,
	".java":     true,
	".cs":       true,
	".rb":       true,
	".php":      true,
	".phtml":    true,
	".sh":       true,
	".bash":     true,
	".scala":    true,
	".sc":       true,
	".jl":       true,
	".v":        true,
	".sv":       true,
	".svh":      true,
	".vh":       true,
	".kt":       true,
	".kts":      true,
	".lua":      true,
	".zig":      true,
	".md":       true,
	".mdx":      true,
	".markdown": true,
	".vue":      true,
	".svelte":   true,
	".astro":    true,
}

SupportedExtensions are the file suffixes this port can extract.

Functions

func CollectFiles

func CollectFiles(root string) ([]string, error)

CollectFiles returns the supported source files under root, relative to root, in sorted order for deterministic output.

func CollectManifests added in v0.8.1

func CollectManifests(root string) ([]string, error)

CollectManifests returns the package-manifest files under root (relative to root, in sorted WalkDir order), honoring the same .gitignore and skip-dir rules as CollectFiles so vendored/ignored manifests are not indexed.

func IsSensitive added in v0.7.1

func IsSensitive(rel string) bool

IsSensitive reports whether rel names a file likely to hold secrets (a key, credential, or a file under a sensitive directory). Exposed so later stages (e.g. the semantic enrichment pass) can re-apply the same skip heuristic before any file content leaves the process.

func ShebangExt added in v0.8.1

func ShebangExt(src []byte) string

ShebangExt returns the extractor extension (e.g. ".sh", ".py") for a script whose leading line is a shebang naming an interpreter with a Go extractor, or "" when src has no such shebang. src need only hold the first line. It lets the extract dispatch route an extensionless script the same way CollectFiles decided to collect it.

Types

type WalkReport added in v0.8.1

type WalkReport struct {
	Files      []string // collected source files, relative to root, in WalkDir order
	WalkErrors []string // "<path>: <error>" for each entry the walk could not read
	Skipped    int      // files seen but dropped for an unsupported extension / no extractor
}

WalkReport carries the diagnostics CollectFilesReport gathers alongside the file list: directory-read errors hit mid-walk (which would otherwise silently truncate the enumeration into a partial graph.json) and a count of files that were walked past but not collected because no extractor handles their extension. Mirrors upstream detect.py's walk_errors / unclassified surfacing.

func CollectFilesReport added in v0.8.1

func CollectFilesReport(root string) (WalkReport, error)

CollectFilesReport walks root exactly like CollectFiles but additionally records the directory-read errors it hits (instead of silently swallowing them) and counts the files it skips for lacking a supported extension. The returned Files slice is identical to CollectFiles' output.

Jump to

Keyboard shortcuts

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