@aicgen/aicgen 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,308 +0,0 @@
1
- # Code Style Rules
2
-
3
- # Naming Conventions
4
-
5
- ## Variables and Functions
6
-
7
- ```typescript
8
- // camelCase for variables and functions
9
- const userName = 'John';
10
- const isActive = true;
11
- const itemCount = 42;
12
-
13
- function calculateTotal(items: Item[]): number {
14
- return items.reduce((sum, item) => sum + item.price, 0);
15
- }
16
-
17
- // Boolean variables: use is/has/can/should prefix
18
- const isValid = validate(input);
19
- const hasPermission = checkPermission(user);
20
- const canEdit = user.role === 'admin';
21
- const shouldRetry = error.code === 'TIMEOUT';
22
-
23
- // Collections: use plural names
24
- const users = getUsers();
25
- const activeOrders = orders.filter(o => o.status === 'active');
26
- ```
27
-
28
- ## Constants
29
-
30
- ```typescript
31
- // UPPER_SNAKE_CASE for constants
32
- const MAX_RETRY_ATTEMPTS = 3;
33
- const DEFAULT_TIMEOUT_MS = 5000;
34
- const API_BASE_URL = 'https://api.example.com';
35
-
36
- // Enum-like objects
37
- const ORDER_STATUS = {
38
- PENDING: 'pending',
39
- PROCESSING: 'processing',
40
- SHIPPED: 'shipped',
41
- DELIVERED: 'delivered',
42
- CANCELLED: 'cancelled'
43
- } as const;
44
-
45
- const HTTP_STATUS = {
46
- OK: 200,
47
- CREATED: 201,
48
- BAD_REQUEST: 400,
49
- NOT_FOUND: 404
50
- } as const;
51
- ```
52
-
53
- ## Classes and Types
54
-
55
- ```typescript
56
- // PascalCase for classes and types
57
- class UserService {
58
- constructor(private userRepository: UserRepository) {}
59
- }
60
-
61
- interface User {
62
- id: string;
63
- name: string;
64
- email: string;
65
- }
66
-
67
- type UserRole = 'admin' | 'editor' | 'viewer';
68
-
69
- // Avoid prefixes
70
- // ❌ IUser, CUser, TUser
71
- // ✅ User
72
- ```
73
-
74
- ## Files and Modules
75
-
76
- ```typescript
77
- // kebab-case for files
78
- user-service.ts
79
- order-repository.ts
80
- create-user.dto.ts
81
-
82
- // Match file name to primary export
83
- // user-service.ts exports UserService
84
- // order-repository.ts exports OrderRepository
85
- ```
86
-
87
- ## Avoid Bad Names
88
-
89
- ```typescript
90
- // ❌ Bad - unclear
91
- const d = Date.now();
92
- const tmp = user.name;
93
- const data = fetchData();
94
- const flag = true;
95
-
96
- // ✅ Good - descriptive
97
- const currentDate = Date.now();
98
- const originalUserName = user.name;
99
- const customerOrders = fetchCustomerOrders();
100
- const isEmailVerified = true;
101
- ```
102
-
103
- ## Avoid Magic Numbers
104
-
105
- ```typescript
106
- // ❌ Magic numbers
107
- if (user.age >= 18) { ... }
108
- if (items.length > 100) { ... }
109
- setTimeout(callback, 5000);
110
-
111
- // ✅ Named constants
112
- const LEGAL_AGE = 18;
113
- const MAX_BATCH_SIZE = 100;
114
- const DEFAULT_TIMEOUT_MS = 5000;
115
-
116
- if (user.age >= LEGAL_AGE) { ... }
117
- if (items.length > MAX_BATCH_SIZE) { ... }
118
- setTimeout(callback, DEFAULT_TIMEOUT_MS);
119
- ```
120
-
121
- ## Consistency
122
-
123
- ```typescript
124
- // Pick ONE style and stick with it across the project
125
-
126
- // ✅ Consistent camelCase in APIs
127
- {
128
- "userId": 123,
129
- "firstName": "John",
130
- "createdAt": "2024-01-01"
131
- }
132
-
133
- // ❌ Mixed styles
134
- {
135
- "user_id": 123, // snake_case
136
- "firstName": "John", // camelCase - inconsistent!
137
- }
138
- ```
139
-
140
-
141
- ---
142
-
143
- # Code Organization
144
-
145
- ## Function Length
146
-
147
- ```typescript
148
- // ❌ Function too long (>50 lines)
149
- function processOrder(orderId: string) {
150
- // 200 lines of validation, payment, inventory, shipping...
151
- }
152
-
153
- // ✅ Extract into smaller, focused functions
154
- function processOrder(orderId: string) {
155
- const order = fetchOrder(orderId);
156
-
157
- validateOrder(order);
158
- reserveInventory(order.items);
159
- processPayment(order);
160
- scheduleShipping(order);
161
- sendConfirmation(order.customer.email);
162
-
163
- return order;
164
- }
165
- ```
166
-
167
- ## Nesting Depth
168
-
169
- ```typescript
170
- // ❌ Too much nesting (>3 levels)
171
- if (user) {
172
- if (user.isActive) {
173
- if (user.hasPermission('edit')) {
174
- if (resource.isAvailable) {
175
- // Deep nesting is hard to follow
176
- }
177
- }
178
- }
179
- }
180
-
181
- // ✅ Guard clauses to reduce nesting
182
- if (!user) return;
183
- if (!user.isActive) return;
184
- if (!user.hasPermission('edit')) return;
185
- if (!resource.isAvailable) return;
186
-
187
- // Clear logic at top level
188
-
189
- // ✅ Extract complex conditions
190
- function canEditResource(user: User, resource: Resource): boolean {
191
- return user &&
192
- user.isActive &&
193
- user.hasPermission('edit') &&
194
- resource.isAvailable;
195
- }
196
-
197
- if (canEditResource(user, resource)) {
198
- // Single level of nesting
199
- }
200
- ```
201
-
202
- ## File Length
203
-
204
- ```typescript
205
- // ❌ God file (1000+ lines)
206
- // user-service.ts with 50 methods handling users, auth, permissions...
207
-
208
- // ✅ Split into focused modules (~200-300 lines each)
209
- // user-service.ts - CRUD operations
210
- // auth-service.ts - login, logout, tokens
211
- // permission-service.ts - role checks
212
- ```
213
-
214
- ## File Organization
215
-
216
- ```typescript
217
- // Consistent structure within files:
218
-
219
- // 1. Imports (grouped and ordered)
220
- import fs from 'fs'; // Standard library
221
- import express from 'express'; // External dependencies
222
- import { UserService } from './user'; // Internal modules
223
-
224
- // 2. Constants and type definitions
225
- const MAX_RETRIES = 3;
226
-
227
- interface UserDTO {
228
- id: string;
229
- name: string;
230
- }
231
-
232
- // 3. Helper functions (if needed)
233
- function validateInput(input: unknown): boolean {
234
- // ...
235
- }
236
-
237
- // 4. Main exports/classes
238
- export class OrderService {
239
- // ...
240
- }
241
-
242
- // 5. Module initialization (if applicable)
243
- export default new OrderService();
244
- ```
245
-
246
- ## Single Responsibility
247
-
248
- ```typescript
249
- // ❌ Class doing too much
250
- class UserManager {
251
- createUser() {}
252
- updateUser() {}
253
- sendEmail() {}
254
- hashPassword() {}
255
- generateToken() {}
256
- }
257
-
258
- // ✅ Split by responsibility
259
- class UserRepository {
260
- create(user: User) {}
261
- update(id: string, data: Partial<User>) {}
262
- }
263
-
264
- class EmailService {
265
- send(to: string, template: string) {}
266
- }
267
-
268
- class PasswordService {
269
- hash(password: string): string {}
270
- verify(password: string, hash: string): boolean {}
271
- }
272
-
273
- class AuthService {
274
- generateToken(userId: string): string {}
275
- }
276
- ```
277
-
278
- ## DRY (Don't Repeat Yourself)
279
-
280
- ```typescript
281
- // ❌ Duplicated logic
282
- function processUserOrder(order: Order) {
283
- const total = order.items.reduce((sum, i) => sum + i.price * i.quantity, 0);
284
- const tax = total * 0.08;
285
- return total + tax;
286
- }
287
-
288
- function processGuestOrder(order: Order) {
289
- const total = order.items.reduce((sum, i) => sum + i.price * i.quantity, 0);
290
- const tax = total * 0.08;
291
- return total + tax;
292
- }
293
-
294
- // ✅ Extract common logic
295
- function calculateOrderTotal(items: Item[]): number {
296
- const subtotal = items.reduce((sum, i) => sum + i.price * i.quantity, 0);
297
- const tax = subtotal * 0.08;
298
- return subtotal + tax;
299
- }
300
-
301
- function processUserOrder(order: Order) {
302
- return calculateOrderTotal(order.items);
303
- }
304
- ```
305
-
306
-
307
- ---
308
- *Generated by aicgen*