@@ -2,7 +2,6 @@ package bench
22
33import (
44 "bytes"
5- "context"
65 "errors"
76 "fmt"
87 "go/build"
@@ -36,15 +35,6 @@ type metrics struct {
3635}
3736
3837func Benchmark_linters (b * testing.B ) {
39- savedWD , err := os .Getwd ()
40- require .NoError (b , err )
41-
42- b .Cleanup (func () {
43- // Restore WD to avoid side effects when during all the benchmarks.
44- err = os .Chdir (savedWD )
45- require .NoError (b , err )
46- })
47-
4838 installGolangCILint (b )
4939
5040 repos := getAllRepositories (b )
@@ -64,11 +54,9 @@ func Benchmark_linters(b *testing.B) {
6454
6555 for _ , repo := range repos {
6656 b .Run (repo .name , func (b * testing.B ) {
67- // TODO(ldez): clean inside go1.25 PR
68- _ = exec .CommandContext (context .Background (), binName , "cache" , "clean" ).Run ()
57+ _ = exec .CommandContext (b .Context (), binName , "cache" , "clean" ).Run ()
6958
70- err = os .Chdir (repo .dir )
71- require .NoErrorf (b , err , "can't chdir to %s" , repo .dir )
59+ b .Chdir (repo .dir )
7260
7361 lc := countGoLines (b )
7462
@@ -85,19 +73,9 @@ func Benchmark_linters(b *testing.B) {
8573}
8674
8775func Benchmark_golangciLint (b * testing.B ) {
88- savedWD , err := os .Getwd ()
89- require .NoError (b , err )
90-
91- b .Cleanup (func () {
92- // Restore WD to avoid side effects when during all the benchmarks.
93- err = os .Chdir (savedWD )
94- require .NoError (b , err )
95- })
96-
9776 installGolangCILint (b )
9877
99- // TODO(ldez): clean inside go1.25 PR
100- _ = exec .CommandContext (context .Background (), binName , "cache" , "clean" ).Run ()
78+ _ = exec .CommandContext (b .Context (), binName , "cache" , "clean" ).Run ()
10179
10280 cases := getAllRepositories (b )
10381
@@ -117,8 +95,7 @@ func Benchmark_golangciLint(b *testing.B) {
11795
11896 for _ , c := range cases {
11997 b .Run (c .name , func (b * testing.B ) {
120- err = os .Chdir (c .dir )
121- require .NoErrorf (b , err , "can't chdir to %s" , c .dir )
98+ b .Chdir (c .dir )
12299
123100 lc := countGoLines (b )
124101
@@ -145,26 +122,26 @@ func getAllRepositories(tb testing.TB) []repo {
145122 name : "golangci/golangci-lint" ,
146123 dir : cloneGithubProject (tb , benchRoot , "golangci" , "golangci-lint" ),
147124 },
148- {
149- name : "goreleaser/goreleaser" ,
150- dir : cloneGithubProject (tb , benchRoot , "goreleaser" , "goreleaser" ),
151- },
152- {
153- name : "gohugoio/hugo" ,
154- dir : cloneGithubProject (tb , benchRoot , "gohugoio" , "hugo" ),
155- },
156- {
157- name : "pact-foundation/pact-go" , // CGO inside
158- dir : cloneGithubProject (tb , benchRoot , "pact-foundation" , "pact-go" ),
159- },
160- {
161- name : "kubernetes/kubernetes" ,
162- dir : cloneGithubProject (tb , benchRoot , "kubernetes" , "kubernetes" ),
163- },
164- {
165- name : "moby/buildkit" ,
166- dir : cloneGithubProject (tb , benchRoot , "moby" , "buildkit" ),
167- },
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+ // },
168145 {
169146 name : "go source code" ,
170147 dir : filepath .Join (build .Default .GOROOT , "src" ),
@@ -180,8 +157,7 @@ func cloneGithubProject(tb testing.TB, benchRoot, owner, name string) string {
180157 if _ , err := os .Stat (dir ); os .IsNotExist (err ) {
181158 repo := fmt .Sprintf ("https://github.com/%s/%s.git" , owner , name )
182159
183- // TODO(ldez): clean inside go1.25 PR
184- err = exec .CommandContext (context .Background (), "git" , "clone" , "--depth" , "1" , "--single-branch" , repo , dir ).Run ()
160+ err = exec .CommandContext (tb .Context (), "git" , "clone" , "--depth" , "1" , "--single-branch" , repo , dir ).Run ()
185161 if err != nil {
186162 tb .Fatalf ("can't git clone %s/%s: %s" , owner , name , err )
187163 }
@@ -214,8 +190,7 @@ func launch(tb testing.TB, run func(testing.TB, string, []string), args []string
214190func run (tb testing.TB , name string , args []string ) {
215191 tb .Helper ()
216192
217- // TODO(ldez): clean inside go1.25 PR
218- cmd := exec .CommandContext (context .Background (), name , args ... )
193+ cmd := exec .CommandContext (tb .Context (), name , args ... )
219194 if os .Getenv ("PRINT_CMD" ) == "1" {
220195 log .Print (strings .Join (cmd .Args , " " ))
221196 }
@@ -233,18 +208,17 @@ func run(tb testing.TB, name string, args []string) {
233208func countGoLines (tb testing.TB ) int {
234209 tb .Helper ()
235210
236- // TODO(ldez): clean inside go1.25 PR
237- cmd := exec .CommandContext (context .Background (), "bash" , "-c" , `find . -type f -name "*.go" | grep -F -v vendor | xargs wc -l | tail -1` )
211+ cmd := exec .CommandContext (tb .Context (), "bash" , "-c" , `find . -type f -name "*.go" | grep -F -v vendor | xargs wc -l | tail -1` )
238212
239213 out , err := cmd .CombinedOutput ()
240214 if err != nil {
241215 tb .Log (string (out ))
242216 tb .Fatalf ("can't run go lines counter: %s" , err )
243217 }
244218
245- parts := bytes .Split (bytes .TrimSpace (out ), []byte (" " ))
219+ lineCount , _ , _ := bytes .Cut (bytes .TrimSpace (out ), []byte (" " ))
246220
247- n , err := strconv .Atoi (string (parts [ 0 ] ))
221+ n , err := strconv .Atoi (string (lineCount ))
248222 if err != nil {
249223 tb .Log (string (out ))
250224 tb .Fatalf ("can't parse go lines count: %s" , err )
@@ -347,8 +321,7 @@ func installGolangCILint(tb testing.TB) {
347321
348322 parentPath := findMakefile (tb )
349323
350- // TODO(ldez): clean inside go1.25 PR
351- cmd := exec .CommandContext (context .Background (), "make" , "-C" , parentPath , "build" )
324+ cmd := exec .CommandContext (tb .Context (), "make" , "-C" , parentPath , "build" )
352325
353326 output , err := cmd .CombinedOutput ()
354327 if err != nil {
@@ -399,7 +372,14 @@ func getLinterNames(tb testing.TB, fastOnly bool) []string {
399372 tb .Helper ()
400373
401374 // add linter names here if needed.
402- 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+ }
403383
404384 linters , err := lintersdb .NewLinterBuilder ().Build (config .NewDefault ())
405385 require .NoError (tb , err )
@@ -410,6 +390,10 @@ func getLinterNames(tb testing.TB, fastOnly bool) []string {
410390 continue
411391 }
412392
393+ if lc .Internal {
394+ continue
395+ }
396+
413397 if fastOnly && lc .IsSlowLinter () {
414398 continue
415399 }
0 commit comments