deadcode

package
v1.37.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package deadcode detects functions and methods with zero incoming calls.

Index

Constants

View Source
const (
	ConfidenceHigh   = "high"
	ConfidenceMedium = "medium"
	ConfidenceLow    = "low"
)

Confidence levels for dead code classification.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeadSymbol

type DeadSymbol struct {
	Name       string `json:"name"`
	Kind       string `json:"kind"`
	File       string `json:"file"`
	Package    string `json:"package"`
	StartLine  int    `json:"start_line"`
	Lines      int    `json:"lines"`
	Exported   bool   `json:"exported"`
	Confidence string `json:"confidence"` // high, medium, low
}

DeadSymbol is a function/method with zero incoming calls.

type Options

type Options struct {
	IncludeExported bool                      // include exported (public) symbols — usually false positives
	IncludeTests    bool                      // include test-file symbols
	HookCallbacks   []string                  // function names registered as WordPress hook callbacks
	Relationships   []parser.TypeRelationship // type relationships for interface-aware filtering
	// OxCodes is an optional ox-codes client. When set, a second pass searches
	// for string references to apparent dead symbols, reducing false positives
	// caused by callbacks, reflection, and config-driven dispatch.
	OxCodes  *oxcodes.Client
	Root     string // repo root path (required for ox-codes queries)
	Language string // primary language (for scoped search)
	// Ctx is used for cancellation when OxCodes is set. A nil Ctx means
	// context.Background() is used.
	Ctx context.Context //nolint:containedctx
}

Options configures dead code detection.

type Result

type Result struct {
	TotalFunctions int          `json:"total_functions"`
	DeadCount      int          `json:"dead_count"`
	DeadRatio      float64      `json:"dead_ratio"`
	DeadSymbols    []DeadSymbol `json:"dead_symbols"`
}

Result is the output of dead code analysis.

func Analyze

func Analyze(cg *callgraph.CallGraph, opts Options) *Result

Analyze detects functions/methods with zero incoming calls in the call graph. It filters out entry points (main, init, TestMain), test functions, and optionally exported symbols to reduce false positives.

Jump to

Keyboard shortcuts

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