baseline

package
v0.6.2 Latest Latest
Warning

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

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

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

View Source
const DefaultBaselinePath = ".art-dupl-baseline.json"

DefaultBaselinePath is the conventional location for the baseline file.

Variables

View Source
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

func Exists

func Exists(path string) bool

Exists reports whether a baseline file is present at the given path.

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

func Load(path string) (*File, error)

Load reads a baseline from disk. Returns a wrapped error if the file cannot be read or parsed.

func NewFile

func NewFile(threshold int) *File

NewFile creates an empty baseline ready to accept entries.

func (*File) Add

func (bf *File) Add(hash string, files []string, tokens int)

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) Has

func (bf *File) Has(hash string) bool

Has reports whether the baseline already accepts the given clone hash.

func (*File) Len

func (bf *File) Len() int

Len returns the number of accepted clone groups.

func (*File) Save

func (bf *File) Save(path string) error

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.

Jump to

Keyboard shortcuts

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