domain

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package domain provides core domain types and logic for art-dupl.

This package defines value objects for code duplication detection: - LineNumber, BytePosition, Filepath: file location types - Threshold, TokenCount, FileCount, CloneCount: metric types - CloneSeverity: classification of duplicate importance - Validation helpers for type-safe construction

All value objects are immutable and validated at construction time.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCloneSeverity = errors.New("invalid clone severity")
	ErrInvalidSeverity      = errors.New("invalid severity value")
)

Static errors for domain type validation.

Functions

This section is empty.

Types

type ClassificationInput added in v0.2.0

type ClassificationInput struct {
	Filename string
	NodeType int32
	Tokens   int
	Lines    int
}

ClassificationInput holds the data needed to classify a clone. Using a struct instead of primitives ensures the compiler catches missing fields when new classification inputs are added.

type CloneActionability added in v0.2.0

type CloneActionability string

CloneActionability indicates whether a clone can realistically be deduplicated.

const (
	// Actionable clones represent real logic duplication that can be extracted,
	// composed, or otherwise refactored to reduce duplication.
	Actionable CloneActionability = "actionable"
	// NonActionable clones are idiomatic patterns that cannot be deduplicated
	// without breaking Go semantics, interfaces, or standard conventions.
	NonActionable CloneActionability = "non-actionable"
)

type CloneCategory added in v0.2.0

type CloneCategory string

CloneCategory represents the category of code that was duplicated.

const (
	CategoryFunction    CloneCategory = "function"
	CategoryMethod      CloneCategory = "method"
	CategoryTest        CloneCategory = "test"
	CategoryStruct      CloneCategory = "struct"
	CategoryInterface   CloneCategory = "interface"
	CategoryHandler     CloneCategory = "handler"
	CategoryLoop        CloneCategory = "loop"
	CategoryConditional CloneCategory = "conditional"
	CategoryAssignment  CloneCategory = "assignment"
	CategoryExpression  CloneCategory = "expression"
	CategoryUnknown     CloneCategory = "unknown"
)

func (CloneCategory) GetCategoryEmoji added in v0.2.0

func (c CloneCategory) GetCategoryEmoji() string

type CloneClassification added in v0.2.0

type CloneClassification struct {
	Category      CloneCategory
	IsTest        bool
	Priority      ClonePriority
	Actionability CloneActionability
	Tokens        int
	Lines         int
	NodeType      string
	Suggestion    string
}

CloneClassification provides metadata about a code clone for actionable reports.

type ClonePriority added in v0.2.0

type ClonePriority string

ClonePriority represents how important it is to address this clone.

const (
	PriorityCritical ClonePriority = "critical"
	PriorityHigh     ClonePriority = "high"
	PriorityMedium   ClonePriority = "medium"
	PriorityLow      ClonePriority = "low"
)

func (ClonePriority) GetPriorityColor added in v0.2.0

func (p ClonePriority) GetPriorityColor() string

func (ClonePriority) GetPriorityEmoji added in v0.2.0

func (p ClonePriority) GetPriorityEmoji() string

type CloneSeverity

type CloneSeverity string

CloneSeverity represents clone severity levels for categorizing duplicate code.

const (
	// CloneSeverityLow indicates minor duplication with low impact.
	CloneSeverityLow CloneSeverity = "low"
	// CloneSeverityMedium indicates moderate duplication that should be reviewed.
	CloneSeverityMedium CloneSeverity = "medium"
	// CloneSeverityHigh indicates significant duplication requiring attention.
	CloneSeverityHigh CloneSeverity = "high"
	// CloneSeverityCritical indicates severe duplication that must be addressed.
	CloneSeverityCritical CloneSeverity = "critical"
)

Clone severity constants define the importance level of detected clones.

func (CloneSeverity) IsValid

func (cs CloneSeverity) IsValid() bool

IsValid returns true if the severity is one of the defined constants.

func (CloneSeverity) MarshalJSON

func (cs CloneSeverity) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for CloneSeverity.

func (CloneSeverity) String

func (cs CloneSeverity) String() string

String returns the string representation of the severity.

func (*CloneSeverity) UnmarshalJSON

func (cs *CloneSeverity) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for CloneSeverity.

type Filepath

type Filepath string

Filepath represents a filesystem path.

func NewFilepath

func NewFilepath(path string) (Filepath, error)

NewFilepath creates a validated Filepath from a string.

func (Filepath) MarshalJSON

func (fp Filepath) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for Filepath.

func (Filepath) String

func (fp Filepath) String() string

String returns the string representation of Filepath.

func (*Filepath) UnmarshalJSON

func (fp *Filepath) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for Filepath.

type LineNumber

type LineNumber uint16

LineNumber represents a line number in a source file. Line numbers start at 1 (not 0) in most editors. Optimized: uint16 provides 0-65,535 range (sufficient for any source file).

func NewLineNumber

func NewLineNumber(n uint16) (LineNumber, error)

NewLineNumber creates a validated LineNumber from a uint16. Returns error if the line number is 0 (invalid).

func (LineNumber) MarshalJSON

func (ln LineNumber) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for LineNumber.

func (LineNumber) Uint16

func (ln LineNumber) Uint16() uint16

Uint16 returns the underlying uint16 value.

func (*LineNumber) UnmarshalJSON

func (ln *LineNumber) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for LineNumber.

type ProcessedClone added in v0.2.0

type ProcessedClone struct {
	Filename       string
	LineStart      int
	LineEnd        int
	Fragment       []byte
	Size           int
	FileSize       int
	Classification CloneClassification
}

ProcessedClone represents a single clone instance with extracted fragment data. Decouples printer output from syntax.Node internals.

type ProcessedCloneGroup added in v0.2.0

type ProcessedCloneGroup struct {
	Hash   string
	Size   int
	Clones []ProcessedClone
}

ProcessedCloneGroup represents a group of duplicate code fragments.

Jump to

Keyboard shortcuts

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