Documentation
¶
Index ¶
- func TraceExit()
- type Analysis
- func (a Analysis) ExportedUnused() Analysis
- func (a Analysis) ExportedWithNoExternalCalls() Analysis
- func (a Analysis) GroupedByObject() AnalysisGroupedByObject
- func (a Analysis) GroupedByPackage() AnalysisGroupedByPackage
- func (a Analysis) GroupedByPackageAndObject() AnalysisGroupedByPackageAndObject
- func (a Analysis) IsFunction() Analysis
- func (a Analysis) IsMethod() Analysis
- func (a Analysis) LeastUsed(n int) Analysis
- func (a Analysis) Limit(n int) Analysis
- func (a Analysis) MethodLike(substr string) Analysis
- func (a Analysis) MethodOf(objectName string) Analysis
- func (a Analysis) MethodOfPointerReceiver() Analysis
- func (a Analysis) MethodOfValueReceiver() Analysis
- func (a Analysis) MostUsed(n int) Analysis
- func (a Analysis) OrderByExternalCallsDesc() Analysis
- func (a Analysis) OrderByNameAsc() Analysis
- func (a Analysis) OrderByNameDesc() Analysis
- func (a Analysis) OrderByTotalCallsAsc() Analysis
- func (a Analysis) OrderByTotalCallsDesc() Analysis
- func (a Analysis) PrintWith(printer *Printer)
- func (a Analysis) String() string
- func (a Analysis) Where(predicate func(FunctionAnalysis) bool) Analysis
- func (a Analysis) WhereExported() Analysis
- func (a Analysis) WhereNameIs(name string) Analysis
- func (a Analysis) WhereNotTested() Analysis
- func (a Analysis) WhereTestedExternally() Analysis
- func (a Analysis) WhereTestedInternally() Analysis
- func (a Analysis) WhereUnexported() Analysis
- func (a Analysis) WhereUnused() Analysis
- type AnalysisGroupedByObject
- type AnalysisGroupedByPackage
- type AnalysisGroupedByPackageAndObject
- type AnalyzeMode
- type Analyzer
- type FunctionAnalysis
- type NameObject
- type NamePackage
- type Printer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Analysis ¶
type Analysis []FunctionAnalysis
func (Analysis) ExportedUnused ¶
func (Analysis) ExportedWithNoExternalCalls ¶
func (Analysis) GroupedByObject ¶
func (a Analysis) GroupedByObject() AnalysisGroupedByObject
func (Analysis) GroupedByPackage ¶
func (a Analysis) GroupedByPackage() AnalysisGroupedByPackage
func (Analysis) GroupedByPackageAndObject ¶
func (a Analysis) GroupedByPackageAndObject() AnalysisGroupedByPackageAndObject
func (Analysis) IsFunction ¶
func (Analysis) Limit ¶
Limit returns at most n elements from the slice. Should be used as the last element in a chain of operations.
Why returning a slice (not a copy) is safe: 1. All preceding operations (Where*, OrderBy*) return NEW slices 2. Limit operates on a slice that exists ONLY within this chain 3. No other code holds references to this intermediate slice 4. FunctionUsage values are immutable (no reference types)
Example safe usage:
result := usage.
WhereExported(). // ← new slice
OrderByTotalCallsDesc(). // ← new slice
Limit(10) // ← slice of the last new slice
Memory efficient: O(1) slice operation, no allocation. Follows Go's slice semantics (like u[:n]).
func (Analysis) MethodLike ¶
func (Analysis) MethodOfPointerReceiver ¶
func (Analysis) MethodOfValueReceiver ¶
func (Analysis) OrderByExternalCallsDesc ¶
func (Analysis) OrderByNameAsc ¶
func (Analysis) OrderByNameDesc ¶
func (Analysis) OrderByTotalCallsAsc ¶
func (Analysis) OrderByTotalCallsDesc ¶
func (Analysis) WhereExported ¶
func (Analysis) WhereNameIs ¶
func (Analysis) WhereNotTested ¶
func (Analysis) WhereTestedExternally ¶
func (Analysis) WhereTestedInternally ¶
func (Analysis) WhereUnexported ¶
func (Analysis) WhereUnused ¶
type AnalysisGroupedByObject ¶
type AnalysisGroupedByObject map[NameObject]Analysis
func (AnalysisGroupedByObject) PrintWith ¶
func (a AnalysisGroupedByObject) PrintWith(printer *Printer)
type AnalysisGroupedByPackage ¶
type AnalysisGroupedByPackage map[NamePackage]Analysis
func (AnalysisGroupedByPackage) PrintWith ¶
func (a AnalysisGroupedByPackage) PrintWith(printer *Printer)
type AnalysisGroupedByPackageAndObject ¶
type AnalysisGroupedByPackageAndObject map[NamePackage]map[NameObject]Analysis
func (AnalysisGroupedByPackageAndObject) PrintWith ¶
func (a AnalysisGroupedByPackageAndObject) PrintWith(printer *Printer)
type AnalyzeMode ¶
type AnalyzeMode int
AnalyzeMode defines how test files influence the analysis. Only one mode is active at a time. Each mode represents a distinct perspective on how production code and test code interact.
The modes are intentionally *mutually exclusive* to avoid boolean-flag combinatorics and to keep the API deterministic and predictable.
const ( // ModeDefault analyzes only production code. // Test files are ignored entirely: // - test functions are not reported // - calls from tests do not increase usage counts // // This mode is ideal for pure dead-code detection in production code. ModeDefault AnalyzeMode = iota + 1 // ModeIncludeTestsForCoverage counts calls from test files *into* // production code, but does not report test-defined functions. // // This mode is useful when you want a coverage-like view of which // production functions are exercised by tests, without treating test // helpers as part of the API surface. ModeIncludeTestsForCoverage // ModeIncludeTestHelpers includes functions defined in test files // (e.g. *_test.go) in the output, and counts their usage normally. // // This mode is useful for cleaning up test suites, identifying unused // test helpers, and understanding the internal API surface of tests. ModeIncludeTestHelpers // ModeOnlyTestHelpers analyzes *only* functions defined in test files. // Production code is ignored entirely. // // This mode is ideal for: // - finding unused test helpers // - understanding test-only utility layers // - refactoring large test suites ModeOnlyTestHelpers // ModeOnlyInTestFiles counts only calls that *originate* from test files. // Production functions are still reported, but only with test-origin // internal/external counts. // // This mode is useful for: // - identifying production functions used exclusively by tests // - detecting over-exported APIs that are not used by real consumers // - understanding test-to-prod dependency patterns ModeOnlyInTestFiles )
type Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
func NewAnalyzer ¶
type FunctionAnalysis ¶
type FunctionAnalysis struct {
// Key is the canonical identity of the function or method.
// Example (function): "github.com/me/project/pkg.DoThing"
// Example (method): "github.com/me/project/pkg.(*User).Save"
Key string
// Name is the short name of the function or method (without package or receiver).
Name string
// MethodOf highlights the object name for which the method belongs to.
// Alias for Object, but only populated for methods.
MethodOf NameObject
// Position is the source position of the function declaration.
Position token.Position
// InternalCount is the number of calls from within the same package.
// Does not include InternalTestsCount.
InternalCount int
// InternalTestsCount is the number of calls from within the same package tests.
InternalTestsCount int
// ExternalCount is the number of calls from other packages.
// Does not include ExternalTestsCount.
ExternalCount int
// ExternalTestsCount is the number of calls from other packages tests.
ExternalTestsCount int
}
FunctionAnalysis describes how a single function or method is used across the module.
type NameObject ¶
type NameObject string
type NamePackage ¶
type NamePackage string
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
func NewPrinter ¶
func NewPrinter() *Printer
func (*Printer) WithMethodOf ¶
Source Files
¶
- analyzer.go
- analyzer_helpers.go
- analyzer_mode_definitions.go
- analyzer_skip.go
- constants.go
- function_analysis.go
- function_analysis_op_convenience.go
- function_analysis_op_generic.go
- function_analysis_op_group_by.go
- function_analysis_op_limit.go
- function_analysis_op_method_of.go
- function_analysis_op_order_by.go
- function_analysis_op_where.go
- function_analysis_printer.go
- helpers.go
- helpers_ast.go
- helpers_debug.go
- helpers_is.go