Skip to content

Commit a67ac9e

Browse files
authored
chore: cleanup golangci-lint and cspell findings (#7548)
Small non-behavioral change fixes to address remaining golangci-lint and cspell findings - Anchor local-template `.gitignore` reads to the template root so nested `.gitignore` files can't escape the local template tree during initialization. - Update `internal/vsrpc/server.go` to derive per-call cancelable contexts from `childCtx`, which preserves the tracing span from `tracing.Start` for Call requests instead of dropping it. - Add targeted `gosec` suppressions where the flagged values are already trusted, managed by azd, or owned by a later callback (local FastAPI detection, Darwin process inspection, spinner/server cancellation callbacks, and managed output paths). - Promote repo-specific spellings into the shared cspell dictionaries, keep compatibility names as file-scoped overrides, and reword the remaining comment-only spellcheck hits. Fixes #7426
1 parent 12b5af3 commit a67ac9e

12 files changed

Lines changed: 50 additions & 22 deletions

File tree

cli/azd/.vscode/cspell-azd-dictionary.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Errorf
1515
Frontends
1616
GOARCH
1717
GOCOVERDIR
18+
GOTOOLCHAIN
19+
GOWORK
1820
Ghostty
1921
LASTEXITCODE
2022
MCPJSON
@@ -110,6 +112,7 @@ containerapps
110112
containerd
111113
containerizable
112114
contoso
115+
covdata
113116
createdby
114117
csharpapp
115118
csharpapptest
@@ -153,6 +156,7 @@ go-imath
153156
godotenv
154157
gofmt
155158
golangci
159+
googleapis
156160
gosec
157161
goterm
158162
gotest
@@ -199,6 +203,7 @@ mysqladmin
199203
mysqlclient
200204
mysqldb
201205
nazd
206+
ndjson
202207
nobanner
203208
nodeapp
204209
nolint

cli/azd/.vscode/cspell.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ overrides:
134134
- filename: cmd/mcp.go
135135
words:
136136
- internalcmd
137+
- filename: cmd/extension.go
138+
words:
139+
- compatResult
140+
- compatCopy
137141
- filename: pkg/azdext/config_helper.go
138142
words:
139143
- myext
@@ -367,10 +371,6 @@ overrides:
367371
- filename: pkg/infra/provisioning/bicep/local_preflight.go
368372
words:
369373
- actioned
370-
- filename: docs/code-coverage-guide.md
371-
words:
372-
- covdata
373-
- GOWORK
374374
ignorePaths:
375375
- "**/*_test.go"
376376
- "**/mock*.go"

cli/azd/internal/appdetect/python.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func PyFastApiLaunch(projectPath string) (string, error) {
142142
}
143143

144144
if strings.HasSuffix(path, "main.py") || strings.HasSuffix(path, "app.py") {
145+
//nolint:gosec // G122: local project contents are trusted for FastAPI detection.
145146
f, err := os.Open(path)
146147
if err != nil {
147148
return err

cli/azd/internal/repository/initializer.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,23 @@ func (i *Initializer) copyLocalTemplate(source, destination string) error {
224224
}
225225
var matchers []gitignoreMatcher
226226

227+
sourceRoot, err := os.OpenRoot(source)
228+
if err != nil {
229+
return fmt.Errorf("opening local template root: %w", err)
230+
}
231+
defer sourceRoot.Close()
232+
227233
_ = filepath.WalkDir(source, func(path string, d fs.DirEntry, err error) error {
228234
if err != nil || d.IsDir() || d.Name() != ".gitignore" {
229235
return err
230236
}
231-
data, readErr := os.ReadFile(path)
237+
238+
rel, relErr := filepath.Rel(source, path)
239+
if relErr != nil {
240+
return relErr
241+
}
242+
243+
data, readErr := sourceRoot.ReadFile(rel)
232244
if readErr != nil {
233245
return nil // skip unreadable gitignore files
234246
}

cli/azd/internal/runcontext/agentdetect/detect_process_darwin.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ import (
1818
func getParentProcessInfoWithPPID(pid int) (parentProcessInfo, int, error) {
1919
info := parentProcessInfo{}
2020
parentPid := 0
21+
pidArg := strconv.Itoa(pid)
2122

2223
// Use ps to get process info and parent PID
2324
// -o comm= gives just the command name, -o ppid= gives parent PID
24-
cmd := exec.Command("ps", "-p", fmt.Sprintf("%d", pid), "-o", "comm=,ppid=")
25+
//nolint:gosec // G204: pidArg is derived from an integer process ID, not shell input.
26+
cmd := exec.Command("ps", "-p", pidArg, "-o", "comm=,ppid=")
2527
output, err := cmd.Output()
2628
if err != nil {
2729
return info, 0, fmt.Errorf("failed to get process info: %w", err)
@@ -37,7 +39,8 @@ func getParentProcessInfoWithPPID(pid int) (parentProcessInfo, int, error) {
3739
}
3840

3941
// Get the full command path
40-
cmd = exec.Command("ps", "-p", fmt.Sprintf("%d", pid), "-o", "args=")
42+
//nolint:gosec // G204: pidArg is derived from an integer process ID, not shell input.
43+
cmd = exec.Command("ps", "-p", pidArg, "-o", "args=")
4144
output, err = cmd.Output()
4245
if err == nil {
4346
cmdLine := strings.TrimSpace(string(output))
@@ -52,7 +55,8 @@ func getParentProcessInfoWithPPID(pid int) (parentProcessInfo, int, error) {
5255

5356
// If we couldn't get the executable from args, try lsof
5457
if info.Executable == "" {
55-
cmd = exec.Command("lsof", "-p", fmt.Sprintf("%d", pid), "-Fn")
58+
//nolint:gosec // G204: pidArg is derived from an integer process ID, not shell input.
59+
cmd = exec.Command("lsof", "-p", pidArg, "-Fn")
5660
output, err = cmd.Output()
5761
if err == nil {
5862
// Parse lsof output - lines starting with 'n' contain file names

cli/azd/internal/vsrpc/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ func (s *Server) Serve(l net.Listener) error {
9090
}
9191

9292
// Run upload periodically in the background while the server is running.
93-
ctx, cancel := context.WithCancel(context.Background()) //nolint:gosec // G118: cancel stored in s.cancelTelemetryUpload
93+
//nolint:gosec // G118: cancel is stored on the server and invoked later by StopAsync.
94+
ctx, cancel := context.WithCancel(context.Background())
9495
ts := telemetry.GetTelemetrySystem()
9596
backgroundTelemetry := func() {
9697
ticker := time.NewTicker(5 * time.Second)
@@ -213,9 +214,9 @@ func serveRpc(w http.ResponseWriter, r *http.Request, handlers map[string]Handle
213214
call, isCall := req.(*jsonrpc2.Call)
214215
if isCall {
215216
span.SetAttributes(fields.JsonRpcId.String(fmt.Sprint(call.ID())))
216-
//nolint:gosec // G118: cancel stored in cancelers map and called on completion
217-
ctx, cancel := context.WithCancel(ctx)
218-
childCtx = ctx
217+
var cancel context.CancelFunc
218+
//nolint:gosec // G118: cancel is stored in cancelers and invoked later by request cancellation handling.
219+
childCtx, cancel = context.WithCancel(childCtx)
219220
cancelersMu.Lock()
220221
cancelers[call.ID()] = cancel
221222
cancelersMu.Unlock()

cli/azd/pkg/azdext/atomicfile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
// WriteFileAtomic writes data to the named file atomically. It writes to a
2121
// temporary file in the same directory as path and renames it into place. This
2222
// ensures that readers never see a partially-written file and that the
23-
// operation is crash-safe on filesystems that support atomic rename (ext4,
23+
// operation is crash-safe on file systems that support atomic rename (ext4,
2424
// APFS, NTFS).
2525
//
2626
// Platform behavior:

cli/azd/pkg/azdext/azd_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func WithAddress(address string) AzdClientOption {
4444
if isLocalhostAddress(address) {
4545
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
4646
} else {
47-
// For non-localhost connections, require TLS to prevent MITM attacks
47+
// For non-localhost connections, require TLS to prevent man-in-the-middle attacks.
4848
opts = append(opts, grpc.WithTransportCredentials(credentials.NewTLS(nil)))
4949
}
5050

cli/azd/pkg/azdext/process_darwin.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ func isProcessRunningOS(pid int) bool {
2727
// getProcessInfoOS retrieves process info on macOS using ps(1).
2828
func getProcessInfoOS(pid int) ProcessInfo {
2929
info := ProcessInfo{PID: pid}
30+
pidArg := strconv.Itoa(pid)
3031

3132
// Use ps to get process name and executable path.
32-
cmd := exec.Command("ps", "-p", strconv.Itoa(pid), "-o", "comm=")
33+
//nolint:gosec // G204: pidArg is derived from an integer process ID, not shell input.
34+
cmd := exec.Command("ps", "-p", pidArg, "-o", "comm=")
3335
output, err := cmd.Output()
3436
if err != nil {
3537
return info // Process does not exist or is inaccessible.
@@ -39,7 +41,8 @@ func getProcessInfoOS(pid int) ProcessInfo {
3941
info.Running = true
4042

4143
// Get full command path.
42-
cmd = exec.Command("ps", "-p", strconv.Itoa(pid), "-o", "args=")
44+
//nolint:gosec // G204: pidArg is derived from an integer process ID, not shell input.
45+
cmd = exec.Command("ps", "-p", pidArg, "-o", "args=")
4346
output, err = cmd.Output()
4447
if err == nil {
4548
args := strings.TrimSpace(string(output))

cli/azd/pkg/infra/provisioning/terraform/terraform_provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ func (t *TerraformProvider) createInputParametersFile(
748748
}
749749

750750
log.Printf("Writing parameters file to: %s", inputFilePath)
751-
//nolint:gosec // G703: path derived from infra config, not user input
751+
//nolint:gosec // G703: inputFilePath is derived from azd's managed .azure environment directory.
752752
err = os.WriteFile(inputFilePath, []byte(replaced), 0600)
753753
if err != nil {
754754
return fmt.Errorf("writing parameter file: %w", err)

0 commit comments

Comments
 (0)