step

package
v0.0.0-...-5749229 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 9 Imported by: 0

README

代码统计工具

注意点

config.yml文件要放在exe所在目录。

input.yml仅作为main()函数中使用的输入文件。

Documentation

Index

Constants

View Source
const CONFIG_FILE = "./config.yml"

/ 程序设置文件

Variables

This section is empty.

Functions

func Count

func Count(file string, mCommentRegExp *map[string]CommentRegExp, stepInfo *[]StepInfo) error

统计单文件代码行数

func Escape

func Escape(sRegExp string) string

转义

func MatchIn

func MatchIn(line string, regexList []*regexp.Regexp) (matchIndex int, isMatch bool)

多个标志的正则表达式确认

func ToCommentRegExp

func ToCommentRegExp(cmtDef []CommentDefine) map[string]CommentRegExp

/ 注释定义转注释正则表达式

Types

type CommentDefine

type CommentDefine struct {
	// 扩展名(多个)
	FileExtension []string `yaml:"fileExtension"`
	// 单行正则表达式
	SingleLine []string `yaml:"singleLine"`
	// 多行正则表达式 开始
	MultiLineStart []string `yaml:"multiLineStart"`
	// 多行正则表达式 结束
	MultiLineEnd []string `yaml:"multiLineEnd"`
}

代码注释统计用正则表达式定义

func LoadCommentConfig

func LoadCommentConfig(commentDefineFile string) ([]CommentDefine, error)

/ 从注释定义文件读取注释定义

type CommentRegExp

type CommentRegExp struct {
	// 扩展名
	FileExtension string
	// 有单行注释
	HasSingleLineMark bool
	// 有多行注释
	HasMultiLineMark bool

	// 空正则表达式
	RegExEmptyLine *regexp.Regexp
	// 单行正则表达式
	RegExSingleLine []*regexp.Regexp
	// 写在单行的多行正则表达式 开始结束
	RegExSingleLineStartEnd []*regexp.Regexp
	// 多行正则表达式 开始
	RegExMultiLineStart []*regexp.Regexp
	// 多行正则表达式 结束
	RegExMultiLineEnd []*regexp.Regexp
}

代码注释统计用正则表达式定义

func ToRegExp

func ToRegExp(ext string, def CommentDefine) CommentRegExp

转换为正则表达式

type StepInfo

type StepInfo struct {
	CommentRuleDefined bool   `json:"commentRuleDefined"` // 存在注释标志定义 true:存在 false:不存在
	File               string `json:"file"`               // 文件名(全路径)
	FileName           string `json:"fileName"`           // 文件名
	TotalStep          int    `json:"totalStep"`          // 总行数
	EmptyLineStep      int    `json:"emptyLineStep"`      // 空行数
	CommentStep        int    `json:"commentStep"`        // 注释行数
	SourceStep         int    `json:"sourceStep"`         // 代码行数
	ValidStep          int    `json:"validStep"`          // 有效行数(注释+代码)
	ExInfo             string `json:"exInfo"`             // 扩展信息
	Counted            bool   `json:"counted"`            // 已统计标志 true:已统计 false:未统计
}

代码行数信息

func CountAll

func CountAll(file []string, mCommentRegExp *map[string]CommentRegExp) []StepInfo

统计多文件代码行数

type StepSummary

type StepSummary struct {
	StepInfo      []StepInfo `json:"stepInfo"`      // 代码行数统计结果
	FlatFile      []string   `json:"flatFile"`      // 无注标志定义文件
	UnCountedFile []string   `json:"unCountedFile"` // 未统计文件一览
	FileCount     int        `json:"fileCount"`     // 文件总数
	TotalStep     int        `json:"totalStep"`     // 总行数
	EmptyLineStep int        `json:"emptyLineStep"` // 空行总行数
	CommentStep   int        `json:"commentStep"`   // 注释总行数
	SourceStep    int        `json:"sourceStep"`    // 代码总行数
	ValidStep     int        `json:"validStep"`     // 有效总行数(注释+代码)
}

代码行数信息汇总

func Step

func Step(file []string) StepSummary

/ 统计代码文件列表的代码行数

func Summary

func Summary(stepInfo []StepInfo) StepSummary

代码行数统计结果

Jump to

Keyboard shortcuts

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