Skip to content

Commit 7c95472

Browse files
tobrunclaudestepankuzmin
authored andcommitted
Update CLAUDE.md based on review comments (internal-12545)
Analyzed inline review comments across the last 100 merged GL-JS PRs to extract recurring corrections and guidance that Claude should follow when generating code for this project. cc @mapbox/gl-js --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Stepan Kuzmin <stepan.kuzmin@mapbox.com> GitOrigin-RevId: 6c0084d9ce3e7d6743debf7a7cf243b68a0c570f
1 parent 248817e commit 7c95472

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,19 @@ test/
158158

159159
- The project has TypeScript configured with `strict: false`, but write all TypeScript code as if strict mode is enabled
160160
- This means: always handle `null`/`undefined` cases, use proper type annotations, avoid `any` types, and ensure type safety
161+
- Prefer explicit return types over `// @ts-expect-error` suppressions for functions that may not return a value
162+
- Prefer literal unions over boolean flags; allows future extension without breaking changes
161163

162164
## Testing Guidelines
163165

164166
- Tests use Vitest framework with Playwright as the browser provider
165167
- Install Playwright browsers: `npx playwright install chromium`
168+
- Any PR that changes rendering behavior (shader changes, draw function logic, bucket data changes) must include a render test in `test/integration/render-tests/`
169+
- For query behavior changes, add corresponding query tests covering all affected layer types
170+
- Render tests for bug fixes must fail without the fix; a tolerance loose enough to pass either way is useless
171+
- Every render test `style.json` must include a `_comment` field explaining what it checks; drop unused intermediate `wait` steps
172+
- Don't inflate render test tolerance to make a failing test pass — investigate the root cause
173+
- Size render test expected images to the minimum needed (e.g., 32×64, not 128×128)
166174

167175
### Writing Unit Tests
168176

@@ -181,10 +189,19 @@ test/
181189
- Function descriptions: start with third-person verb (e.g., "Sets...", "Returns...")
182190
- For functions returning values, start with "Returns..."
183191
- Event descriptions: start with "Fired when..."
192+
- Style-spec `doc` fields in `v8.json` render verbatim in the public API reference — use unambiguous language, avoid internal terms, and don't reference implementation details
193+
- When adding a new property to `v8.json`, populate the `sdk-support` table and set `experimental: true` until release version is confirmed
184194

185195
## WebGL and Shaders
186196

187197
- Custom `#pragma mapbox` directives in shaders expand to uniforms or attributes
188198
- Shader programs are dynamically generated based on style properties
189199
- Data-driven styling creates paint vertex arrays at layout time
190200
- See [@src/shaders/README.md](src/shaders/README.md) for shader documentation
201+
- Use named `#define` constants for integer mode values in shaders — never bare magic numbers like `if (u_blend_mode == 1)`
202+
- Use `#if defined(A) && defined(B)` for compound shader conditionals (not `#ifdef`); required for the Metal preprocessing pipeline
203+
204+
## Performance
205+
206+
- Allocate GPU objects (buffers, textures, bind groups, UBOs) at bucket creation or style load time; invalidate only when underlying data changes. **Never allocate GPU objects inside draw functions that run every frame.**
207+
- In hot paths, prefer flat typed arrays (`Float32Array`, `Uint16Array`) over arrays of objects or nested arrays

0 commit comments

Comments
 (0)