Documentation
¶
Overview ¶
Package baseline records and compares sets of accepted clone hashes so art-dupl can run as a CI gate: a baseline captures the clones a codebase currently has, and a check reports only clones that are new relative to the baseline.
File format (JSON):
{
"version": "1.0",
"threshold": 15,
"recorded_at": "2026-06-20T18:30:00Z",
"entries": [
{"hash": "abc123", "files": ["a.go", "b.go"], "tokens": 42}
]
}
Matching is by clone-group hash (content fingerprint), so renamed files or moved code that keeps the same structure still matches the baseline.
Index ¶
Constants ¶
const DefaultBaselinePath = ".art-dupl-baseline.json"
DefaultBaselinePath is the conventional location for the baseline file.
Variables ¶
var ErrUnsupportedBaselineVersion = errors.New("unsupported baseline version")
ErrUnsupportedBaselineVersion is returned by Load when the on-disk baseline uses a file-format version this binary cannot interpret. CI must fail loudly rather than silently treating an incompatible file as an empty baseline.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
Hash string `json:"hash"`
Files []string `json:"files"`
Tokens int `json:"tokens"`
}
Entry records a single accepted clone group.
type File ¶
type File struct {
Version string `json:"version"`
Threshold int `json:"threshold"`
RecordedAt time.Time `json:"recordedAt"`
Entries []Entry `json:"entries"`
// contains filtered or unexported fields
}
File is the on-disk baseline representation.
func Load ¶
Load reads a baseline from disk. Returns a wrapped error if the file cannot be read or parsed.
func (*File) Add ¶
Add records a clone group in the baseline. Duplicate hashes are ignored. The files slice is copied so later caller mutation cannot corrupt the entry.
func (*File) Save ¶
Save writes the baseline to disk as formatted JSON. Entries are sorted by hash for deterministic, reviewable diffs. The write is atomic: data is written to a temp file in the same directory and then renamed, so a crash mid-write never leaves a truncated baseline that would silently empty the CI accepted-set.