engine

package
v0.0.0-...-46be04c Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTpl = `` /* 722592-byte string literal not displayed */

Variables

This section is empty.

Functions

func SaveAsHtml

func SaveAsHtml(htmlData HtmlData, projectPath, savePath, timestamp, tpl string)

SaveAsHtml is a function that save HtmlData as a html report.And will receive htmlData, projectPath, savePath and tpl parameters.

Types

type CodeCount

type CodeCount struct {
	Summary struct {
		LineCount     int `json:"line_count"`
		CommentCount  int `json:"comment_count"`
		FunctionCount int `json:"function_count"`
		FileCount     int `json:"file_count"`
	} `json:"summary"`
	Content struct {
		Pkg               []string `json:"pkg"`
		PkgLineCount      []int    `json:"pkg_line_count"`
		PkgCommentCount   []int    `json:"pkg_comment_count"`
		PkgFunctionCount  []int    `json:"pkg_function_count"`
		File              []string `json:"file"`
		FileLineCount     []int    `json:"file_line_count"`
		FileCommentCount  []int    `json:"file_comment_count"`
		FileFunctionCount []int    `json:"file_function_count"`
	} `json:"content"`
}

CodeCount is a struct that contains Summary and Content. t represents the code statistics of the data, you can understand the project from the perspective of the number of lines.

type CodeOptimization

type CodeOptimization struct {
	Summary struct {
		IssuesNum int    `json:"issue_num"`
		FilesNum  int    `json:"file_num"`
		Quality   string `json:"quality"`
	} `json:"summary"`
	Content struct {
		DeadCode       StyleItem `json:"dead_code"`
		SimpleCode     StyleItem `json:"simple_code"`
		StaticCode     StyleItem `json:"static_code"`
		CopyCode       CopyItem  `json:"copy_code"`
		InterfacerCode StyleItem `json:"interfacer_code"`
	} `json:"content"`
}

CodeTest is a struct that contains Summary and Content. It represents the result data of the project unit test.

type CodeSmell

type CodeSmell struct {
	Summary struct {
		CycloAvg   int `json:"cyclo_avg"`
		CycloHigh  int `json:"cyclo_high"`
		CycloGrave int `json:"cyclo_grave"`
	} `json:"summary"`
	Content struct {
		Percentage map[string]int  `json:"percentage"`
		Pkg        []string        `json:"pkg"`
		Cyclo      []int           `json:"cyclo"`
		List       []CodeSmellItem `json:"list"`
	} `json:"content"`
}

CodeSmell is a struct that contains Summary and Content. It represents the taste of the code data, you can understand the project from the perspective of complexity.

type CodeSmellItem

type CodeSmellItem struct {
	Path  string `json:"path"`
	Cyclo int    `json:"cyclo"`
}

CodeSmellItem is a struct that contains path and cyclo.

type CodeStyle

type CodeStyle struct {
	Summary struct {
		IssuesNum int    `json:"issue_num"`
		FilesNum  int    `json:"file_num"`
		Quality   string `json:"quality"`
	} `json:"summary"`
	Content struct {
		GoFmt     StyleItem `json:"go_fmt"`
		GoVet     StyleItem `json:"go_vet"`
		GoLint    StyleItem `json:"go_lint"`
		MissSpell StyleItem `json:"miss_spell"`
	} `json:"content"`
}

CodeTest is a struct that contains Summary and Content. It represents the result data of the project unit test.

type CodeTest

type CodeTest struct {
	Summary struct {
		CodeCover    float64 `json:"code_cover"`
		PackageCover float64 `json:"pkg_cover"`
		TotalTime    float64 `json:"total_time"`
	} `json:"summary"`
	Content struct {
		Pkg    []string  `json:"pkg"`
		Cover  []float64 `json:"cover"`
		Time   []float64 `json:"time"`
		NoTest []string  `json:"no_test"`
	} `json:"content"`
}

CodeTest is a struct that contains Summary and Content. It represents the result data of the project unit test.

type CopyItem

type CopyItem struct {
	Label  string     `json:"label"`
	Score  int        `json:"score"`
	Detail [][]string `json:"detail"`
	// contains filtered or unexported fields
}

CodeTest is a struct that contains Summary and Content. It represents the result data of the project unit test.

type Copycode

type Copycode struct {
	Files string
	Path  []string
}

Copycode is a struct that contains Files and Path. The type of Path MUST []string that contains more than one file path. The Copycode represents some copyed code information.

type Cyclo

type Cyclo struct {
	Pkg  string
	Size int
	Info []CycloInfo
}

Cyclo is a struct that contains Pkg, Size and Info. The type of Info MUST []CycloInfo that represents detail information of all function.

type CycloInfo

type CycloInfo struct {
	Comp int
	Info string
}

CycloInfo is a struct that contains Comp and Info. The type of Comp MUST int that represents the cyclo of one function.The CycloInfo represents one cyclo function information.

type Cycloi

type Cycloi struct {
	Average string
	Result  []string
}

Cycloi is a struct that contains Average and Result. The Average is one package's cyclo coverage. And Result is the detail cyclo of the package's all function.

type Deadcode

type Deadcode struct {
	Path string
	Info string
}

Deadcode is a struct that contains Path and Info. The type of Path and Info MUST string. The Deadcode represents one dead code.

type Depth

type Depth struct {
	Pkg  string
	Size int
	Info []DepthInfo
}

Depth is a struct that contains Pkg, Size and Info. Info is an alias to CycloInfo

type DepthInfo

type DepthInfo CycloInfo

type Error

type Error struct {
	LineNumber  int    `json:"line_number"`
	ErrorString string `json:"error_string"`
}

Error contains the line number and the reason for an error output from a command

type File

type File struct {
	Color     string
	CycloVal  string
	CycloInfo string
}

File is a struct that contains Color, CycloVal and CycloInfo. And it is just for one file's display. The CycloInfo contains all cyclo detail information.

type HtmlData

type HtmlData struct {
	Project          string
	Score            int
	IssuesNum        int
	CodeTest         string
	CodeStyle        string
	CodeOptimization string
	CodeCount        string
	CodeSmell        string
	DepGraph         template.HTML

	Date                 string
	LastRefresh          time.Time `json:"last_refresh"`
	HumanizedLastRefresh string    `json:"humanized_last_refresh"`
}

UnitTest is a struct that contains some features in a report of html.

     GoReporter HTML Report Features

+----------------------------------------------------------------------+
|        Feature        |                 Information                  |
+=======================+==============================================+
| Project               | The path address of the item being detected  |
+-----------------------+----------------------------------------------+
| Score                 | The score of the tested project              |
+-----------------------+----------------------------------------------+
| CodeTest              | Unit test results                            |
+-----------------------+----------------------------------------------+
| IssuesNum             | Issues number of the project                 |
+-----------------------+----------------------------------------------+
| CodeCount             | Number of lines of code                      |
+-----------------------+----------------------------------------------+
| CodeStyle             | Code style check                             |
+-----------------------+----------------------------------------------+
| CodeOptimization      | Code optimization                            |
+-----------------------+----------------------------------------------+
| CodeSmell             | Code smell                                   |
+-----------------------+----------------------------------------------+
| DepGraph              | Depend graph of all packages in the project  |
+-----------------------+----------------------------------------------+
| Date                  | Date assessment of the project               |
+-----------------------+----------------------------------------------+
| LastRefresh           | Last refresh time of one project             |
+-----------------------+----------------------------------------------+
| HumanizedLastRefresh  | Humanized last refresh setting               |
+-----------------------+----------------------------------------------+

And the HtmlData just as data for default html template. If you want to customize your own template file, please follow these data, or you can redefine it yourself.

type Interfacer

type Interfacer struct {
	Path string
	Info string
}

Interfacer is a struct that contains Path and Info. The type of Path and Info MUST string. The Interfacer warns about the usage of types that are more specific than necessary.

type Item

type Item struct {
	File    string   `json:"rep"`
	Content []string `json:"content"`
}

Item is a struct that contains File and Content. It is the code-based infrastructure.

type Metric

type Metric struct {
	Name        string             `json:"name"`
	Description string             `json:"description"`
	Summaries   map[string]Summary `json:"summaries"`
	Weight      float64            `json:"weight"`
	Percentage  float64            `json:"percentage"`
	Error       string             `json:"error"`
}

Metric as template of report and will save all linters result data.But may have some difference in different linter.

type PackageTest

type PackageTest struct {
	IsPass   bool    `json:"is_pass"`
	Coverage string  `json:"coverage"`
	Time     float64 `json:"time"`
}

PackageTest is a struct that contains IsPass, Coverage and Time. The type of Time MUST float64.

type Race

type Race struct {
	Pkg  string
	Len  string
	Leng string
	Info []string
}

Race is a struct that contains Pkg, Len, Leng and Info. The type of Info MUST []string that represents more than one race case. Len is the number of cases.

type Reporter

type Reporter struct {
	Project   string            `json:"project"`
	Score     int               `json:"score"`
	Grade     int               `json:"grade"`
	Metrics   map[string]Metric `json:"metrics"`
	Issues    int               `json:"issues"`
	TimeStamp string            `json:"time_stamp"`
	Linters   []StrategyLinter
	Sync      *Synchronizer `inject:"" json:"-"`

	ProjectPath    string `json:"-"`
	ReportPath     string `json:"-"`
	HtmlTemplate   string `json:"-"`
	ReportFormat   string `json:"-"`
	ExceptPackages string `json:"-"`

	StartTime time.Time
}

Reporter is the top struct of GoReporter.

func NewReporter

func NewReporter(projectPath, reportPath, reportFormat, htmlTemplate string) *Reporter

func (*Reporter) AddLinters

func (r *Reporter) AddLinters(strategies ...StrategyLinter)

func (*Reporter) Close

func (r *Reporter) Close()

func (*Reporter) GetFinalScore

func (r *Reporter) GetFinalScore() (score float64)

func (*Reporter) Render

func (r *Reporter) Render() (err error)

func (*Reporter) Report

func (r *Reporter) Report() error

Report is a important function of goreporter, it will run all linters and rebuild metrics data in a golang project. And all linters' result will be as one metric data for Reporter.

type Scan

type Scan struct {
	Path string
	Info string
}

Scan is a struct that contains Path and Info. The type of Path and Info MUST string. The Scan represents one defect case.

type Simple

type Simple struct {
	Path string
	Info string
}

Simple is a struct that contains Path and Info. The type of Path and Info MUST string. The Simple represents one can be simpled code case.

type Spell

type Spell struct {
	Path string
	Info string
}

Spell is a struct that contains Path and Info. The type of Path and Info MUST string. The Spell represents one word is misspelled.

type StrategyCopyCheck

type StrategyCopyCheck struct {
	Sync *Synchronizer `inject:""`
}

func (*StrategyCopyCheck) Compute

func (s *StrategyCopyCheck) Compute(parameters StrategyParameter) (summaries *Summaries)

linterCopy provides a function that scans all duplicate code in the project and give duplicate code locations and rows.It will extract from the linter need to convert the data.The result will be saved in the r's attributes.

func (*StrategyCopyCheck) GetDescription

func (s *StrategyCopyCheck) GetDescription() string

func (*StrategyCopyCheck) GetName

func (s *StrategyCopyCheck) GetName() string

func (*StrategyCopyCheck) GetWeight

func (s *StrategyCopyCheck) GetWeight() float64

func (*StrategyCopyCheck) Percentage

func (s *StrategyCopyCheck) Percentage(summaries *Summaries) float64

type StrategyCountCode

type StrategyCountCode struct {
	Sync *Synchronizer `inject:""`
}

func (*StrategyCountCode) Compute

func (s *StrategyCountCode) Compute(parameters StrategyParameter) (summaries *Summaries)

linterCount is a function that counts go files and go code lines of project.It will extract from the linter need to convert the data. The result will be saved in the r's attributes.

func (*StrategyCountCode) GetDescription

func (s *StrategyCountCode) GetDescription() string

func (*StrategyCountCode) GetName

func (s *StrategyCountCode) GetName() string

func (*StrategyCountCode) GetWeight

func (s *StrategyCountCode) GetWeight() float64

func (*StrategyCountCode) Percentage

func (s *StrategyCountCode) Percentage(summaries *Summaries) float64

type StrategyCyclo

type StrategyCyclo struct {
	Sync *Synchronizer `inject:""`
	// contains filtered or unexported fields
}

func (*StrategyCyclo) Compute

func (s *StrategyCyclo) Compute(parameters StrategyParameter) (summaries *Summaries)

func (*StrategyCyclo) GetDescription

func (s *StrategyCyclo) GetDescription() string

func (*StrategyCyclo) GetName

func (s *StrategyCyclo) GetName() string

func (*StrategyCyclo) GetWeight

func (s *StrategyCyclo) GetWeight() float64

func (*StrategyCyclo) Percentage

func (s *StrategyCyclo) Percentage(summaries *Summaries) float64

type StrategyDeadCode

type StrategyDeadCode struct {
	Sync *Synchronizer `inject:""`
}

func (*StrategyDeadCode) Compute

func (s *StrategyDeadCode) Compute(parameters StrategyParameter) (summaries *Summaries)

linterDead provides a function that will scans all useless code, or never obsolete obsolete code.It will extract from the linter need to convert the data.The result will be saved in the r's attributes.

func (*StrategyDeadCode) GetDescription

func (s *StrategyDeadCode) GetDescription() string

func (*StrategyDeadCode) GetName

func (s *StrategyDeadCode) GetName() string

func (*StrategyDeadCode) GetWeight

func (s *StrategyDeadCode) GetWeight() float64

func (*StrategyDeadCode) Percentage

func (s *StrategyDeadCode) Percentage(summaries *Summaries) float64

type StrategyDependGraph

type StrategyDependGraph struct {
	Sync *Synchronizer `inject:""`
}

func (*StrategyDependGraph) Compute

func (s *StrategyDependGraph) Compute(parameters StrategyParameter) (summaries *Summaries)

linterDependGraph is a function that builds the dependency graph of all packages in the project helps you optimize the project architecture.It will extract from the linter need to convert the data.The result will be saved in the r's attributes.

func (*StrategyDependGraph) GetDescription

func (s *StrategyDependGraph) GetDescription() string

func (*StrategyDependGraph) GetName

func (s *StrategyDependGraph) GetName() string

func (*StrategyDependGraph) GetWeight

func (s *StrategyDependGraph) GetWeight() float64

func (*StrategyDependGraph) Percentage

func (s *StrategyDependGraph) Percentage(summaries *Summaries) float64

type StrategyDepth

type StrategyDepth struct {
	Sync *Synchronizer `inject:""`
	// contains filtered or unexported fields
}

func (*StrategyDepth) Compute

func (s *StrategyDepth) Compute(parameters StrategyParameter) (summaries *Summaries)

Compute all [.go] file's function maximum depth. It is an important indicator that allows developer to see whether a function needs to be splitted into smaller functions for readability purpose

func (*StrategyDepth) GetDescription

func (s *StrategyDepth) GetDescription() string

func (*StrategyDepth) GetName

func (s *StrategyDepth) GetName() string

func (*StrategyDepth) GetWeight

func (s *StrategyDepth) GetWeight() float64

func (*StrategyDepth) Percentage

func (s *StrategyDepth) Percentage(summaries *Summaries) float64

type StrategyGoFmt

type StrategyGoFmt struct {
	Sync *Synchronizer `inject:""`
}

func (*StrategyGoFmt) Compute

func (s *StrategyGoFmt) Compute(parameters StrategyParameter) (summaries *Summaries)

func (*StrategyGoFmt) GetDescription

func (s *StrategyGoFmt) GetDescription() string

func (*StrategyGoFmt) GetName

func (s *StrategyGoFmt) GetName() string

func (*StrategyGoFmt) GetWeight

func (s *StrategyGoFmt) GetWeight() float64

func (*StrategyGoFmt) Percentage

func (s *StrategyGoFmt) Percentage(summaries *Summaries) float64

type StrategyGoVet

type StrategyGoVet struct {
	Sync *Synchronizer `inject:""`
}

func (*StrategyGoVet) Compute

func (s *StrategyGoVet) Compute(parameters StrategyParameter) (summaries *Summaries)

func (*StrategyGoVet) GetDescription

func (s *StrategyGoVet) GetDescription() string

func (*StrategyGoVet) GetName

func (s *StrategyGoVet) GetName() string

func (*StrategyGoVet) GetWeight

func (s *StrategyGoVet) GetWeight() float64

func (*StrategyGoVet) Percentage

func (s *StrategyGoVet) Percentage(summaries *Summaries) float64

type StrategyImportPackages

type StrategyImportPackages struct {
	Sync *Synchronizer `inject:""`
}

func (*StrategyImportPackages) Compute

func (s *StrategyImportPackages) Compute(parameters StrategyParameter) (summaries *Summaries)

linterImportPackages is a function that scan the project contains all the package lists.It will extract from the linter need to convert the data.The result will be saved in the r's attributes.

func (*StrategyImportPackages) GetDescription

func (s *StrategyImportPackages) GetDescription() string

func (*StrategyImportPackages) GetName

func (s *StrategyImportPackages) GetName() string

func (*StrategyImportPackages) GetWeight

func (s *StrategyImportPackages) GetWeight() float64

func (*StrategyImportPackages) Percentage

func (s *StrategyImportPackages) Percentage(summaries *Summaries) float64

type StrategyInterfacer

type StrategyInterfacer struct {
	Sync *Synchronizer `inject:""`
}

func (*StrategyInterfacer) Compute

func (s *StrategyInterfacer) Compute(parameters StrategyParameter) (summaries *Summaries)

linterInterfacer is a function that scan the interface of all packages in the project helps you optimize the project architecture.It will extract from the linter need to convert the data.The result will be saved in the r's attributes.

func (*StrategyInterfacer) GetDescription

func (s *StrategyInterfacer) GetDescription() string

func (*StrategyInterfacer) GetName

func (s *StrategyInterfacer) GetName() string

func (*StrategyInterfacer) GetWeight

func (s *StrategyInterfacer) GetWeight() float64

func (*StrategyInterfacer) Percentage

func (s *StrategyInterfacer) Percentage(summaries *Summaries) float64

type StrategyLint

type StrategyLint struct {
	Sync *Synchronizer `inject:""`
}

func (*StrategyLint) Compute

func (s *StrategyLint) Compute(parameters StrategyParameter) (summaries *Summaries)

func (*StrategyLint) GetDescription

func (s *StrategyLint) GetDescription() string

func (*StrategyLint) GetName

func (s *StrategyLint) GetName() string

func (*StrategyLint) GetWeight

func (s *StrategyLint) GetWeight() float64

func (*StrategyLint) Percentage

func (s *StrategyLint) Percentage(summaries *Summaries) float64

type StrategyLinter

type StrategyLinter interface {
	Compute(parameters StrategyParameter) *Summaries
	Percentage(summaries *Summaries) float64
	GetName() string
	GetDescription() string
	GetWeight() float64
}

type StrategyParameter

type StrategyParameter struct {
	AllDirs, UnitTestDirs       map[string]string
	ProjectPath, ExceptPackages string
}

type StrategySimpleCode

type StrategySimpleCode struct {
	Sync *Synchronizer `inject:""`
}

func (*StrategySimpleCode) Compute

func (s *StrategySimpleCode) Compute(parameters StrategyParameter) (summaries *Summaries)

func (*StrategySimpleCode) GetDescription

func (s *StrategySimpleCode) GetDescription() string

func (*StrategySimpleCode) GetName

func (s *StrategySimpleCode) GetName() string

func (*StrategySimpleCode) GetWeight

func (s *StrategySimpleCode) GetWeight() float64

func (*StrategySimpleCode) Percentage

func (s *StrategySimpleCode) Percentage(summaries *Summaries) float64

type StrategySpellCheck

type StrategySpellCheck struct {
	Sync *Synchronizer `inject:""`
}

func (*StrategySpellCheck) Compute

func (s *StrategySpellCheck) Compute(parameters StrategyParameter) (summaries *Summaries)

func (*StrategySpellCheck) GetDescription

func (s *StrategySpellCheck) GetDescription() string

func (*StrategySpellCheck) GetName

func (s *StrategySpellCheck) GetName() string

func (*StrategySpellCheck) GetWeight

func (s *StrategySpellCheck) GetWeight() float64

func (*StrategySpellCheck) Percentage

func (s *StrategySpellCheck) Percentage(summaries *Summaries) float64

type StrategyUnitTest

type StrategyUnitTest struct {
	Sync *Synchronizer `inject:""`
	// contains filtered or unexported fields
}

func (*StrategyUnitTest) Compute

func (s *StrategyUnitTest) Compute(parameters StrategyParameter) (summaries *Summaries)

func (*StrategyUnitTest) GetDescription

func (s *StrategyUnitTest) GetDescription() string

func (*StrategyUnitTest) GetName

func (s *StrategyUnitTest) GetName() string

func (*StrategyUnitTest) GetWeight

func (s *StrategyUnitTest) GetWeight() float64

func (*StrategyUnitTest) Percentage

func (s *StrategyUnitTest) Percentage(summaries *Summaries) float64

type StyleItem

type StyleItem struct {
	Label  string `json:"label"`
	Score  int    `json:"score"`
	Detail []Item `json:"detail"`
	// contains filtered or unexported fields
}

CodeTest is a struct that contains Summary and Content. It represents the result data of the project unit test.

type Summaries

type Summaries struct {
	Summaries map[string]Summary
	sync.RWMutex
}

func NewSummaries

func NewSummaries() *Summaries

type Summary

type Summary struct {
	Name        string  `json:"name"`
	Description string  `json:"description"`
	Errors      []Error `json:"errors"`
	SumCover    float64
	CountCover  int
	Avg         float64
}

FileSummary contains the filename, location of the file on GitHub, and all of the errors related to the file

type Synchronizer

type Synchronizer struct {
	SyncRW                *sync.RWMutex     `inject:""`
	WaitGW                *WaitGroupWrapper `inject:""`
	LintersProcessChans   chan int64        `json:"-"`
	LintersFinishedSignal chan string       `json:"-"`
}

type Test

type Test struct {
	Path   string
	Result int
	Time   float64
	Cover  float64
}

Test is a struct that contains Path, Result, Time and Cover. The type of Time and Cover MUST float64. And it is just for one package's display.

type UnitTest

type UnitTest struct {
	AvgCover           string                 `json:"average_cover"`
	PackagesTestDetail map[string]PackageTest `json:"packages_test_detail"`
	PackagesRaceDetail map[string][]string    `json:"packages_race_detail"`
}

UnitTest is a struct that contains AvgCover, PackagesTestDetail and PackagesRaceDetail. The type of AvgCover MUST string that represents the code coverage of the entire project. The type of PackagesTestDetail MUST map[string]PackageTest(contains pass-status,code-coverage and time). and it has all packages' detail information. PackagesRaceDetail contains all packages' race cases.

And the UnitTest contains all packages' result.

type WaitGroupWrapper

type WaitGroupWrapper struct {
	sync.WaitGroup
}

WaitGroupWrapper is a struct that as a waiter for all linetr-tasks.And it encapsulates Sync.WaitGroup that can be call as a interface.

func (*WaitGroupWrapper) Wrap

func (w *WaitGroupWrapper) Wrap(cb func())

Wrap implements a interface that run the function cd as a goroutine.And it encapsulates Add(1) and Done() operation.You can just think go cd() but not worry about synchronization and security issues.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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