duplication

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: 10 Imported by: 0

Documentation

Overview

Package duplication is a deterministic, pure-Go copy-paste (clone) detector: it walks a source tree, tokenizes each file (comment- and whitespace-insensitive, language-aware comment stripping), and finds runs of duplicated tokens across and within files via a Rabin-Karp rolling hash, then reports the standard duplication metrics (blocks, duplicated lines, files, density). It NEVER executes the target and reads bounded (skips vendored/binary/oversized files, follows no symlinks). Pure Go with no CGO, so it is available in every build (unlike the tree-sitter metrics sidecar). Exact (Type-1) clones: identifiers and literals are matched by text, which is the copy-paste signal operators expect.

Index

Constants

View Source
const (
	// DefaultMinTokens is the smallest duplicated token run reported by default. Tokens here are at
	// lexer granularity (an identifier/number, a whole string literal, or an operator run – see the
	// tokenizer), so 100 matches the long-standing PMD/CPD default and keeps trivial repetition out.
	DefaultMinTokens = 100
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Detector

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

Detector finds duplicated token runs of at least MinTokens tokens.

func New

func New(minTokens int) *Detector

New returns a detector. minTokens <= 0 uses DefaultMinTokens.

func (*Detector) Duplication

func (d *Detector) Duplication(ctx context.Context, root string) (measure.DuplicationReport, error)

Duplication walks root, tokenizes each supported source file, and returns the duplication report.

Jump to

Keyboard shortcuts

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