Skip to content

Commit d174ff7

Browse files
committed
chore: lint
1 parent 3a2a3e4 commit d174ff7

1 file changed

Lines changed: 70 additions & 42 deletions

File tree

AGENTS.md

Lines changed: 70 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ yarn test
5656

5757
### Common Setup Issues
5858

59-
| Problem | Solution |
60-
|---------|----------|
61-
| `command not found: yarn` | Run `corepack enable` |
62-
| Build fails with type errors | Run `yarn build:clean` |
63-
| Tests fail after setup | Ensure all dependencies installed: `yarn install` |
64-
| Circular dependency warnings | Run `yarn lint:dependencies:fix` |
59+
| Problem | Solution |
60+
| ---------------------------- | ------------------------------------------------- |
61+
| `command not found: yarn` | Run `corepack enable` |
62+
| Build fails with type errors | Run `yarn build:clean` |
63+
| Tests fail after setup | Ensure all dependencies installed: `yarn install` |
64+
| Circular dependency warnings | Run `yarn lint:dependencies:fix` |
6565

6666
---
6767

@@ -81,6 +81,7 @@ yarn build:docs
8181
```
8282

8383
**Build System Notes:**
84+
8485
- Uses `ts-bridge` for TypeScript compilation
8586
- Build outputs go to each package's `dist/` directory
8687
- Source maps are generated for debugging
@@ -106,6 +107,7 @@ yarn test:clean
106107
```
107108

108109
**Testing Notes:**
110+
109111
- Tests must be colocated with source files (e.g., `file.ts``file.test.ts`)
110112
- Uses Jest as test runner
111113
- Coverage reports in `coverage/` directory of each package
@@ -160,6 +162,7 @@ yarn dedupe
160162
```
161163

162164
**Dependency Notes:**
165+
163166
- Use workspace protocol for internal dependencies: `"@metamask/keyring-api": "workspace:^"`
164167
- Run `yarn lint:dependencies:fix` after adding/updating packages
165168
- Check `syncpack` for version consistency across packages
@@ -321,54 +324,61 @@ accounts/
321324
**The dependency relationships between packages are maintained in [README.md](./README.md) with a visual graph. Always run `yarn readme:update` when updating dependencies to keep this graph current.**
322325

323326
**Core Packages:**
327+
324328
- `keyring-api` - Core interfaces
325329
- `keyring-utils` - Shared utilities
326330

327331
**Implementation Packages:**
332+
328333
- `keyring-eth-hd` - HD wallet implementation
329334
- `keyring-eth-simple` - Simple keyring implementation
330335
- `keyring-eth-trezor` - Trezor hardware wallet integration
331336
- `keyring-eth-ledger-bridge` - Ledger hardware wallet integration
332337
- `keyring-eth-qr` - QR code keyring for air-gapped signing
333338

334339
**Snap Packages:**
340+
335341
- `keyring-snap-bridge` - Snap keyring bridge for MetaMask Snaps
336342
- `keyring-snap-client` - Client library for snap communication
337343
- `keyring-snap-sdk` - SDK for building keyring Snaps
338344
- `keyring-internal-api` - Internal APIs for keyring communication
339345
- `keyring-internal-snap-client` - Internal snap client implementation
340346

341347
**Account API:**
348+
342349
- `account-api` - Account abstractions and utilities
343350

344351
### Finding Specific Code
345352

346-
| Feature | Location |
347-
|---------|----------|
348-
| Core keyring interfaces | `packages/keyring-api/src/api/` |
349-
| Ethereum-specific methods | `packages/keyring-api/src/eth/` |
350-
| Bitcoin methods | `packages/keyring-api/src/btc/` |
351-
| Solana methods | `packages/keyring-api/src/sol/` |
352-
| Snap integration | `packages/keyring-snap-bridge/src/` |
353-
| Utility functions | `packages/keyring-utils/src/` |
354-
| Type definitions | Each package's `src/*.types.ts` or `src/types.ts` |
353+
| Feature | Location |
354+
| ------------------------- | ------------------------------------------------- |
355+
| Core keyring interfaces | `packages/keyring-api/src/api/` |
356+
| Ethereum-specific methods | `packages/keyring-api/src/eth/` |
357+
| Bitcoin methods | `packages/keyring-api/src/btc/` |
358+
| Solana methods | `packages/keyring-api/src/sol/` |
359+
| Snap integration | `packages/keyring-snap-bridge/src/` |
360+
| Utility functions | `packages/keyring-utils/src/` |
361+
| Type definitions | Each package's `src/*.types.ts` or `src/types.ts` |
355362

356363
### Architecture Patterns
357364

358365
**Keyring Implementations:**
366+
359367
- Implement the `Keyring` interface from `@metamask/keyring-api`
360368
- Methods for account management: `getAccounts()`, `addAccounts()`, etc.
361369
- Methods for signing: `signTransaction()`, `signMessage()`, etc.
362370
- State serialization: `serialize()` and `deserialize()`
363371
- Type property to identify keyring type
364372

365373
**Type Definitions:**
374+
366375
- Use strict TypeScript types (no `any`)
367376
- Export types and interfaces from separate files when complex
368377
- Use JSDoc comments for public APIs
369378
- Leverage TypeScript utility types (`Partial`, `Required`, `Pick`, etc.)
370379

371380
**Testing:**
381+
372382
- Tests colocated with source: `file.ts``file.test.ts`
373383
- Use `describe` blocks to organize by class/function
374384
- Use `it` blocks for individual test cases (not `test`)
@@ -381,6 +391,7 @@ accounts/
381391
When you modify certain files, you typically need to update related files:
382392

383393
**When modifying a package's main export:**
394+
384395
```
385396
packages/foo/src/FooKeyring.ts → ALSO UPDATE:
386397
├── packages/foo/src/FooKeyring.test.ts (tests)
@@ -390,6 +401,7 @@ packages/foo/src/FooKeyring.ts → ALSO UPDATE:
390401
```
391402

392403
**When adding a new file to a package:**
404+
393405
```
394406
packages/foo/src/new-feature.ts → ALSO CREATE:
395407
├── packages/foo/src/new-feature.test.ts (tests)
@@ -398,6 +410,7 @@ packages/foo/src/new-feature.ts → ALSO CREATE:
398410
```
399411

400412
**When changing exported types:**
413+
401414
```
402415
packages/foo/src/types.ts → CHECK:
403416
├── All packages that depend on this package
@@ -406,6 +419,7 @@ packages/foo/src/types.ts → CHECK:
406419
```
407420

408421
**When adding/removing dependencies:**
422+
409423
```
410424
packages/foo/package.json → MUST RUN:
411425
├── yarn install (update lockfile)
@@ -432,11 +446,11 @@ enum AccountType {
432446
}
433447

434448
// ❌ WRONG: Plural enum names
435-
enum EthMethods { // Don't use plural
449+
enum EthMethods { // Don't use plural
436450
SignTransaction = 'eth_signTransaction',
437451
}
438452

439-
enum AccountTypes { // Don't use plural
453+
enum AccountTypes { // Don't use plural
440454
Eoa = 'eoa',
441455
}
442456

@@ -454,16 +468,22 @@ enum EthMethod {
454468
}
455469

456470
// ✅ CORRECT: Interfaces and types use PascalCase
457-
interface KeyringAccount { /* ... */ }
471+
interface KeyringAccount {
472+
/* ... */
473+
}
458474
type AccountId = string;
459475

460476
// ✅ CORRECT: Functions and variables use camelCase
461-
function getAccountById(id: string): KeyringAccount { /* ... */ }
477+
function getAccountById(id: string): KeyringAccount {
478+
/* ... */
479+
}
462480
const accountList: KeyringAccount[] = [];
463481

464482
// ✅ CORRECT: Constants use SCREAMING_SNAKE_CASE or camelCase
465483
const SNAP_KEYRING_TYPE = 'Snap Keyring';
466-
const defaultOptions = { /* ... */ };
484+
const defaultOptions = {
485+
/* ... */
486+
};
467487

468488
// ✅ CORRECT: Private class members use # prefix
469489
class SnapKeyring {
@@ -642,7 +662,7 @@ expect(mockMessenger.call).toHaveBeenCalledWith(
642662
'SnapController:handleRequest',
643663
expect.objectContaining({
644664
snapId: 'local:snap.mock',
645-
})
665+
}),
646666
);
647667
```
648668

@@ -659,7 +679,7 @@ it('creates account asynchronously', async () => {
659679
// ✅ CORRECT: Test error cases
660680
it('throws error when creation fails', async () => {
661681
await expect(
662-
keyring.createAccount(snapId, { invalid: true })
682+
keyring.createAccount(snapId, { invalid: true }),
663683
).rejects.toThrow('Invalid account options');
664684
});
665685
```
@@ -749,6 +769,7 @@ describe('SnapKeyringV2', () => {
749769
```
750770

751771
**Setup Function Best Practices:**
772+
752773
- Return an object with the instance under test, mocks, and any helpers
753774
- Use default parameters for optional configuration
754775
- Type the return value explicitly for better IDE support
@@ -904,50 +925,55 @@ IF you added/modified types:
904925

905926
### Build Issues
906927

907-
| Problem | Solution |
908-
|---------|----------|
909-
| Type errors in build | Run `yarn build:clean` to rebuild from scratch |
910-
| Module not found | Run `yarn install` to ensure all deps installed |
911-
| Circular dependency warnings | Check `packages/*/src/index.ts` exports |
912-
| Build hangs | Check for infinite loops in type definitions |
928+
| Problem | Solution |
929+
| ---------------------------- | ----------------------------------------------- |
930+
| Type errors in build | Run `yarn build:clean` to rebuild from scratch |
931+
| Module not found | Run `yarn install` to ensure all deps installed |
932+
| Circular dependency warnings | Check `packages/*/src/index.ts` exports |
933+
| Build hangs | Check for infinite loops in type definitions |
913934

914935
### Test Issues
915936

916-
| Problem | Solution |
917-
|---------|----------|
918-
| Tests fail after changes | Check if test expectations need updating |
919-
| Tests timeout | Increase timeout in jest.config.js |
920-
| Coverage too low | Add tests for uncovered code paths |
921-
| Mock not working | Verify mock is called before test assertion |
937+
| Problem | Solution |
938+
| ------------------------ | ------------------------------------------- |
939+
| Tests fail after changes | Check if test expectations need updating |
940+
| Tests timeout | Increase timeout in jest.config.js |
941+
| Coverage too low | Add tests for uncovered code paths |
942+
| Mock not working | Verify mock is called before test assertion |
922943

923944
### Development Issues
924945

925-
| Problem | Solution |
926-
|---------|----------|
927-
| ESLint errors | Run `yarn lint:fix` to auto-fix |
928-
| Type errors | Check imported types are exported correctly |
929-
| Dependency version mismatch | Run `yarn lint:dependencies:fix` |
930-
| Yarn lockfile conflicts | Run `yarn dedupe` |
946+
| Problem | Solution |
947+
| --------------------------- | ------------------------------------------- |
948+
| ESLint errors | Run `yarn lint:fix` to auto-fix |
949+
| Type errors | Check imported types are exported correctly |
950+
| Dependency version mismatch | Run `yarn lint:dependencies:fix` |
951+
| Yarn lockfile conflicts | Run `yarn dedupe` |
931952

932953
### Common Error Messages
933954

934955
**"@typescript-eslint/no-explicit-any: Unexpected any"**
956+
935957
- Solution: Replace `any` with proper type (string, number, Json, unknown, etc.)
936958

937959
**"Cannot find module '@metamask/...'"**
960+
938961
- Solution: Add dependency to package.json and run `yarn install`
939962

940963
**"Circular dependency detected"**
964+
941965
- Solution: Refactor imports to avoid circular references, use type-only imports if needed
942966

943967
**"Test suite failed to run"**
968+
944969
- Solution: Check jest.config.js configuration, ensure test file has `.test.ts` extension
945970

946971
---
947972

948973
## Summary for Quick Reference
949974

950975
**Key Commands:**
976+
951977
```bash
952978
yarn install # Install dependencies
953979
yarn build # Build all packages
@@ -957,6 +983,7 @@ yarn release # Start release process
957983
```
958984

959985
**Key Principles:**
986+
960987
1. TypeScript only, no `any` types
961988
2. Tests colocated with source
962989
3. High test coverage (>80%)
@@ -965,13 +992,14 @@ yarn release # Start release process
965992
6. Follow existing patterns in codebase
966993

967994
**Before Committing:**
995+
968996
- [ ] `yarn lint:fix` passes
969-
- [ ] `yarn test` passes
997+
- [ ] `yarn test` passes
970998
- [ ] `yarn build` succeeds
971999
- [ ] CHANGELOG.md updated
9721000
- [ ] Tests added/updated
9731001
- [ ] Documentation updated
9741002

9751003
---
9761004

977-
*This document is intended to help AI coding agents understand the codebase structure, patterns, and workflows. For human developers, please also refer to the package-specific README files and MetaMask contributor documentation.*
1005+
_This document is intended to help AI coding agents understand the codebase structure, patterns, and workflows. For human developers, please also refer to the package-specific README files and MetaMask contributor documentation._

0 commit comments

Comments
 (0)