Skip to content

Commit ab547c3

Browse files
authored
fix: make lint pass clean(er) (#4390)
1 parent e1c020b commit ab547c3

File tree

334 files changed

+681
-359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

334 files changed

+681
-359
lines changed

.github/pull_request_template.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
- [ ] [System-Tests](https://github.com/DataDog/system-tests/) covering this feature have been added and enabled with the va.b.c-dev version tag.
3131
- [ ] There is a benchmark for any new code, or changes to existing code.
3232
- [ ] If this interacts with the agent in a new way, a system test has been added.
33-
- [ ] New code is free of linting errors. You can check this by running `./scripts/lint.sh` locally.
33+
- [ ] New code is free of linting errors. You can check this by running `make lint` locally.
34+
- [ ] New code doesn't break existing tests. You can check this by running `make test` locally.
3435
- [ ] Add an appropriate team label so this PR gets put in the right place for the release notes.
35-
- [ ] Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.
36+
- [ ] All generated files are up to date. You can check this by running `make generate` locally.
37+
- [ ] Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild. Make sure all nested modules are up to date by running `make fix-modules` locally.
3638

3739
Unsure? Have a question? Request a review!

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,14 @@ linters:
117117
formatters:
118118
enable:
119119
- gofmt
120+
- goimports
120121
exclusions:
121122
generated: lax
122123
paths:
123124
- third_party$
124125
- builtin$
125126
- examples$
127+
settings:
128+
goimports:
129+
local-prefixes:
130+
- github.com/DataDog/dd-trace-go/v2

CONTRIBUTING.md

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Our CI pipeline includes several automated checks:
5555

5656
- **Copyright Check**: Verifies all files have proper copyright headers
5757
- **Generate Check**: Ensures generated code is up-to-date
58-
- **Module Check**: Validates Go module consistency using `./scripts/fix_modules.sh`
58+
- **Module Check**: Validates Go module consistency using `make fix-modules`
5959
- **Lint Check**: Runs comprehensive linting using `golangci-lint`
6060
- **Lock Analysis**: Runs `checklocks` to detect potential deadlocks and race conditions
6161

@@ -87,6 +87,9 @@ Before submitting a PR, you can run the same checks locally using make targets:
8787
# Show all available targets
8888
make help
8989

90+
# Install tools
91+
make tools-install
92+
9093
# Run all linters (same as CI)
9194
make lint
9295

@@ -107,15 +110,15 @@ You can also run scripts directly for more control:
107110

108111
```shell
109112
# Run specific linting options
110-
./scripts/lint.sh --all
113+
make lint
111114

112115
# Format specific file types
113-
./scripts/format.sh --go
114-
./scripts/format.sh --shell
116+
make format/go
117+
make format/shell
115118

116119
# Run specific test configurations
117-
./scripts/test.sh --contrib
118-
./scripts/test.sh --appsec
120+
make test/contrib
121+
make test/appsec
119122
```
120123

121124
## Getting a PR Reviewed
@@ -130,19 +133,13 @@ We provide several utility scripts in the `scripts/` directory to help with comm
130133

131134
### Code Quality Scripts
132135

133-
#### `./scripts/lint.sh`
136+
#### `make lint`
134137

135138
Runs all linters on the codebase to ensure code quality and consistency.
136139

137140
```shell
138-
# Run all linters (default behavior)
139-
./scripts/lint.sh
140-
141-
# Install linting tools only
142-
./scripts/lint.sh --tools
143-
144-
# Run all linters and install tools
145-
./scripts/lint.sh --all
141+
# Run all linters (default behavior, install tools)
142+
make lint
146143
```
147144

148145
The script runs:
@@ -151,25 +148,19 @@ The script runs:
151148
- `golangci-lint` for comprehensive Go linting
152149
- `checklocks` for lock analysis (with error tolerance)
153150

154-
#### `./scripts/format.sh`
151+
#### `make format`
155152

156153
Formats Go and shell files in the repository.
157154

158155
```shell
159-
# Format Go files only (default behavior)
160-
./scripts/format.sh
156+
# Format both Go and shell files and install tools (default behavior)
157+
make format
161158

162159
# Format Go files and install tools
163-
./scripts/format.sh --go
160+
make format/go
164161

165162
# Format shell files and install tools
166-
./scripts/format.sh --shell
167-
168-
# Format both Go and shell files and install tools
169-
./scripts/format.sh --all
170-
171-
# Install formatting tools only
172-
./scripts/format.sh --tools
163+
make format/shell
173164
```
174165

175166
#### `./scripts/checklocks.sh`
@@ -189,12 +180,12 @@ Analyzes lock usage patterns to detect potential deadlocks and race conditions.
189180

190181
### Module Management Scripts
191182

192-
#### `./scripts/fix_modules.sh`
183+
#### `make fix-modules`
193184

194185
Maintains Go module consistency across the repository by running `go mod tidy` on all modules and adding missing replace directives for local imports.
195186

196187
```shell
197-
./scripts/fix_modules.sh
188+
make fix-modules
198189
```
199190

200191
This script:
@@ -205,34 +196,25 @@ This script:
205196

206197
### Testing Scripts
207198

208-
#### `./scripts/test.sh`
199+
#### `make test`
209200

210201
Enhanced testing script with improved output formatting and additional options.
211202

212203
```shell
213204
# Run core tests only
214-
./scripts/test.sh
205+
make test/unit
215206

216207
# Run integration tests
217-
./scripts/test.sh --integration
208+
make test/integration
218209

219210
# Run contrib tests
220-
./scripts/test.sh --contrib
211+
make test/contrib
221212

222213
# Run all tests
223-
./scripts/test.sh --all
214+
make test
224215

225216
# Run with AppSec enabled
226-
./scripts/test.sh --appsec
227-
228-
# Install test tools
229-
./scripts/test.sh --tools
230-
231-
# Run specific test with race detection
232-
./scripts/test.sh --race
233-
234-
# Run with custom sleep time for service startup
235-
./scripts/test.sh --sleep 30
217+
make test/appsec
236218
```
237219

238220
The script provides:
@@ -269,13 +251,13 @@ For more specific control, you can use scripts directly:
269251

270252
```shell
271253
# Run specific linting configurations
272-
./scripts/lint.sh --tools
254+
make lint --tools
273255

274256
# Format only specific file types
275-
./scripts/format.sh --go
257+
make format/go
276258

277259
# Run specific test types
278-
./scripts/test.sh --contrib
260+
make test/contrib
279261
```
280262

281263
### Docker Alternative

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ test: tools-install test/unit ## Run all tests (core, integration, contrib)
9595
test/unit: tools-install ## Run unit tests
9696
go test -v -failfast ./...
9797

98-
.PHONY: test-appsec
98+
.PHONY: test/appsec
9999
test/appsec: tools-install ## Run tests with AppSec enabled
100100
$(BIN_PATH) ./scripts/test.sh --appsec
101101

102-
.PHONY: test-contrib
102+
.PHONY: test/contrib
103103
test/contrib: tools-install ## Run contrib package tests
104104
$(BIN_PATH) ./scripts/test.sh --contrib
105105

106-
.PHONY: test-integration
106+
.PHONY: test/integration
107107
test/integration: tools-install ## Run integration tests
108108
$(BIN_PATH) ./scripts/test.sh --integration
109109

appsec/appsecv1_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import (
1010
"strconv"
1111
"testing"
1212

13+
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/require"
15+
1316
"github.com/DataDog/dd-trace-go/v2/appsec"
1417
"github.com/DataDog/dd-trace-go/v2/ddtrace/ext"
1518
"github.com/DataDog/dd-trace-go/v2/ddtrace/mocktracer"
1619
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
1720
"github.com/DataDog/dd-trace-go/v2/internal/telemetry"
1821
"github.com/DataDog/dd-trace-go/v2/internal/telemetry/telemetrytest"
19-
"github.com/stretchr/testify/assert"
20-
"github.com/stretchr/testify/require"
2122
)
2223

2324
func TestTrackUserLoginSuccessEvent(t *testing.T) {

contrib/99designs/gqlgen/appsec_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ import (
1818
"github.com/99designs/gqlgen/graphql"
1919
"github.com/99designs/gqlgen/graphql/handler"
2020
"github.com/99designs/gqlgen/graphql/handler/transport"
21-
"github.com/DataDog/dd-trace-go/v2/ddtrace/mocktracer"
22-
"github.com/DataDog/dd-trace-go/v2/instrumentation/testutils"
2321
"github.com/stretchr/testify/require"
2422
"github.com/vektah/gqlparser/v2"
2523
"github.com/vektah/gqlparser/v2/ast"
2624
"github.com/vektah/gqlparser/v2/gqlerror"
25+
26+
"github.com/DataDog/dd-trace-go/v2/ddtrace/mocktracer"
27+
"github.com/DataDog/dd-trace-go/v2/instrumentation/testutils"
2728
)
2829

2930
func TestAppSec(t *testing.T) {

contrib/99designs/gqlgen/example_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/99designs/gqlgen/graphql/handler/testserver"
1313

1414
gqlgentrace "github.com/DataDog/dd-trace-go/contrib/99designs/gqlgen/v2"
15+
1516
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
1617
)
1718

contrib/99designs/gqlgen/option.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"math"
1111

1212
"github.com/99designs/gqlgen/graphql"
13+
1314
"github.com/DataDog/dd-trace-go/v2/instrumentation"
1415
instrgraphql "github.com/DataDog/dd-trace-go/v2/instrumentation/graphql"
1516
)

contrib/99designs/gqlgen/tracer_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ package gqlgen
77

88
import (
99
"context"
10+
"testing"
11+
1012
"github.com/99designs/gqlgen/client"
1113
"github.com/99designs/gqlgen/graphql"
1214
"github.com/99designs/gqlgen/graphql/handler/testserver"
1315
"github.com/99designs/gqlgen/graphql/handler/transport"
1416
"github.com/stretchr/testify/assert"
1517
"github.com/stretchr/testify/require"
16-
"testing"
1718

1819
internaltestserver "github.com/DataDog/dd-trace-go/contrib/99designs/gqlgen/v2/internal/testserver"
20+
1921
"github.com/DataDog/dd-trace-go/v2/ddtrace/ext"
2022
"github.com/DataDog/dd-trace-go/v2/ddtrace/mocktracer"
2123
)

contrib/IBM/sarama/example_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"log"
1212

1313
saramatrace "github.com/DataDog/dd-trace-go/contrib/IBM/sarama/v2"
14+
1415
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
1516

1617
"github.com/IBM/sarama"

0 commit comments

Comments
 (0)