metrics

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package metrics provides utilities for measuring and formatting metrics.

Package metrics provides measurement utilities for source code analysis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateTokens

func EstimateTokens(text string) int

EstimateTokens estimates the token count for text using heuristics.

The estimation accounts for: - Word boundaries (identifiers, keywords) - Code punctuation (braces, parentheses, operators) - GPT tokenizer behavior (~1.5 tokens per word for code)

This is an approximation; actual token counts depend on the specific tokenizer used by the target LLM.

func EstimateTokensInFile

func EstimateTokensInFile(content []byte) int

EstimateTokensInFile estimates tokens in a source file. This is a convenience wrapper that accepts byte content.

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes formats a byte count as a human-readable string (e.g., "1.5 KB").

func FormatNumber

func FormatNumber(n int) string

FormatNumber formats a number with K/M suffixes for readability.

func WalkSourceFiles

func WalkSourceFiles(root string, opts WalkOptions) ([]string, error)

WalkSourceFiles walks a directory and returns all source files matching the options.

func WalkSourceFilesWithContent

func WalkSourceFilesWithContent(root string, opts WalkOptions, fn func(path string, content []byte) error) error

WalkSourceFilesWithContent walks a directory and calls fn for each matching file with its content. If fn returns an error, walking stops and the error is returned.

Types

type WalkOptions

type WalkOptions struct {
	// Extensions to include (e.g., []string{".go", ".java"}). Empty means all files.
	Extensions []string

	// SkipDirs are directory names to skip (e.g., "vendor", "node_modules").
	SkipDirs []string

	// SkipHidden skips directories starting with "." (default: true).
	SkipHidden bool

	// SkipTests skips test files based on language conventions.
	SkipTests bool
}

WalkOptions configures source file walking behavior.

func DefaultWalkOptions

func DefaultWalkOptions() WalkOptions

DefaultWalkOptions returns sensible defaults for Go projects.

Jump to

Keyboard shortcuts

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