analyzer

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzeFile

func AnalyzeFile(filepath string) ([]string, error)

AnalyzeFile analyzes a Go source file and returns its functions and methods

func CalculateCommentDensity

func CalculateCommentDensity(fileContent string, comments []*ast.CommentGroup) float64

CalculateCommentDensity computes the ratio of comment lines to total lines in the file.

func CalculateCyclomaticComplexity

func CalculateCyclomaticComplexity(n ast.Node) int

CalculateCyclomaticComplexity calculates the cyclomatic complexity for a given AST node.

func CalculateHalsteadVolume

func CalculateHalsteadVolume(src string) float64

CalculateHalsteadVolume computes a simplified Halstead Volume based on operator and operand counts.

func CalculateLOC

func CalculateLOC(src string) int

CalculateLOC returns the number of lines in the source code.

func CalculateMaintainabilityIndex

func CalculateMaintainabilityIndex(cyclomatic int, halsteadVolume float64, loc int, commentDensity float64, commentDensityMultiplier float64) float64

CalculateMaintainabilityIndex computes the Maintainability Index (MI) using a standard formula and a bonus from comment density.

Types

type MethodResult

type MethodResult struct {
	MethodName           string
	Cyclomatic           int
	HalsteadVolume       float64
	LOC                  int
	MaintainabilityIndex float64
}

MethodResult holds the analysis results for each function.

func AnalyzeMethods

func AnalyzeMethods(filePath string, commentDensityMultiplier float64) ([]MethodResult, float64, error)

AnalyzeMethods analyzes all functions in a given Go source file and computes code quality metrics. It returns the analysis results for each function and the global comment density.

Jump to

Keyboard shortcuts

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