deadcode

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeprecatedCommentRule added in v1.4.2

type DeprecatedCommentRule struct {
	*rules.BaseRule
	// contains filtered or unexported fields
}

DeprecatedCommentRule detects functions/methods with Deprecated comments that should be removed. Functions marked as deprecated often linger in codebases long after they should be removed.

Detects patterns like:

// Deprecated: use NewFunction instead
func OldFunction() {}

// DEPRECATED - this will be removed
func LegacyMethod() {}

func NewDeprecatedCommentRule added in v1.4.2

func NewDeprecatedCommentRule() *DeprecatedCommentRule

NewDeprecatedCommentRule creates the rule

func (*DeprecatedCommentRule) AnalyzeFile added in v1.4.2

func (r *DeprecatedCommentRule) AnalyzeFile(ctx *core.FileContext) []*core.Violation

AnalyzeFile checks for deprecated comments in Go files

type NeverAssignedFieldRule added in v1.4.2

type NeverAssignedFieldRule struct {
	*rules.BaseRule
}

NeverAssignedFieldRule detects a dependency field that code reads but nothing ever assigns:

type Composer struct {
    logger  logging.Logger
    manager Manager
}

func newComposer(m Manager) *Composer {
    return &Composer{manager: m}   // logger stays nil
}

func (c *Composer) apply() {
    c.logger.Info("applied")       // nil dereference on the first call
}

This is the mirror image of unused-field, and the dangerous half: unused-field finds state kept up to date for nobody, this rule finds state everybody trusts that nobody fills. It is exactly what a constructor loses when a field assignment is deleted while the field and its readers survive — the code still compiles and panics the first time the path runs.

Only fields whose type can be nil are considered — interface, map, channel, function, and pointer. A missing int or string is a wrong value; a missing interface is a crash. Fields of basic types are also routinely filled by reflection (json.Unmarshal, sql.Scan), where the absence of an explicit assignment is normal and this rule would only produce noise.

A pointer field counts as read only where the read dereferences it (p.field.X, *p.field): an always-nil pointer that every caller nil-checks — the shape of an optional filter — misleads but does not crash, and belongs to unused-field's territory rather than here.

Not flagged: fields written anywhere in the analyzed packages, including positional composite literals (T{a, b, c}), which name no field and are therefore treated as writing all of them; and tagged fields, which reflection fills without any assignment appearing in the source.

func NewNeverAssignedFieldRule added in v1.4.2

func NewNeverAssignedFieldRule() *NeverAssignedFieldRule

NewNeverAssignedFieldRule creates the rule

func (*NeverAssignedFieldRule) AnalyzeFile added in v1.4.2

func (r *NeverAssignedFieldRule) AnalyzeFile(_ *core.FileContext) []*core.Violation

AnalyzeFile is a no-op: the writer of a field may live in any file.

func (*NeverAssignedFieldRule) AnalyzeGoProject added in v1.4.2

func (r *NeverAssignedFieldRule) AnalyzeGoProject(ctx *core.GoProjectContext) ([]*core.Violation, error)

AnalyzeGoProject reports the nil-able fields that are read but never written.

func (*NeverAssignedFieldRule) RequiresSSA added in v1.4.2

func (r *NeverAssignedFieldRule) RequiresSSA() bool

RequiresSSA reports that typed syntax is enough for this rule.

type NilReturnStubRule added in v1.4.2

type NilReturnStubRule struct {
	*rules.BaseRule
	// contains filtered or unexported fields
}

NilReturnStubRule detects methods that only return nil without doing any work. These are typically interface compliance stubs that provide no functionality.

Detects patterns like:

func (s *Service) GetData() (*Data, error) {
    return nil, nil
}

func (s *Service) Process() error {
    return nil // INTERFACE COMPLIANCE WRAPPER
}

func NewNilReturnStubRule added in v1.4.2

func NewNilReturnStubRule() *NilReturnStubRule

NewNilReturnStubRule creates the rule

func (*NilReturnStubRule) AnalyzeFile added in v1.4.2

func (r *NilReturnStubRule) AnalyzeFile(ctx *core.FileContext) []*core.Violation

AnalyzeFile checks for nil-return stub methods in Go files

type StubMethodRule added in v1.4.2

type StubMethodRule struct {
	*rules.BaseRule
	// contains filtered or unexported fields
}

StubMethodRule detects methods that only return errors indicating they are deprecated or not implemented. These are typically interface compliance stubs that should be removed or properly implemented.

Detects patterns like:

func (s *Service) Method() error {
    return fmt.Errorf("not implemented")
}

func (s *Service) Method() error {
    return errors.New("deprecated: use NewMethod instead")
}

func NewStubMethodRule added in v1.4.2

func NewStubMethodRule() *StubMethodRule

NewStubMethodRule creates the rule

func (*StubMethodRule) AnalyzeFile added in v1.4.2

func (r *StubMethodRule) AnalyzeFile(ctx *core.FileContext) []*core.Violation

AnalyzeFile checks for stub methods in Go files

type UnusedConfigFieldRule added in v1.4.2

type UnusedConfigFieldRule struct {
	*rules.BaseRule
}

UnusedConfigFieldRule detects struct fields that are parsed from configuration or from a payload but never mentioned anywhere in the code:

type RuleConfig struct {
    Enabled  bool   `yaml:"enabled"`
    Severity string `yaml:"severity"`  // parsed, never read
}

Such a field makes the configuration lie: the user writes `severity: high`, the loader accepts it without complaint, and nothing changes. The failure is silent by construction — there is no error to see and no behaviour to notice.

Only types that are actually decoded are examined: the rule follows the types reaching Unmarshal/Decode through their fields. Types that are also encoded are left alone, because there the encoder reads the field on the program's behalf.

func NewUnusedConfigFieldRule added in v1.4.2

func NewUnusedConfigFieldRule() *UnusedConfigFieldRule

NewUnusedConfigFieldRule creates the rule

func (*UnusedConfigFieldRule) AnalyzeFile added in v1.4.2

func (r *UnusedConfigFieldRule) AnalyzeFile(_ *core.FileContext) []*core.Violation

AnalyzeFile is a no-op: deciding that nothing uses a field needs the whole project, not one file.

func (*UnusedConfigFieldRule) AnalyzeGoProject added in v1.4.2

func (r *UnusedConfigFieldRule) AnalyzeGoProject(ctx *core.GoProjectContext) ([]*core.Violation, error)

AnalyzeGoProject finds the decoded types, then reports their tagged fields that no compiled file mentions.

func (*UnusedConfigFieldRule) RequiresSSA added in v1.4.2

func (r *UnusedConfigFieldRule) RequiresSSA() bool

RequiresSSA reports that typed syntax is enough for this rule.

type UnusedFieldRule added in v1.4.2

type UnusedFieldRule struct {
	*rules.BaseRule
}

UnusedFieldRule detects unexported struct fields that the package never reads:

type Cache struct {
    entries map[string]string
    hits    int      // counted on every Get, read by nobody
}

A field only ever written is a computation whose result is discarded: the value costs memory per instance and, worse, tells the next reader that something keeps track of hits when nothing does.

Only unexported fields of the analyzed packages are considered: an exported field belongs to the package's API, and its reader may live outside the tree being analyzed. Tagged fields belong to unused-config-field, which knows about values arriving from outside. Embedded and blank fields carry no name to use.

func NewUnusedFieldRule added in v1.4.2

func NewUnusedFieldRule() *UnusedFieldRule

NewUnusedFieldRule creates the rule

func (*UnusedFieldRule) AnalyzeFile added in v1.4.2

func (r *UnusedFieldRule) AnalyzeFile(_ *core.FileContext) []*core.Violation

AnalyzeFile is a no-op: the readers of a field may live in any file.

func (*UnusedFieldRule) AnalyzeGoProject added in v1.4.2

func (r *UnusedFieldRule) AnalyzeGoProject(ctx *core.GoProjectContext) ([]*core.Violation, error)

AnalyzeGoProject reports the unexported fields no compiled file reads.

func (*UnusedFieldRule) RequiresSSA added in v1.4.2

func (r *UnusedFieldRule) RequiresSSA() bool

RequiresSSA reports that typed syntax is enough for this rule.

type UnusedInternalExportRule added in v1.4.2

type UnusedInternalExportRule struct {
	*rules.BaseRule
}

UnusedInternalExportRule detects exported package-level symbols in internal/ packages that no production code references. internal/ packages cannot be imported from outside the module, so "no references in the module" means the symbol is dead — the export keyword only hides it from per-file dead-code checks.

Родилось из ревью projectD 2026-08: в internal/config накопилась 51 экспортированная константа и кластер экспортированных функций, на которые не ссылался никто, кроме их собственных тестов. Per-file правило unused-symbol их не видело — символы экспортированы, а границу модуля файл-за-файлом не проверить.

Символ считается живым, если на него есть хотя бы одна ссылка в production-коде — в своём пакете или в любом другом. Ссылки только из _test.go файлов не спасают: код, нужный лишь тестам, — мёртвый груз production-сборки, и сообщение это называет отдельно.

Методы не проверяются: они могут закрывать интерфейсы. Интерфейсные типы — зона orphaned-interface.

func NewUnusedInternalExportRule added in v1.4.2

func NewUnusedInternalExportRule() *UnusedInternalExportRule

NewUnusedInternalExportRule creates the rule.

func (*UnusedInternalExportRule) AnalyzeFile added in v1.4.2

func (r *UnusedInternalExportRule) AnalyzeFile(_ *core.FileContext) []*core.Violation

AnalyzeFile does nothing: the rule needs every package to count references.

func (*UnusedInternalExportRule) AnalyzeGoProject added in v1.4.2

func (r *UnusedInternalExportRule) AnalyzeGoProject(ctx *core.GoProjectContext) ([]*core.Violation, error)

AnalyzeGoProject collects exported symbols of internal packages and counts their references across the whole module.

func (*UnusedInternalExportRule) RequiresSSA added in v1.4.2

func (r *UnusedInternalExportRule) RequiresSSA() bool

RequiresSSA reports that typed packages are enough — no SSA program needed.

type UnusedParamRule

type UnusedParamRule struct {
	*rules.BaseRule
}

UnusedParamRule detects function parameters that are never used

func NewUnusedParamRule

func NewUnusedParamRule() *UnusedParamRule

NewUnusedParamRule creates the rule

func (*UnusedParamRule) AnalyzeFile

func (r *UnusedParamRule) AnalyzeFile(ctx *core.FileContext) []*core.Violation

AnalyzeFile checks for unused function parameters

type UnusedSymbolsRule added in v1.4.0

type UnusedSymbolsRule struct {
	*rules.BaseRule
	// contains filtered or unexported fields
}

UnusedSymbolsRule detects unexported symbols that appear unused within their file

func NewUnusedSymbolsRule added in v1.4.0

func NewUnusedSymbolsRule() *UnusedSymbolsRule

NewUnusedSymbolsRule creates the rule

func (*UnusedSymbolsRule) AnalyzeFile added in v1.4.0

func (r *UnusedSymbolsRule) AnalyzeFile(ctx *core.FileContext) []*core.Violation

AnalyzeFile checks for unused symbols

func (*UnusedSymbolsRule) ResetState added in v1.4.2

func (r *UnusedSymbolsRule) ResetState()

ResetState drops the per-directory cache, so a second project root never inherits the counts of the first.

Jump to

Keyboard shortcuts

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