Skip to content

Commit eb904ec

Browse files
mpywclaude
andauthored
fix: Remove custom -test flag that conflicted with driver's built-in flag (#4)
The custom `-test` flag for skipping test files conflicted with singlechecker's built-in `-test` flag (registered by checker.RegisterFlags()). This caused the flag to be silently ignored when running the linter directly. The driver's built-in `-test` flag provides the same functionality, so we remove the redundant custom implementation and delegate to it. Changes: - Remove `analyzeTests` variable and flag registration in `init()` - Remove test file skipping logic from `buildSkipFiles()` - Remove `TestFileFilterSkipTests` test and rename `TestFileFilterDefault` to `TestFileFilter` - Remove `filefilterskip` testdata fixtures - Update README to remove go vet usage and clarify -test flag is built-in - Retract v0.1.0-v0.4.0 due to broken -test flag 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent eb1eb1c commit eb904ec

File tree

7 files changed

+9
-106
lines changed

7 files changed

+9
-106
lines changed

README.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ A Go linter that checks goroutine context propagation.
1616

1717
## Installation & Usage
1818

19-
### Using [`go vet`](https://pkg.go.dev/cmd/go#hdr-Report_likely_mistakes_in_packages) (Recommended)
20-
21-
```bash
22-
# Install the analyzer
23-
go install github.com/mpyw/goroutinectx/cmd/goroutinectx@latest
24-
25-
# Run with go vet
26-
go vet -vettool=$(which goroutinectx) ./...
27-
```
28-
2919
### Using [`go tool`](https://pkg.go.dev/cmd/go#hdr-Run_specified_go_tool) (Go 1.24+)
3020

3121
```bash
@@ -267,12 +257,6 @@ This is useful for wrapper functions that abstract away goroutine spawning patte
267257

268258
## Flags
269259

270-
> [!TIP]
271-
> When using `go vet -vettool`, pass flags directly:
272-
> ```bash
273-
> go vet -vettool=$(which goroutinectx) -goroutine-deriver='pkg.Func' ./...
274-
> ```
275-
276260
### `-goroutine-deriver`
277261

278262
Require goroutines to call a specific function to derive context. Useful for APM libraries like New Relic.
@@ -368,16 +352,13 @@ Available flags:
368352

369353
| Flag | Default | Description |
370354
|------|---------|-------------|
371-
| `-test` | `true` | Analyze test files (`*_test.go`) |
355+
| `-test` | `true` | Analyze test files (`*_test.go`) — built-in driver flag |
372356

373357
Generated files (containing `// Code generated ... DO NOT EDIT.`) are always excluded and cannot be opted in.
374358

375359
```bash
376360
# Exclude test files from analysis
377361
goroutinectx -test=false ./...
378-
379-
# With go vet
380-
go vet -vettool=$(which goroutinectx) -goroutinectx.test=false ./...
381362
```
382363

383364
### `-spawnerlabel`

analyzer.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ var (
3939
enableSpawner bool
4040
enableSpawnerlabel bool
4141
enableGotask bool
42-
43-
// File filtering flags.
44-
analyzeTests bool
4542
)
4643

4744
func init() {
@@ -59,9 +56,6 @@ func init() {
5956
Analyzer.Flags.BoolVar(&enableSpawner, "spawner", true, "enable spawner checker")
6057
Analyzer.Flags.BoolVar(&enableSpawnerlabel, "spawnerlabel", false, "enable spawnerlabel checker")
6158
Analyzer.Flags.BoolVar(&enableGotask, "gotask", true, "enable gotask checker (requires -goroutine-deriver)")
62-
63-
// File filtering flags
64-
Analyzer.Flags.BoolVar(&analyzeTests, "test", true, "analyze test files (*_test.go)")
6559
}
6660

6761
// Analyzer is the main analyzer for goroutinectx.
@@ -111,9 +105,9 @@ func run(pass *analysis.Pass) (any, error) {
111105
return nil, nil
112106
}
113107

114-
// buildSkipFiles creates a set of filenames to skip based on flags.
108+
// buildSkipFiles creates a set of filenames to skip.
115109
// Generated files are always skipped.
116-
// Test files are skipped when analyzeTests is false.
110+
// Test files can be skipped via the driver's built-in -test flag.
117111
func buildSkipFiles(pass *analysis.Pass) map[string]bool {
118112
skipFiles := make(map[string]bool)
119113

@@ -123,12 +117,6 @@ func buildSkipFiles(pass *analysis.Pass) map[string]bool {
123117
// Always skip generated files
124118
if ast.IsGenerated(file) {
125119
skipFiles[filename] = true
126-
continue
127-
}
128-
129-
// Skip test files if -test=false
130-
if !analyzeTests && strings.HasSuffix(filename, "_test.go") {
131-
skipFiles[filename] = true
132120
}
133121
}
134122

analyzer_test.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,8 @@ func TestGotask(t *testing.T) {
132132
analysistest.Run(t, testdata, goroutinectx.Analyzer, "gotask")
133133
}
134134

135-
func TestFileFilterDefault(t *testing.T) {
135+
func TestFileFilter(t *testing.T) {
136136
testdata := analysistest.TestData()
137-
// Default: -test=true, so test files are analyzed
137+
// Tests that generated files are skipped
138138
analysistest.Run(t, testdata, goroutinectx.Analyzer, "filefilter")
139139
}
140-
141-
func TestFileFilterSkipTests(t *testing.T) {
142-
testdata := analysistest.TestData()
143-
144-
// Set -test=false to skip test files
145-
if err := goroutinectx.Analyzer.Flags.Set("test", "false"); err != nil {
146-
t.Fatal(err)
147-
}
148-
149-
defer func() {
150-
_ = goroutinectx.Analyzer.Flags.Set("test", "true")
151-
}()
152-
153-
analysistest.Run(t, testdata, goroutinectx.Analyzer, "filefilterskip")
154-
}

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ module github.com/mpyw/goroutinectx
22

33
go 1.24.0
44

5-
// Retract all previous versions due to a bug where -goroutine-deriver flag
6-
// incorrectly disabled the base goroutine checker instead of running both independently.
7-
retract [v0.1.0, v0.2.0]
5+
// Retract all previous versions due to:
6+
// - v0.1.0-v0.2.0: -goroutine-deriver flag incorrectly disabled the base goroutine checker
7+
// - v0.1.0-v0.4.0: -test flag conflicted with singlechecker's built-in flag
8+
retract [v0.1.0, v0.4.0]
89

910
require golang.org/x/tools v0.40.0
1011

testdata/src/filefilterskip/code_test.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

testdata/src/filefilterskip/generated.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

testdata/src/filefilterskip/main.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)