score

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package score ranks static-analysis findings so renderers can lead with the ones that matter. The score is severity weight × file centrality: errors outweigh warnings outweigh notes, and production code outweighs internal/test code. Used by pkg/view to order Findings before rendering.

Weights are constants (no runtime flag) — tuning means editing the package, not configuring fo.

Index

Constants

View Source
const (
	SeverityWeightError   = 3
	SeverityWeightWarning = 2
	SeverityWeightNote    = 1
)

Severity weights used by Score. Tunable as constants — no runtime flag.

View Source
const (
	CentralityRoot     = 1.0  // cmd/* or pkg/* roots
	CentralityInternal = 0.5  // internal/* paths
	CentralityTest     = 0.25 // any *_test.go file
	CentralityDefault  = 1.0  // anything else (treat as root-equivalent)
)

File centrality factors used by Score. Tests get the lowest weight so that production code defects sort above test-file defects of equal severity.

Variables

This section is empty.

Functions

func FileCentrality

func FileCentrality(path string) float64

FileCentrality returns the centrality factor for path.

Precedence (first match wins):

  1. *_test.go → CentralityTest (test files, even under cmd/ or pkg/)
  2. internal/ → CentralityInternal
  3. cmd/ or pkg/ → CentralityRoot
  4. anything else → CentralityDefault

Test-file precedence is intentional: a defect inside a *_test.go file under pkg/ is still test code and should sort below production defects of equal severity.

func Score

func Score(severityWeight, occurrenceCount int, path string) float64

Score is the deterministic priority score for a finding:

score = severityWeight × occurrenceCount × fileCentrality(path)

Higher scores sort first. Inputs are expected to be non-negative; callers that pass an occurrenceCount of 0 will get a score of 0.

func SeverityWeight

func SeverityWeight(level string) int

SeverityWeight maps a SARIF level string to its score weight. Unknown levels (including empty and "none") get the note weight.

Types

This section is empty.

Jump to

Keyboard shortcuts

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