engine

package
v0.0.0-...-261465a Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2017 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func AbsPath

func AbsPath(path string) string

AbsPath is a function that will get absolute path of file.

func CountPercentage

func CountPercentage(issues int) float64

CountPercentage will count all linters' percentage.And rule is

+--------------------------------------------------+
|   issues    |               score                |
+==================================================+
| 5           | 100-issues*2                       |
+--------------------------------------------------+
| [5,10)      | 100 - 10 - (issues-5)*4            |
+--------------------------------------------------+
| [10,20)     | 100 - 10 - 20 - (issues-10)*5      |
+--------------------------------------------------+
| [20,40)     | 100 - 10 - 20 - 50 - (issues-20)*1 |
+--------------------------------------------------+
| [40,*)      | 0                                  |
+--------------------------------------------------+

It will return a float64 type score.

func DirList

func DirList(projectPath string, suffix, except string) (dirs map[string]string, err error)

DirList is a function that traverse the file directory containing the specified file format according to the specified rule.

func ExceptPkg

func ExceptPkg(pkg string) bool

ExceptPkg is a function that will determine whether the package is an exception.

func GetProcessUnit

func GetProcessUnit(sumProcessNumber int64, number int) int64

GetProcessUnit provides function that will get sumProcessNumber of linter's weight and the number of current linter's case.It will return 1 if sumProcessNumber/int64(number) <= 0 or sumProcessNumber / int64(number). Just for communication.

func PackageAbsPath

func PackageAbsPath(path string) (packagePath string)

PackageAbsPath will gets the absolute path of the specified package from GOPATH's [src].

func PackageAbsPathExceptSuffix

func PackageAbsPathExceptSuffix(path string) (packagePath string)

PackageAbsPath will gets the absolute directory path of the specified file from GOPATH's [src].

func PackageNameFromGoPath

func PackageNameFromGoPath(path string) string

PackageNameFromGoPath is a function that will get package's name from GOPATH.

func ProjectName

func ProjectName(projectPath string) (project string)

ProjectName is a function that gets project's name.

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 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
	Tests               string
	Date                string
	Issues              int
	FileCount           int
	CodeLines           int
	CommentLines        int
	TotalLines          int
	TestSummaryCoverAvg string
	AveragePackageCover float64
	SimpleIssues        int
	DeadcodeIssues      int
	CycloBigThan15      int
	DepthBigThan3       int
	Races               []Race
	NoTests             string
	Simples             string
	Interfacers         string
	Spells              string
	SimpleLevel         int
	Deadcodes           string
	Copycodes           string
	Cyclos              string
	Depths              string
	DepGraph            template.HTML

	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              |
+-----------------------+----------------------------------------------+
| Tests                 | Unit test results                            |
+-----------------------+----------------------------------------------+
| Date                  | Date assessment of the project               |
+-----------------------+----------------------------------------------+
| Issues                | Issues number of the project                 |
+-----------------------+----------------------------------------------+
| FileCount             | Go file number of the peoject                |
+-----------------------+----------------------------------------------+
| CodeLines             | Number of lines of code                      |
+-----------------------+----------------------------------------------+
| CommentLines          | Number of lines of Comment                   |
+-----------------------+----------------------------------------------+
| TestSummaryCoverAvg   | Code cover average of all unit test          |
+-----------------------+----------------------------------------------+
| AveragePackageCover   | Package cover average of all packages        |
+-----------------------+----------------------------------------------+
| SimpleIssues          | Simpled issues number                        |
+-----------------------+----------------------------------------------+
| DeadcodeIssues        | Dead code issues number                      |
+-----------------------+----------------------------------------------+
| CycloBigThan15        | Cyclo more than 15 number                    |
+-----------------------+----------------------------------------------+
| Races                 | Race result of all packages                  |
+-----------------------+----------------------------------------------+
| NoTests               | No unit test packages information            |
+-----------------------+----------------------------------------------+
| Simples               | Simpled cases of all packages information    |
+-----------------------+----------------------------------------------+
| Interfacers           | Warns about types specific  necessary        |
+-----------------------+----------------------------------------------+
| SimpleLevel           | Simple level of path                         |
+-----------------------+----------------------------------------------+
| Deadcodes             | Dead code cases information                  |
+-----------------------+----------------------------------------------+
| Copycodes             | Copy code cases information                  |
+-----------------------+----------------------------------------------+
| Cyclos                | Cyclo of function cases information           |
+-----------------------+----------------------------------------------+
| DepGraph              | Depend graph of all packages in 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 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 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 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 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