github.com/serversong/goreporter@v0.0.0-20200325104552-3cfaf44fd178/engine/strategy_importpackages.go (about)

     1  package engine
     2  
     3  import (
     4  	"github.com/360EntSecGroup-Skylar/goreporter/linters/unittest"
     5  	"github.com/360EntSecGroup-Skylar/goreporter/utils"
     6  )
     7  
     8  type StrategyImportPackages struct {
     9  	Sync *Synchronizer `inject:""`
    10  }
    11  
    12  func (s *StrategyImportPackages) GetName() string {
    13  	return "ImportPackages"
    14  }
    15  
    16  func (s *StrategyImportPackages) GetDescription() string {
    17  	return "Check the project variables, functions, etc. naming spelling is wrong."
    18  }
    19  
    20  func (s *StrategyImportPackages) GetWeight() float64 {
    21  	return 0.
    22  }
    23  
    24  // linterImportPackages is a function that scan the project contains all the
    25  // package lists.It will extract from the linter need to convert
    26  // the data.The result will be saved in the r's attributes.
    27  func (s *StrategyImportPackages) Compute(parameters StrategyParameter) (summaries *Summaries) {
    28  	summaries = NewSummaries()
    29  
    30  	importPkgs := unittest.GoListWithImportPackages(parameters.ProjectPath)
    31  	for i := 0; i < len(importPkgs); i++ {
    32  		summaries.Lock()
    33  		summaries.Summaries[importPkgs[i]] = Summary{Name: importPkgs[i]}
    34  		summaries.Unlock()
    35  	}
    36  	return
    37  }
    38  
    39  func (s *StrategyImportPackages) Percentage(summaries *Summaries) float64 {
    40  	summaries.RLock()
    41  	defer summaries.RUnlock()
    42  	return utils.CountPercentage(len(summaries.Summaries))
    43  }