smell

package
v1.54.0 Latest Latest
Warning

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

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

Documentation

Overview

Package smell implements advisory complexity smell rules (SM1–SM8). Each rule fires only on a provable SSA pattern — the smell analogue of ⊤: when a detector cannot prove the pattern, it stays silent.

Smells are firewalled from verdicts: a smell never reads from or writes to a budget, a bound.Check result, or any verdict state. The analyzer runs the smell pass after and independent of the budget pass. Diagnostics carry the fixed prefix "smell(SMn):" so they form a class golangci-lint users filter on.

Discovery notes (Task 0 of the implementation plan):

  • Constant-trip loops: tripcount.Of returns ⊤ for `for i := 0; i < 10; i++` (UpperExtent rejects a *ssa.Const bound), so constantTrip is detected structurally here, not via tripcount. ⊤ from tripcount is ambiguous (constant-trip AND data-dependent both read ⊤), which is why the loop family helpers below inspect the exit comparison directly.
  • Ignore representation: //bigo:ignore reaches the analyzer as a verb in directive.FuncDirectives.Dirs, retrievable via directive.Verb(fd.Dirs, annotation.Ignore). The analyzer skips ignored decls before calling Detect.

Index

Constants

This section is empty.

Variables

View Source
var AllRules = []string{"SM1", "SM2", "SM3", "SM4", "SM5", "SM6", "SM7", "SM8"}

AllRules is every smell rule, in canonical ID order.

Functions

func ParseRules

func ParseRules(flag string) (map[string]bool, error)

ParseRules parses the -smells flag value into an enabled-set.

  • "all" or "" (empty) → every rule enabled
  • "none" → empty set (no rules)
  • "SM1,SM4" → exactly those named rules

An unknown rule ID is an error.

Types

type Finding

type Finding struct {
	Pos     token.Pos
	Rule    string
	Message string
}

Finding is one smell diagnostic. Rule is the canonical ID (SM1..SM8); Message excludes the "smell(SMn):" prefix (the analyzer adds it).

func Detect

func Detect(fn *ssa.Function, enabled map[string]bool) []Finding

Detect runs every enabled rule's detector over fn and returns the combined findings. A nil/empty enabled map runs nothing.

Jump to

Keyboard shortcuts

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