Skip to content

Commit 09b1d35

Browse files
committed
[refactor] summarize Example codes of Copilot instruction
1 parent a9c5b0a commit 09b1d35

1 file changed

Lines changed: 20 additions & 54 deletions

File tree

.github/copilot-instructions.md

Lines changed: 20 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ Based on comprehensive PR review analysis, follow these critical development sta
100100
- Use utilities from established libraries: 'web-utility'
101101
- Import `'./Base'` in model files for proper configuration
102102

103+
#### Error Handling and Static Generation
104+
105+
- **Natural error throwing** for static generation - let errors bubble up to catch build issues
106+
- Ensure build passes before pushing - resolve issues at compile time
107+
103108
### UI/UX Standards
104109

105110
#### Component Usage Patterns
@@ -129,34 +134,16 @@ import { Button, Badge, Breadcrumb, Card, Container } from 'react-bootstrap';
129134

130135
#### Modern ECMAScript Features
131136

132-
```typescript
133-
// ✅ Correct - use optional chaining
134-
node.parent_path?.split('/')
135-
node.children?.length > 0
136-
137-
// ✅ Correct - let TypeScript infer types when possible
138-
const renderTree = (nodes: WikiNode[], level = 0) => (
139-
// No need for explicit return type annotation
140-
)
141-
142-
// ❌ Wrong - verbose type annotations where inference works
143-
const renderTree = (nodes: WikiNode[], level = 0): React.ReactElement => (
144-
```
137+
- Use optional chaining and modern JavaScript features
138+
- Let TypeScript infer types when possible to avoid verbose annotations
139+
- Use modern ECMAScript patterns for cleaner, more maintainable code
145140

146141
#### Import and Type Management
147142

148-
```typescript
149-
// ✅ Correct - import from established sources
150-
import { ContentModel } from 'mobx-github';
151-
import { treeFrom } from 'web-utility';
152-
import './Base'; // For configuration
153-
154-
// ✅ Correct - minimal exports
155-
export const policyContentStore = new ContentModel('fpsig', 'open-source-policy');
156-
157-
// ❌ Wrong - unnecessary custom implementations
158-
// Don't create new GitHub API clients when configured ones exist
159-
```
143+
- Import from established sources: ContentModel from mobx-github, utilities from web-utility
144+
- Import configuration files where needed: `'./Base'` for GitHub client setup
145+
- Use minimal exports and avoid unnecessary custom implementations
146+
- Use configured clients rather than creating new ones
160147

161148
### Translation and Internationalization
162149

@@ -168,19 +155,9 @@ export const policyContentStore = new ContentModel('fpsig', 'open-source-policy'
168155

169156
#### Translation Patterns
170157

171-
```typescript
172-
// ✅ Correct - all text translated
173-
const { t } = useContext(I18nContext);
174-
175-
<p>{t('no_docs_available')}</p>
176-
<Button>{t('contribute_content')}</Button>
177-
alert(t('operation_successful'));
178-
179-
// ❌ Wrong - hardcoded text
180-
<p>暂无政策文档</p>
181-
<Button>贡献内容</Button>
182-
alert('操作成功');
183-
```
158+
- Use the `t()` function from I18nContext for all user-facing text
159+
- Translate all button text, labels, error messages, and dynamic content
160+
- Avoid hardcoded text in any language
184161

185162
#### Translation Key Management
186163

@@ -192,25 +169,14 @@ alert('操作成功');
192169

193170
#### Content Model Patterns
194171

195-
```typescript
196-
// ✅ Correct - use ContentModel with configured client
197-
import { ContentModel } from 'mobx-github';
198-
import './Base'; // Ensures githubClient configuration
199-
200-
export const policyContentStore = new ContentModel('fpsig', 'open-source-policy');
201-
202-
// Content processing with proper Base64 decoding
203-
const content = item.content ? atob(item.content) : '';
204-
```
172+
- Use ContentModel with configured client from mobx-github
173+
- Import configuration via `'./Base'` to ensure proper GitHub client setup
174+
- Handle Base64 content decoding when processing GitHub API responses
205175

206176
#### Tree Structure and Navigation
207177

208-
```typescript
209-
// ✅ Correct - use treeFrom utility for hierarchical data
210-
import { treeFrom } from 'web-utility';
211-
212-
const tree = treeFrom(nodes, 'path', 'parent_path', 'children');
213-
```
178+
- Use `treeFrom` utility from web-utility for hierarchical data structures
179+
- Follow established patterns for tree node organization and navigation
214180

215181
### GitHub Integration Standards
216182

0 commit comments

Comments
 (0)