@@ -18,14 +18,14 @@ import (
18
18
// by Rytia <admin@zzfly.net>, 2021-07-17 周六
19
19
20
20
var (
21
- wg sync.WaitGroup
22
- result sync.Map
23
- totalFile uint32
24
- errFile uint32
21
+ processLintWg sync.WaitGroup
22
+ lintErrResult sync.Map
23
+ totalFileCounter uint32
24
+ errFileCounter uint32
25
25
)
26
26
27
27
// PHP 可执行文件路径
28
- var phpExecutor string = "php"
28
+ var phpExecutor = "php"
29
29
30
30
// 控制最大运行协程个数
31
31
var ch = make (chan bool , 8 )
@@ -63,10 +63,10 @@ func main() {
63
63
}
64
64
}
65
65
66
- wg .Wait ()
66
+ processLintWg .Wait ()
67
67
printResult ()
68
68
69
- if errFile > 0 {
69
+ if errFileCounter > 0 {
70
70
os .Exit (StatusCoedFilesError )
71
71
}
72
72
os .Exit (0 )
@@ -88,13 +88,13 @@ func printWelcome() {
88
88
func printResult () {
89
89
fmt .Println ("\n ---------------------------" )
90
90
fmt .Println ("Result:" )
91
- fmt .Printf ("Check: %d / Errors: %d \n " , totalFile , errFile )
91
+ fmt .Printf ("Check: %d / Errors: %d \n " , totalFileCounter , errFileCounter )
92
92
93
- if errFile > 0 {
94
- result .Range (processResultPrint )
93
+ if errFileCounter > 0 {
94
+ lintErrResult .Range (processResultPrint )
95
95
}
96
96
97
- fmt .Println (" \n " )
97
+ fmt .Println ()
98
98
}
99
99
100
100
// 获取执行目录下的文件,执行检测
@@ -111,7 +111,7 @@ func lintPath(path string, recursive bool) {
111
111
if recursive && file .IsDir () {
112
112
lintPath (path + "/" + file .Name (), recursive )
113
113
} else if strings .Contains (file .Name (), ".php" ) {
114
- wg .Add (1 )
114
+ processLintWg .Add (1 )
115
115
go processPhpLint (path , file .Name ())
116
116
}
117
117
}
@@ -142,7 +142,7 @@ func lintGit() {
142
142
for _ , file := range gitDiffFiles {
143
143
// 防止空串影响
144
144
if len (file ) != 0 {
145
- wg .Add (1 )
145
+ processLintWg .Add (1 )
146
146
go processPhpLint (gitRootPath , file )
147
147
}
148
148
}
@@ -169,15 +169,15 @@ func lintSvn() {
169
169
for _ , file := range svnDiffFiles {
170
170
// 防止空串影响
171
171
if len (file ) != 0 {
172
- wg .Add (1 )
172
+ processLintWg .Add (1 )
173
173
go processPhpLint (svnPath , file )
174
174
}
175
175
}
176
176
}
177
177
178
178
// 处理 PHP 语法检测
179
179
func processPhpLint (path string , file string ) {
180
- defer wg .Done ()
180
+ defer processLintWg .Done ()
181
181
182
182
// 控制最大协程数
183
183
ch <- true
@@ -193,13 +193,13 @@ func processPhpLint(path string, file string) {
193
193
194
194
if err != nil {
195
195
fmt .Println (color .HiRedString ("[ERR]" ), file , err .Error ())
196
- result .Store (path + "/" + file , string ( stdout ) )
197
- atomic .AddUint32 (& errFile , 1 )
196
+ lintErrResult .Store (path + "/" + file , stdout )
197
+ atomic .AddUint32 (& errFileCounter , 1 )
198
198
} else {
199
199
fmt .Println (color .HiGreenString ("[OK] " ), file )
200
200
}
201
201
202
- atomic .AddUint32 (& totalFile , 1 )
202
+ atomic .AddUint32 (& totalFileCounter , 1 )
203
203
204
204
<- ch
205
205
}
0 commit comments