Skip to content

Commit f47a2d4

Browse files
committed
fix linting and ensure claude reads agents file every time
Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
1 parent b556434 commit f47a2d4

File tree

3 files changed

+74
-15
lines changed

3 files changed

+74
-15
lines changed

AGENTS.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,29 @@ Prefer `make` targets at repo root:
3232

3333
## Testing Guidelines
3434

35-
- Unit tests: `*_test.go` next to code; run `make test`.
36-
- BDD tests: run `cd tests-bdd && go test ./...` (requires Docker; feature files are `tests-bdd/features/*.feature`).
37-
- Integration tests may require the compose stack; follow module README(s) under `service/`.
35+
### Required Tests Before Committing
36+
37+
**CRITICAL**: All Go code changes must pass these checks before being marked as complete:
38+
39+
1. **Linting**: `golangci-lint run ./path/to/changed/files.go`
40+
- Must pass with 0 issues
41+
- Fixes common issues: formatting, shadowing, unused code, suspicious constructs
42+
- Never let the user discover linting issues from CI
43+
44+
2. **Unit Tests**: `go test ./...` (or `make test` from repo root)
45+
- All existing tests must continue to pass
46+
- Add tests for new functionality
47+
48+
3. **README Code Block Tests**:
49+
- SDK README examples: `cd sdk && go test -run TestREADMECodeBlocks`
50+
- Ensures documentation examples remain compilable
51+
52+
### Test Types
53+
54+
- **Unit tests**: `*_test.go` next to code; run `make test`.
55+
- **BDD tests**: run `cd tests-bdd && go test ./...` (requires Docker; feature files are `tests-bdd/features/*.feature`).
56+
- **Integration tests** may require the compose stack; follow module README(s) under `service/`.
57+
- **README tests**: verify code examples in documentation compile and work correctly.
3858

3959
## Commit & Pull Request Guidelines
4060

CLAUDE.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Claude Code Instructions
2+
3+
## Overview
4+
5+
This file provides instructions for AI agents working on the OpenTDF Platform codebase.
6+
7+
**For complete repository guidelines, coding standards, and development workflow, see [AGENTS.md](AGENTS.md).**
8+
9+
## Critical Requirements
10+
11+
### Before Completing ANY Go Code Changes
12+
13+
**MANDATORY CHECKS** - Run these before marking work as complete:
14+
15+
1. **Linting**: `golangci-lint run ./path/to/changed/files.go`
16+
- Must pass with 0 issues
17+
- User should NEVER discover linting issues from CI
18+
19+
2. **Unit Tests**: `go test ./...` or `make test`
20+
- All existing tests must pass
21+
- Add tests for new functionality
22+
23+
3. **README Tests** (if SDK changes): `cd sdk && go test -run TestREADMECodeBlocks`
24+
- Ensures documentation examples remain compilable
25+
26+
### Formatting
27+
28+
- Run `gofumpt -w <files>` on all changed Go files before completing
29+
- Use tabs for indentation (Go standard)
30+
31+
### Key Guidelines from AGENTS.md
32+
33+
- **Project Structure**: Go workspace with multiple modules (service, sdk, lib/*)
34+
- **Build Commands**: Use `make` targets (build, test, lint, fmt)
35+
- **Commit Style**: Conventional Commits with DCO sign-off (`git commit -s`)
36+
- **Testing**: Unit tests, BDD tests, integration tests - see AGENTS.md for details
37+
38+
## Remember
39+
40+
✅ Run linting checks proactively - don't let CI catch issues
41+
✅ Test changes locally before marking complete
42+
✅ Follow patterns and conventions in AGENTS.md
43+
✅ Update documentation when changing APIs

sdk/readme_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func formatBlockName(index int, code string) string {
7373
}
7474

7575
// Try to find a meaningful identifier in the first few lines
76-
for _, line := range lines[:min(5, len(lines))] {
76+
for _, line := range lines[:minInt(5, len(lines))] {
7777
line = strings.TrimSpace(line)
7878
if strings.HasPrefix(line, "package ") {
7979
return strings.TrimPrefix(line, "package ")
@@ -89,15 +89,11 @@ func formatBlockName(index int, code string) string {
8989
// testCodeBlock attempts to compile a code block.
9090
func testCodeBlock(t *testing.T, code string) error {
9191
// Create a temporary directory
92-
tmpDir, err := os.MkdirTemp("", "readme-test-*")
93-
if err != nil {
94-
return err
95-
}
96-
defer os.RemoveAll(tmpDir)
92+
tmpDir := t.TempDir()
9793

9894
// Write the code to main.go
9995
mainPath := filepath.Join(tmpDir, "main.go")
100-
if err := os.WriteFile(mainPath, []byte(code), 0644); err != nil {
96+
if err := os.WriteFile(mainPath, []byte(code), 0o644); err != nil {
10197
return err
10298
}
10399

@@ -111,7 +107,7 @@ func testCodeBlock(t *testing.T, code string) error {
111107

112108
// Get the absolute path to the platform directory
113109
// When running from sdk directory, we need to go up one level
114-
platformDir, err := filepath.Abs(filepath.Join(".."))
110+
platformDir, err := filepath.Abs("..")
115111
if err != nil {
116112
return err
117113
}
@@ -124,9 +120,9 @@ func testCodeBlock(t *testing.T, code string) error {
124120
}
125121

126122
for _, replace := range replacements {
127-
cmd := exec.Command("go", "mod", "edit", "-replace", replace)
128-
cmd.Dir = tmpDir
129-
if output, err := cmd.CombinedOutput(); err != nil {
123+
editCmd := exec.Command("go", "mod", "edit", "-replace", replace)
124+
editCmd.Dir = tmpDir
125+
if output, err := editCmd.CombinedOutput(); err != nil {
130126
t.Logf("go mod edit output: %s", output)
131127
return err
132128
}
@@ -153,7 +149,7 @@ func testCodeBlock(t *testing.T, code string) error {
153149
return nil
154150
}
155151

156-
func min(a, b int) int {
152+
func minInt(a, b int) int {
157153
if a < b {
158154
return a
159155
}

0 commit comments

Comments
 (0)