codestats

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package codestats provides code statistics analysis (lines of code, comments, blanks, complexity)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalyzedBucket

type AnalyzedBucket struct {
	Total      Stats           `json:"total"`
	ByLanguage []LanguageStats `json:"by_language"` // Sorted by lines descending
}

AnalyzedBucket holds stats for SCC-analyzed files (full code/comments/blanks breakdown)

type Analyzer

type Analyzer interface {
	// ProcessFile analyzes a file and adds its stats
	// language is the go-enry detected language name (used for grouping)
	// If content is provided, it will be used; otherwise the file will be read
	ProcessFile(filename string, language string, content []byte)

	// ProcessFileForComponent analyzes a file for a specific component
	// componentID is used to group stats by component
	// language is the go-enry detected language name (used for grouping)
	// If content is provided, it will be used; otherwise the file will be read
	ProcessFileForComponent(filename string, language string, content []byte, componentID string)

	// GetStats returns the aggregated statistics
	GetStats() interface{}

	// GetComponentStats returns statistics for a specific component
	GetComponentStats(componentID string) interface{}

	// IsEnabled returns whether code stats collection is enabled
	IsEnabled() bool

	// IsPerComponentEnabled returns whether per-component code stats collection is enabled
	IsPerComponentEnabled() bool
}

Analyzer interface for code statistics collection

func NewAnalyzer

func NewAnalyzer(enabled bool) Analyzer

NewAnalyzer creates an analyzer based on enabled flag

func NewAnalyzerWithOptions

func NewAnalyzerWithOptions(enabled bool, perComponent bool, primaryThreshold float64, maxPrimaryLangs int) Analyzer

NewAnalyzerWithOptions creates an analyzer with all custom options

func NewAnalyzerWithPerComponent

func NewAnalyzerWithPerComponent(enabled bool, perComponent bool) Analyzer

NewAnalyzerWithPerComponent creates an analyzer with per-component option

type ByType

type ByType struct {
	Programming *TypeBucket `json:"programming,omitempty"`
	Data        *TypeBucket `json:"data,omitempty"`
	Markup      *TypeBucket `json:"markup,omitempty"`
	Prose       *TypeBucket `json:"prose,omitempty"`
}

ByType holds stats grouped by GitHub Linguist language type

type CodeStats

type CodeStats struct {
	Total      Stats            `json:"total"`      // Grand total (analyzed only)
	ByType     ByType           `json:"by_type"`    // Stats grouped by language type (metrics in programming section)
	Analyzed   AnalyzedBucket   `json:"analyzed"`   // SCC-recognized languages
	Unanalyzed UnanalyzedBucket `json:"unanalyzed"` // Files SCC can't parse
}

CodeStats holds aggregated code statistics

type LanguageStats

type LanguageStats struct {
	Language   string `json:"language"`
	Lines      int64  `json:"lines"`
	Code       int64  `json:"code"`
	Comments   int64  `json:"comments"`
	Blanks     int64  `json:"blanks"`
	Complexity int64  `json:"complexity"`
	Files      int    `json:"files"`
}

LanguageStats holds stats for a specific language (includes language name for sorted output)

type Metrics

type Metrics struct {
	CommentRatio      float64           `json:"comment_ratio"`       // comments / code (documentation level)
	CodeDensity       float64           `json:"code_density"`        // code / lines (actual code vs whitespace/comments)
	AvgFileSize       float64           `json:"avg_file_size"`       // lines / files
	ComplexityPerKLOC float64           `json:"complexity_per_kloc"` // complexity / (code / 1000)
	AvgComplexity     float64           `json:"avg_complexity"`      // complexity / files
	PrimaryLanguages  []PrimaryLanguage `json:"primary_languages"`   // primary programming languages (≥1%)
}

Metrics holds derived code metrics (programming languages only)

type OtherLanguageStats

type OtherLanguageStats struct {
	Language string `json:"language"`
	Lines    int64  `json:"lines"`
	Files    int    `json:"files"`
}

OtherLanguageStats holds stats for unanalyzed language (includes language name)

type OtherStats

type OtherStats struct {
	Lines int64 `json:"lines"`
	Files int   `json:"files"`
}

OtherStats holds statistics for files SCC cannot analyze (just line counts)

type PrimaryLanguage

type PrimaryLanguage struct {
	Language string  `json:"language"`
	Pct      float64 `json:"pct"`
}

PrimaryLanguage represents a primary programming language in Metrics

type Stats

type Stats struct {
	Lines      int64 `json:"lines"`
	Code       int64 `json:"code"`
	Comments   int64 `json:"comments"`
	Blanks     int64 `json:"blanks"`
	Complexity int64 `json:"complexity"`
	Files      int   `json:"files"`
}

Stats holds code statistics for a language or total (SCC-analyzed files)

type TypeBucket

type TypeBucket struct {
	Total     Stats    `json:"total"`             // Aggregated stats for this type
	Metrics   *Metrics `json:"metrics,omitempty"` // Derived metrics (programming languages only)
	Languages []string `json:"languages"`         // Languages in this type (sorted by lines desc)
}

TypeBucket holds stats for a language type (programming, data, markup, prose)

type UnanalyzedBucket

type UnanalyzedBucket struct {
	Total      OtherStats           `json:"total"`
	ByLanguage []OtherLanguageStats `json:"by_language"` // Sorted by lines descending
}

UnanalyzedBucket holds stats for files SCC cannot analyze (just line counts)

Jump to

Keyboard shortcuts

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