codequality

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package codequality assembles the code-quality findings for a source tree: it runs the deterministic maintainability/reliability rule engine and layers on the metric-derived signals (duplication, and complexity when an AST backend is available), mapping everything to first-party finding.Finding values (Kind=quality/reliability, ungated, publishable like SAST). No LLM, no persistence – a read-only producer the CLI (and, later, the scan pipeline + UI) consume.

Index

Constants

View Source
const DefaultComplexityThreshold = 15

DefaultComplexityThreshold is the cyclomatic complexity above which a function earns a maintainability finding (a widely used "refactor" line). Configurable via WithComplexityThreshold.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Service)

Option configures a Service.

func WithBugs

func WithBugs(b ports.BugDetector) Option

WithBugs wires the deeper AST bug detector (unreachable code, constant conditions), emitting its findings as Kind=reliability. Requires the synapse-ast sidecar; degrades to nothing without it.

func WithComplexity

func WithComplexity(m ports.CodeMetricsProvider, threshold int) Option

WithComplexity adds high-complexity maintainability findings (functions over threshold), using the AST metrics provider. threshold <= 0 uses DefaultComplexityThreshold.

func WithDuplication

func WithDuplication(d ports.DuplicationScanner) Option

WithDuplication adds duplicated-block maintainability findings.

func WithInventory

func WithInventory(inv ports.CodeInventoryScanner) Option

WithInventory wires the code-size inventory, enabling Report() to compute ratings + a health summary.

func WithStructuralAnalyzer

func WithStructuralAnalyzer(a ports.CodeAnalyzer) Option

WithStructuralAnalyzer adds language-aware AST findings. It is optional; an unavailable sidecar returns no findings through its adapter.

func WithTestScopedSmells

func WithTestScopedSmells(include bool) Option

WithTestScopedSmells controls whether info-severity code smells located in test code (src/test, *_test.*, *.spec.*, __tests__, testdata, ...) are emitted. They are SUPPRESSED by default: a rule like commented-out-code fires heavily in tests and otherwise drowns the higher-value findings (complexity, duplication, reliability). Pass true to restore full verbosity. Only Info-severity smells are affected; medium/high findings (and every non-test finding) are always kept.

Because the filter lives in the single analyze() chokepoint, it also applies to BuildReport and thus to rating.Compute: test-scoped Info smells (5 debt-minutes each) are excluded from the technical-debt total and the maintainability grade by default, which is intentional (test TODOs are not production debt).

type Report

type Report struct {
	Inventory   measure.Inventory          `json:"inventory"`
	Findings    []finding.Finding          `json:"findings"`
	Duplication *measure.DuplicationReport `json:"duplication,omitempty"`
	Complexity  *measure.ComplexityReport  `json:"complexity,omitempty"`
	Truncated   bool                       `json:"truncated,omitempty"`
	Rating      rating.Report              `json:"rating"`
}

Report is the full code-quality dashboard payload for a source tree: the per-language inventory, the findings, the duplication summary, and the rolled-up A-E health ratings + technical debt.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service produces code-quality findings. analyzer is required; dup, metrics and inventory are optional enrichers.

func New

func New(analyzer ports.CodeAnalyzer, opts ...Option) *Service

New returns a Service. analyzer is required.

func (*Service) Analyze

func (s *Service) Analyze(ctx context.Context, root string) ([]finding.Finding, error)

Analyze returns the code-quality findings for root, sorted deterministically by dedup key.

func (*Service) BuildReport

func (s *Service) BuildReport(ctx context.Context, root string) (Report, error)

BuildReport computes the full dashboard report for root. Findings come from Analyze (which already bridges duplication + complexity); the inventory + duplication summary + ratings are added for display. Missing optional dependencies degrade to empty sections rather than erroring.

Jump to

Keyboard shortcuts

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