analyzer

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchesIgnoreExport

func MatchesIgnoreExport(name string, patterns []string) bool

MatchesIgnoreExport checks if a symbol name matches any ignore export pattern.

Types

type Analyzer

type Analyzer interface {
	Name() string
	Description() string
	Analyze(project *Project, cfg *Config) (*Result, error)
}

Analyzer is the interface all analyzers implement.

type Category

type Category string

Category represents the category of analysis.

const (
	CategoryDeadCode     Category = "dead-code"
	CategoryDuplication  Category = "duplication"
	CategoryComplexity   Category = "complexity"
	CategoryArchitecture Category = "architecture"
	CategoryDependency   Category = "dependency"
)

type Config

type Config struct {
	IgnorePatterns      []string            `json:"ignore_patterns"`
	IncludeTests        bool                `json:"include_tests"`
	Rules               map[string]Severity `json:"rules"`
	CyclomaticThreshold int                 `json:"cyclomatic_threshold"`
	CognitiveThreshold  int                 `json:"cognitive_threshold"`
	MinDuplicateLines   int                 `json:"min_duplicate_lines"`
	MinDuplicateTokens  int                 `json:"min_duplicate_tokens"`
	ArchitectureLayers  []LayerConfig       `json:"architecture_layers"`
	IgnoreExports       []string            `json:"ignore_exports"`
	GodPackageThreshold int                 `json:"god_package_threshold"`
}

Config holds all configuration for analyzer execution.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with sensible defaults.

type Finding

type Finding struct {
	Rule             string         `json:"rule"`
	Category         Category       `json:"category"`
	Severity         Severity       `json:"severity"`
	Message          string         `json:"message"`
	Location         Location       `json:"location"`
	RelatedLocations []Location     `json:"related_locations,omitempty"`
	Meta             map[string]any `json:"meta,omitempty"`
}

Finding represents a single issue found by an analyzer.

type GoModDep

type GoModDep struct {
	Path     string
	Version  string
	Indirect bool
	Line     int
}

GoModDep represents a dependency line from go.mod.

type LayerConfig

type LayerConfig struct {
	Name      string   `json:"name"`
	Packages  []string `json:"packages"`
	CanImport []string `json:"can_import"`
}

LayerConfig defines an architecture layer for violation checking.

type Location

type Location struct {
	File    string `json:"file"`
	Line    int    `json:"line"`
	Column  int    `json:"column,omitempty"`
	EndLine int    `json:"end_line,omitempty"`
}

Location identifies a position in source code.

type PackageInfo

type PackageInfo struct {
	ImportPath string
	RelPath    string
	Name       string
	Dir        string
	Files      []*ast.File
	FilePaths  []string
}

PackageInfo groups files belonging to the same Go package.

type Project

type Project struct {
	RootDir    string
	ModulePath string
	Fset       *token.FileSet
	Packages   map[string]*PackageInfo
	Files      map[string]*ast.File
	GoModDeps  []GoModDep
}

Project holds all parsed data for the Go module being analyzed.

type Report

type Report struct {
	Version       string        `json:"version"`
	Timestamp     string        `json:"timestamp"`
	RootDir       string        `json:"root_dir"`
	TotalDuration string        `json:"total_duration"`
	Summary       ReportSummary `json:"summary"`
	Results       []*Result     `json:"results"`
}

Report is the aggregate output of all analyzers.

type ReportSummary

type ReportSummary struct {
	TotalFindings int              `json:"total_findings"`
	BySeverity    map[Severity]int `json:"by_severity"`
	ByCategory    map[Category]int `json:"by_category"`
}

ReportSummary holds aggregate counts for a report.

type Result

type Result struct {
	Analyzer   string         `json:"analyzer"`
	Duration   time.Duration  `json:"-"`
	DurationMs int64          `json:"duration_ms"`
	Findings   []*Finding     `json:"findings"`
	Stats      map[string]any `json:"stats,omitempty"`
}

Result is the output of a single analyzer run.

type Severity

type Severity string

Severity represents the severity level of a finding.

const (
	SeverityError   Severity = "error"
	SeverityWarning Severity = "warning"
	SeverityInfo    Severity = "info"
	SeverityOff     Severity = "off"
)

func ResolveSeverity

func ResolveSeverity(rule string, defaultSev Severity, cfg *Config) (Severity, bool)

ResolveSeverity applies the config's severity override for a rule. Returns the resolved severity and whether the finding should be included.

Jump to

Keyboard shortcuts

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