@@ -35,15 +35,6 @@ type metrics struct {
3535}
3636
3737func Benchmark_linters (b * testing.B ) {
38- savedWD , err := os .Getwd ()
39- require .NoError (b , err )
40-
41- b .Cleanup (func () {
42- // Restore WD to avoid side effects when during all the benchmarks.
43- err = os .Chdir (savedWD )
44- require .NoError (b , err )
45- })
46-
4738 installGolangCILint (b )
4839
4940 repos := getAllRepositories (b )
@@ -65,8 +56,7 @@ func Benchmark_linters(b *testing.B) {
6556 b .Run (repo .name , func (b * testing.B ) {
6657 _ = exec .Command (binName , "cache" , "clean" ).Run ()
6758
68- err = os .Chdir (repo .dir )
69- require .NoErrorf (b , err , "can't chdir to %s" , repo .dir )
59+ b .Chdir (repo .dir )
7060
7161 lc := countGoLines (b )
7262
@@ -83,15 +73,6 @@ func Benchmark_linters(b *testing.B) {
8373}
8474
8575func Benchmark_golangciLint (b * testing.B ) {
86- savedWD , err := os .Getwd ()
87- require .NoError (b , err )
88-
89- b .Cleanup (func () {
90- // Restore WD to avoid side effects when during all the benchmarks.
91- err = os .Chdir (savedWD )
92- require .NoError (b , err )
93- })
94-
9576 installGolangCILint (b )
9677
9778 _ = exec .Command (binName , "cache" , "clean" ).Run ()
@@ -114,8 +95,7 @@ func Benchmark_golangciLint(b *testing.B) {
11495
11596 for _ , c := range cases {
11697 b .Run (c .name , func (b * testing.B ) {
117- err = os .Chdir (c .dir )
118- require .NoErrorf (b , err , "can't chdir to %s" , c .dir )
98+ b .Chdir (c .dir )
11999
120100 lc := countGoLines (b )
121101
@@ -142,26 +122,26 @@ func getAllRepositories(tb testing.TB) []repo {
142122 name : "golangci/golangci-lint" ,
143123 dir : cloneGithubProject (tb , benchRoot , "golangci" , "golangci-lint" ),
144124 },
145- {
146- name : "goreleaser/goreleaser" ,
147- dir : cloneGithubProject (tb , benchRoot , "goreleaser" , "goreleaser" ),
148- },
149- {
150- name : "gohugoio/hugo" ,
151- dir : cloneGithubProject (tb , benchRoot , "gohugoio" , "hugo" ),
152- },
153- {
154- name : "pact-foundation/pact-go" , // CGO inside
155- dir : cloneGithubProject (tb , benchRoot , "pact-foundation" , "pact-go" ),
156- },
157- {
158- name : "kubernetes/kubernetes" ,
159- dir : cloneGithubProject (tb , benchRoot , "kubernetes" , "kubernetes" ),
160- },
161- {
162- name : "moby/buildkit" ,
163- dir : cloneGithubProject (tb , benchRoot , "moby" , "buildkit" ),
164- },
125+ // {
126+ // name: "goreleaser/goreleaser",
127+ // dir: cloneGithubProject(tb, benchRoot, "goreleaser", "goreleaser"),
128+ // },
129+ // {
130+ // name: "gohugoio/hugo",
131+ // dir: cloneGithubProject(tb, benchRoot, "gohugoio", "hugo"),
132+ // },
133+ // {
134+ // name: "pact-foundation/pact-go", // CGO inside
135+ // dir: cloneGithubProject(tb, benchRoot, "pact-foundation", "pact-go"),
136+ // },
137+ // {
138+ // name: "kubernetes/kubernetes",
139+ // dir: cloneGithubProject(tb, benchRoot, "kubernetes", "kubernetes"),
140+ // },
141+ // {
142+ // name: "moby/buildkit",
143+ // dir: cloneGithubProject(tb, benchRoot, "moby", "buildkit"),
144+ // },
165145 {
166146 name : "go source code" ,
167147 dir : filepath .Join (build .Default .GOROOT , "src" ),
@@ -236,9 +216,9 @@ func countGoLines(tb testing.TB) int {
236216 tb .Fatalf ("can't run go lines counter: %s" , err )
237217 }
238218
239- parts := bytes .Split (bytes .TrimSpace (out ), []byte (" " ))
219+ lineCount , _ , _ := bytes .Cut (bytes .TrimSpace (out ), []byte (" " ))
240220
241- n , err := strconv .Atoi (string (parts [ 0 ] ))
221+ n , err := strconv .Atoi (string (lineCount ))
242222 if err != nil {
243223 tb .Log (string (out ))
244224 tb .Fatalf ("can't parse go lines count: %s" , err )
@@ -392,7 +372,14 @@ func getLinterNames(tb testing.TB, fastOnly bool) []string {
392372 tb .Helper ()
393373
394374 // add linter names here if needed.
395- var excluded []string
375+ excluded := []string {
376+ "gci" , // Formatter
377+ "gofmt" , // Formatter
378+ "gofumpt" , // Formatter
379+ "goimports" , // Formatter
380+ "golines" , // Formatter
381+ "swaggo" , // Formatter
382+ }
396383
397384 linters , err := lintersdb .NewLinterBuilder ().Build (config .NewDefault ())
398385 require .NoError (tb , err )
@@ -403,6 +390,10 @@ func getLinterNames(tb testing.TB, fastOnly bool) []string {
403390 continue
404391 }
405392
393+ if lc .Internal {
394+ continue
395+ }
396+
406397 if fastOnly && lc .IsSlowLinter () {
407398 continue
408399 }
0 commit comments