forked from qax-os/goreporter
/
strategy_spellcheck.go
69 lines (59 loc) · 1.9 KB
/
strategy_spellcheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package engine
import (
"strconv"
"strings"
"github.com/360EntSecGroup-Skylar/goreporter/linters/spellcheck"
"github.com/360EntSecGroup-Skylar/goreporter/utils"
)
type StrategySpellCheck struct {
Sync *Synchronizer `inject:""`
}
func (s *StrategySpellCheck) GetName() string {
return "SpellCheck"
}
func (s *StrategySpellCheck) GetDescription() string {
return "Check the project variables, functions, etc. naming spelling is wrong."
}
func (s *StrategySpellCheck) GetWeight() float64 {
return 0.05
}
func (s *StrategySpellCheck) Compute(parameters StrategyParameter) (summaries Summaries) {
summaries = NewSummaries()
spelltips := spellcheck.SpellCheck(parameters.ProjectPath, parameters.ExceptPackages)
sumProcessNumber := int64(10)
processUnit := utils.GetProcessUnit(sumProcessNumber, len(spelltips))
for _, simpleTip := range spelltips {
simpleTips := strings.Split(simpleTip, ":")
if len(simpleTips) == 4 {
packageName := utils.PackageNameFromGoPath(simpleTips[0])
line, _ := strconv.Atoi(simpleTips[1])
erroru := Error{
LineNumber: line,
ErrorString: utils.AbsPath(simpleTips[0]) + ":" + strings.Join(simpleTips[1:], ":"),
}
summaries.Lock()
if summarie, ok := summaries.Summaries[packageName]; ok {
summarie.Errors = append(summarie.Errors, erroru)
summaries.Summaries[packageName] = summarie
} else {
summarie := Summary{
Name: utils.PackageAbsPathExceptSuffix(simpleTips[0]),
Errors: make([]Error, 0),
}
summarie.Errors = append(summarie.Errors, erroru)
summaries.Summaries[packageName] = summarie
}
summaries.Unlock()
}
if sumProcessNumber > 0 {
s.Sync.LintersProcessChans <- processUnit
sumProcessNumber = sumProcessNumber - processUnit
}
}
return
}
func (s *StrategySpellCheck) Percentage(summaries Summaries) float64 {
summaries.RLock()
defer summaries.RUnlock()
return utils.CountPercentage(len(summaries.Summaries))
}