Skip to content

Commit e823664

Browse files
committed
Improve no-any convention with concrete repo-specific patterns
1 parent f3ed032 commit e823664

4 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
paths: "packages/plugins/**"
3+
---
4+
# Plugin Development Conventions
5+
6+
- Inject bundler functionality (e.g., `vite.build`, bundler references) as parameters rather than importing bundler packages directly. This improves testability and avoids dynamic import issues.
7+
- When a plugin needs bundler-specific behavior, encapsulate it in a bundler-specific sub-plugin (e.g., `getVitePlugin()`) and pass bundler functionality in from the top-level plugin entry point.
8+
- The bundler reference is available through the factory's global context — don't import bundler APIs directly when the context already provides what you need.
9+
- When adding new functionality, check if similar patterns already exist in other plugins. Follow established patterns for consistency.

.claude/rules/testing.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
paths: "**/*.test.ts"
3+
---
4+
# Testing Conventions
5+
6+
- Use existing test infrastructure from `packages/tests/src/_jest/helpers/` — check for mock helpers (e.g., `getMockLogger` from `mocks.ts`) before creating ad-hoc mocks.
7+
- Avoid timing-based waits (`setTimeout`, `sleep`) in tests. Wait for specific conditions instead.
8+
- Tests should exercise meaningful behavior, not just repeat the implementation. If a test only asserts what the code literally does with no edge cases or integration value, it's low-value.
9+
- Follow the `cases` + `test.each` pattern for unit tests with multiple inputs/outputs.
10+
- Use `nock` for HTTP mocking and `memfs` for filesystem mocking in integration tests.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ yarn-error.log
88

99
.claude/*
1010
!.claude/commands/*
11+
!.claude/rules/
12+
!.claude/rules/*
1113
!.claude/settings.json
1214

1315
node_modules/

CLAUDE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ Code formatting and linting are configured via:
114114
### Yarn Workspace Commands
115115
Yarn provides "prefixed" scripts using the `<scope>:<action>` pattern. Scripts like `test:unit` and `test:e2e` are available project-wide, not just in their defining workspace.
116116

117+
### Code Conventions
118+
119+
- **No `any` or `as` casts**: Don't use `any` types or `as` type assertions as an escape hatch. Instead use patterns the repo already follows: import types directly from external packages (e.g. `import type { UserConfig } from 'vite'`), use `typeof`/`instanceof`/`in` guards for narrowing (see `wrapPlugins.ts`), derive types from constants with `(typeof MY_CONST)[number]`, or use constrained generics (`<T extends SomeType>`). If you think you need `any`, something is wrong.
120+
- **Use existing repo utilities**: Before writing new helpers, check what already exists:
121+
- HTTP requests: `doRequest` from `@dd/core/helpers/request` (not raw `fetch`)
122+
- File operations: `rm` from `@dd/core/helpers/fs` (not `fs/promises` directly)
123+
- Types: `@dd/core/types` for shared types like `GlobalContext`, `Logger`, etc.
124+
- Test mocks: `getMockLogger` and other helpers from `packages/tests/src/_jest/helpers/mocks`
125+
- **No unnecessary optionality**: Don't make parameters optional (`?`) when they are always provided. If a value must exist at the call site, make the type reflect that.
126+
- **DRY with existing code**: Before writing a new implementation, search for existing code that does the same thing. Reuse and extend rather than duplicate.
127+
- **Consistent dependency versions**: When adding a new dependency, check what version is already used elsewhere in the monorepo (`grep` across `package.json` files) and use the same version. Don't introduce a second version of a package that already exists in the repo.
128+
117129
### Pre-commit Quality Workflow
118130
Always run these commands before committing changes:
119131
1. `yarn format` - Check and fix linting issues

0 commit comments

Comments
 (0)