Skip to content

Commit 0187671

Browse files
committed
copy from cdk-utils
1 parent 060549a commit 0187671

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

.github/instructions/languages/typescript.instructions.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ This document provides instructions for generating, reviewing, and maintaining T
4343
- Use 2 spaces for indentation.
4444
- Limit lines to 120 characters.
4545
- Use single quotes for strings.
46-
- Always use semicolons.
47-
- Prefer trailing commas in multiline objects and arrays.
46+
- Never use semicolons for line termination.
47+
- Avoid trailing commas in multiline objects and arrays.
48+
- Avoid spaces at start and end of single line braces.
4849
- Use ESLint and Prettier for consistent formatting.
4950

5051
## Architecture/Structure
@@ -64,10 +65,10 @@ This document provides instructions for generating, reviewing, and maintaining T
6465
- Example:
6566

6667
```typescript
67-
import { logger } from './utils/logger';
68+
import {logger} from './utils/logger';
6869

69-
logger.info('Fetching user data', { userId });
70-
logger.error('Failed to fetch user', { error });
70+
logger.info('Fetching user data', {userId});
71+
logger.error('Failed to fetch user', {error});
7172
```
7273

7374
### Error Handling
@@ -81,14 +82,14 @@ This document provides instructions for generating, reviewing, and maintaining T
8182
try {
8283
const result = await fetchData();
8384
} catch (error) {
84-
logger.error('Data fetch failed', { error });
85+
logger.error('Data fetch failed', {error});
8586
throw new DataFetchError('Unable to fetch data');
8687
}
8788
```
8889

8990
### Type Safety
9091

91-
- Prefer interfaces and types over `any`.
92+
- Prefer interfaces and types. You MUST NOT use `any`.
9293
- Use type guards and assertions when necessary.
9394
- Example:
9495

@@ -98,7 +99,7 @@ This document provides instructions for generating, reviewing, and maintaining T
9899
name: string;
99100
}
100101
101-
function isUser(obj: any): obj is User {
102+
function isUser(obj: object): obj is User {
102103
return typeof obj.id === 'string' && typeof obj.name === 'string';
103104
}
104105
```
@@ -119,7 +120,7 @@ This document provides instructions for generating, reviewing, and maintaining T
119120
## Testing
120121

121122
- Write unit tests for all business logic.
122-
- Use Jest or similar frameworks for testing.
123+
- Use the existing framework for testing and vitest for new packages.
123124
- Mock external dependencies in tests.
124125
- Example test file structure:
125126

@@ -130,6 +131,20 @@ This document provides instructions for generating, reviewing, and maintaining T
130131
handler.test.ts
131132
```
132133

134+
## JSDoc
135+
136+
- Write concise JSDoc for exported interfaces, types, functions, classes, and exported constants.
137+
- Prefer short phrase-style summaries; avoid long narrative prose.
138+
- Avoid stating information that is obvious from function signatures.
139+
- Consider @param and @returns for every exported function, then include them only when they add meaning not obvious from the signature.
140+
- Skip @param when it only repeats parameter name/type; keep it when documenting constraints, defaults, units, side effects, or domain context.
141+
- It is acceptable to use only @returns in a JSDoc block when that tag carries all useful context.
142+
- Omit a free-text summary line when it only restates the @returns content.
143+
- Provide @example on constructors of exported types/classes and on non-trivial exported types.
144+
- Use @default only when the property is optional in the type and is defaulted in implementation.
145+
- Keep JSDoc defaults aligned with both type signatures and runtime behaviour.
146+
- For construct props interfaces, include a top-level summary and property docs only when intent is non-obvious.
147+
133148
## Examples and Code Snippets
134149

135150
### Good Example

0 commit comments

Comments
 (0)