memory-journal-mcp 7.0.1 → 7.2.0
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.
- package/README.md +75 -66
- package/dist/{chunk-6J4RPJ4I.js → chunk-GR4T3SRW.js} +146 -105
- package/dist/{chunk-ARLH46WS.js → chunk-IWKLHSPU.js} +89 -3
- package/dist/{chunk-2BJHLTYP.js → chunk-ORV7ZZOE.js} +1086 -86
- package/dist/cli.js +30 -4
- package/dist/github-integration-2TFMXHIJ.js +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +3 -3
- package/dist/{tools-FFFGXIKN.js → tools-CXR2FEB2.js} +2 -2
- package/package.json +2 -2
- package/skills/README.md +77 -0
- package/skills/autonomous-dev/SKILL.md +56 -0
- package/skills/bin/sync.js +50 -0
- package/skills/bun/SKILL.md +156 -0
- package/skills/github-commander/SKILL.md +1 -1
- package/skills/github-commander/workflows/code-quality-audit.md +7 -5
- package/skills/github-commander/workflows/issue-triage.md +13 -4
- package/skills/github-commander/workflows/milestone-sprint.md +9 -1
- package/skills/github-commander/workflows/perf-audit.md +2 -0
- package/skills/github-commander/workflows/pr-review.md +9 -3
- package/skills/github-commander/workflows/roadmap-kickoff.md +79 -0
- package/skills/github-commander/workflows/security-audit.md +3 -3
- package/skills/github-commander/workflows/update-deps.md +2 -2
- package/skills/gitlab/SKILL.md +115 -0
- package/skills/gitlab/package-lock.json +392 -0
- package/skills/gitlab/package.json +14 -0
- package/skills/gitlab/scripts/gitlab-client.ts +125 -0
- package/skills/gitlab/scripts/gitlab-helper.ts +80 -0
- package/skills/golang/SKILL.md +54 -0
- package/skills/mysql/SKILL.md +30 -0
- package/skills/package.json +48 -0
- package/skills/playwright-standard/SKILL.md +58 -0
- package/skills/playwright-standard/examples/fixtures.ts +66 -0
- package/skills/playwright-standard/examples/type-stubs.d.ts +10 -0
- package/skills/playwright-standard/references/advanced-scenarios.md +59 -0
- package/skills/playwright-standard/references/infrastructure.md +43 -0
- package/skills/postgres/SKILL.md +33 -0
- package/skills/react-best-practices/AGENTS.md +2883 -0
- package/skills/react-best-practices/README.md +127 -0
- package/skills/react-best-practices/SKILL.md +138 -0
- package/skills/react-best-practices/metadata.json +17 -0
- package/skills/react-best-practices/rules/_sections.md +46 -0
- package/skills/react-best-practices/rules/_template.md +28 -0
- package/skills/react-best-practices/rules/advanced-event-handler-refs.md +55 -0
- package/skills/react-best-practices/rules/advanced-init-once.md +42 -0
- package/skills/react-best-practices/rules/advanced-use-latest.md +39 -0
- package/skills/react-best-practices/rules/async-api-routes.md +35 -0
- package/skills/react-best-practices/rules/async-defer-await.md +80 -0
- package/skills/react-best-practices/rules/async-dependencies.md +48 -0
- package/skills/react-best-practices/rules/async-parallel.md +24 -0
- package/skills/react-best-practices/rules/async-suspense-boundaries.md +99 -0
- package/skills/react-best-practices/rules/bundle-barrel-imports.md +59 -0
- package/skills/react-best-practices/rules/bundle-conditional.md +37 -0
- package/skills/react-best-practices/rules/bundle-defer-third-party.md +48 -0
- package/skills/react-best-practices/rules/bundle-dynamic-imports.md +34 -0
- package/skills/react-best-practices/rules/bundle-preload.md +44 -0
- package/skills/react-best-practices/rules/client-event-listeners.md +78 -0
- package/skills/react-best-practices/rules/client-localstorage-schema.md +74 -0
- package/skills/react-best-practices/rules/client-passive-event-listeners.md +48 -0
- package/skills/react-best-practices/rules/client-swr-dedup.md +56 -0
- package/skills/react-best-practices/rules/js-batch-dom-css.md +110 -0
- package/skills/react-best-practices/rules/js-cache-function-results.md +80 -0
- package/skills/react-best-practices/rules/js-cache-property-access.md +28 -0
- package/skills/react-best-practices/rules/js-cache-storage.md +68 -0
- package/skills/react-best-practices/rules/js-combine-iterations.md +32 -0
- package/skills/react-best-practices/rules/js-early-exit.md +50 -0
- package/skills/react-best-practices/rules/js-hoist-regexp.md +45 -0
- package/skills/react-best-practices/rules/js-index-maps.md +37 -0
- package/skills/react-best-practices/rules/js-length-check-first.md +50 -0
- package/skills/react-best-practices/rules/js-min-max-loop.md +82 -0
- package/skills/react-best-practices/rules/js-set-map-lookups.md +24 -0
- package/skills/react-best-practices/rules/js-tosorted-immutable.md +57 -0
- package/skills/react-best-practices/rules/rendering-activity.md +24 -0
- package/skills/react-best-practices/rules/rendering-animate-svg-wrapper.md +38 -0
- package/skills/react-best-practices/rules/rendering-conditional-render.md +32 -0
- package/skills/react-best-practices/rules/rendering-content-visibility.md +38 -0
- package/skills/react-best-practices/rules/rendering-hoist-jsx.md +36 -0
- package/skills/react-best-practices/rules/rendering-hydration-no-flicker.md +72 -0
- package/skills/react-best-practices/rules/rendering-hydration-suppress-warning.md +26 -0
- package/skills/react-best-practices/rules/rendering-svg-precision.md +28 -0
- package/skills/react-best-practices/rules/rendering-usetransition-loading.md +75 -0
- package/skills/react-best-practices/rules/rerender-defer-reads.md +39 -0
- package/skills/react-best-practices/rules/rerender-dependencies.md +45 -0
- package/skills/react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
- package/skills/react-best-practices/rules/rerender-derived-state.md +29 -0
- package/skills/react-best-practices/rules/rerender-functional-setstate.md +77 -0
- package/skills/react-best-practices/rules/rerender-lazy-state-init.md +56 -0
- package/skills/react-best-practices/rules/rerender-memo-with-default-value.md +36 -0
- package/skills/react-best-practices/rules/rerender-memo.md +44 -0
- package/skills/react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
- package/skills/react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
- package/skills/react-best-practices/rules/rerender-transitions.md +40 -0
- package/skills/react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
- package/skills/react-best-practices/rules/server-after-nonblocking.md +73 -0
- package/skills/react-best-practices/rules/server-auth-actions.md +96 -0
- package/skills/react-best-practices/rules/server-cache-lru.md +41 -0
- package/skills/react-best-practices/rules/server-cache-react.md +76 -0
- package/skills/react-best-practices/rules/server-dedup-props.md +65 -0
- package/skills/react-best-practices/rules/server-parallel-fetching.md +83 -0
- package/skills/react-best-practices/rules/server-serialization.md +38 -0
- package/skills/rust/SKILL.md +86 -0
- package/skills/shadcn-ui/SKILL.md +72 -0
- package/skills/skill-builder/SKILL.md +457 -0
- package/skills/skill-builder/checklist.md +65 -0
- package/skills/sqlite/SKILL.md +38 -0
- package/skills/typescript/SKILL.md +453 -0
- package/skills/typescript/assets/eslint-template.js +102 -0
- package/skills/typescript/assets/tsconfig-template.json +45 -0
- package/skills/typescript/references/enterprise-patterns.md +531 -0
- package/skills/typescript/references/generics.md +493 -0
- package/skills/typescript/references/nestjs-integration.md +579 -0
- package/skills/typescript/references/react-integration.md +616 -0
- package/skills/typescript/references/toolchain.md +547 -0
- package/skills/typescript/references/type-system.md +481 -0
- package/skills/vitest-standard/SKILL.md +82 -0
- package/skills/vitest-standard/examples/service-mock.ts +60 -0
- package/skills/vitest-standard/examples/tdd-calculator.ts +41 -0
- package/skills/vitest-standard/examples/type-stubs.d.ts +18 -0
- package/skills/vitest-standard/references/async-and-errors.md +58 -0
- package/skills/vitest-standard/references/coverage-and-config.md +53 -0
- package/skills/vitest-standard/references/mocking.md +61 -0
- package/skills/vitest-standard/references/tdd-patterns.md +60 -0
- package/dist/github-integration-PDRLXKGM.js +0 -1
- package/skills/github-commander/workflows/full-audit.md +0 -134
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
# Modern Toolchain Reference
|
|
2
|
+
|
|
3
|
+
> **Load when:** User asks about Vite, pnpm, ESLint, Vitest, tsconfig, build tools, or project configuration.
|
|
4
|
+
|
|
5
|
+
Modern TypeScript toolchain configuration for 2025.
|
|
6
|
+
|
|
7
|
+
## Contents
|
|
8
|
+
|
|
9
|
+
- [TypeScript Configuration](#typescript-configuration)
|
|
10
|
+
- [Package Manager (pnpm)](#package-manager-pnpm)
|
|
11
|
+
- [Build Tool (Vite)](#build-tool-vite)
|
|
12
|
+
- [Linting (ESLint 9)](#linting-eslint-9)
|
|
13
|
+
- [Testing (Vitest)](#testing-vitest)
|
|
14
|
+
- [Formatting (Prettier)](#formatting-prettier)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## TypeScript Configuration
|
|
19
|
+
|
|
20
|
+
### Strict Enterprise Configuration
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
// tsconfig.json
|
|
24
|
+
{
|
|
25
|
+
"compilerOptions": {
|
|
26
|
+
// Language and Environment
|
|
27
|
+
"target": "ES2024",
|
|
28
|
+
"lib": ["ES2024"],
|
|
29
|
+
"module": "ESNext",
|
|
30
|
+
"moduleResolution": "bundler",
|
|
31
|
+
|
|
32
|
+
// Strict Type Checking
|
|
33
|
+
"strict": true,
|
|
34
|
+
"noUncheckedIndexedAccess": true,
|
|
35
|
+
"exactOptionalPropertyTypes": true,
|
|
36
|
+
"noImplicitOverride": true,
|
|
37
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
38
|
+
|
|
39
|
+
// Module Handling
|
|
40
|
+
"esModuleInterop": true,
|
|
41
|
+
"allowSyntheticDefaultImports": true,
|
|
42
|
+
"isolatedModules": true,
|
|
43
|
+
"verbatimModuleSyntax": true,
|
|
44
|
+
|
|
45
|
+
// Output
|
|
46
|
+
"declaration": true,
|
|
47
|
+
"declarationMap": true,
|
|
48
|
+
"sourceMap": true,
|
|
49
|
+
"outDir": "./dist",
|
|
50
|
+
"rootDir": "./src",
|
|
51
|
+
|
|
52
|
+
// Path Aliases
|
|
53
|
+
"baseUrl": ".",
|
|
54
|
+
"paths": {
|
|
55
|
+
"@/*": ["./src/*"]
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
// Performance
|
|
59
|
+
"skipLibCheck": true,
|
|
60
|
+
"incremental": true,
|
|
61
|
+
"tsBuildInfoFile": "./node_modules/.cache/tsbuildinfo"
|
|
62
|
+
},
|
|
63
|
+
"include": ["src/**/*"],
|
|
64
|
+
"exclude": ["node_modules", "dist"]
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### React Project Configuration
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
// tsconfig.json for React
|
|
72
|
+
{
|
|
73
|
+
"compilerOptions": {
|
|
74
|
+
"target": "ES2022",
|
|
75
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
76
|
+
"module": "ESNext",
|
|
77
|
+
"moduleResolution": "bundler",
|
|
78
|
+
"jsx": "react-jsx",
|
|
79
|
+
|
|
80
|
+
"strict": true,
|
|
81
|
+
"noUncheckedIndexedAccess": true,
|
|
82
|
+
"noImplicitOverride": true,
|
|
83
|
+
|
|
84
|
+
"esModuleInterop": true,
|
|
85
|
+
"isolatedModules": true,
|
|
86
|
+
"skipLibCheck": true,
|
|
87
|
+
|
|
88
|
+
"baseUrl": ".",
|
|
89
|
+
"paths": {
|
|
90
|
+
"@/*": ["./src/*"],
|
|
91
|
+
"@components/*": ["./src/components/*"],
|
|
92
|
+
"@hooks/*": ["./src/hooks/*"]
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"include": ["src"],
|
|
96
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Node.js Backend Configuration
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
// tsconfig.json for Node.js/NestJS
|
|
104
|
+
{
|
|
105
|
+
"compilerOptions": {
|
|
106
|
+
"target": "ES2022",
|
|
107
|
+
"module": "NodeNext",
|
|
108
|
+
"moduleResolution": "NodeNext",
|
|
109
|
+
"lib": ["ES2022"],
|
|
110
|
+
|
|
111
|
+
"strict": true,
|
|
112
|
+
"noUncheckedIndexedAccess": true,
|
|
113
|
+
"exactOptionalPropertyTypes": true,
|
|
114
|
+
"noImplicitOverride": true,
|
|
115
|
+
|
|
116
|
+
"esModuleInterop": true,
|
|
117
|
+
"isolatedModules": true,
|
|
118
|
+
"skipLibCheck": true,
|
|
119
|
+
|
|
120
|
+
"outDir": "./dist",
|
|
121
|
+
"rootDir": "./src",
|
|
122
|
+
"declaration": true,
|
|
123
|
+
"sourceMap": true,
|
|
124
|
+
|
|
125
|
+
"experimentalDecorators": true,
|
|
126
|
+
"emitDecoratorMetadata": true
|
|
127
|
+
},
|
|
128
|
+
"include": ["src/**/*"],
|
|
129
|
+
"exclude": ["node_modules", "dist", "**/*.spec.ts"]
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Package Manager (pnpm)
|
|
136
|
+
|
|
137
|
+
### Why pnpm
|
|
138
|
+
|
|
139
|
+
| Feature | npm | pnpm |
|
|
140
|
+
| ---------------- | ------------------- | ---------------------- |
|
|
141
|
+
| Disk usage | Duplicates packages | Shared store, symlinks |
|
|
142
|
+
| Install speed | Slower | 2-3x faster |
|
|
143
|
+
| Strictness | Allows phantom deps | Strict by default |
|
|
144
|
+
| Monorepo support | Basic workspaces | First-class support |
|
|
145
|
+
|
|
146
|
+
### Basic Commands
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# Install dependencies
|
|
150
|
+
pnpm install
|
|
151
|
+
|
|
152
|
+
# Add packages
|
|
153
|
+
pnpm add typescript
|
|
154
|
+
pnpm add -D vitest @types/node
|
|
155
|
+
|
|
156
|
+
# Run scripts
|
|
157
|
+
pnpm run build
|
|
158
|
+
pnpm test
|
|
159
|
+
|
|
160
|
+
# Update packages
|
|
161
|
+
pnpm update
|
|
162
|
+
pnpm update --interactive
|
|
163
|
+
|
|
164
|
+
# List packages
|
|
165
|
+
pnpm list
|
|
166
|
+
pnpm why lodash
|
|
167
|
+
|
|
168
|
+
# Clean install
|
|
169
|
+
pnpm install --frozen-lockfile
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Workspace Configuration
|
|
173
|
+
|
|
174
|
+
```yaml
|
|
175
|
+
# pnpm-workspace.yaml
|
|
176
|
+
packages:
|
|
177
|
+
- 'packages/*'
|
|
178
|
+
- 'apps/*'
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
// package.json (root)
|
|
183
|
+
{
|
|
184
|
+
"name": "my-monorepo",
|
|
185
|
+
"private": true,
|
|
186
|
+
"scripts": {
|
|
187
|
+
"build": "pnpm -r run build",
|
|
188
|
+
"test": "pnpm -r run test",
|
|
189
|
+
"lint": "pnpm -r run lint"
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Build Tool (Vite)
|
|
197
|
+
|
|
198
|
+
### Vite Configuration
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
// vite.config.ts
|
|
202
|
+
import { defineConfig } from 'vite'
|
|
203
|
+
import react from '@vitejs/plugin-react'
|
|
204
|
+
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
205
|
+
|
|
206
|
+
export default defineConfig({
|
|
207
|
+
plugins: [react(), tsconfigPaths()],
|
|
208
|
+
server: {
|
|
209
|
+
port: 3000,
|
|
210
|
+
host: true,
|
|
211
|
+
},
|
|
212
|
+
build: {
|
|
213
|
+
target: 'es2022',
|
|
214
|
+
sourcemap: true,
|
|
215
|
+
rollupOptions: {
|
|
216
|
+
output: {
|
|
217
|
+
manualChunks: {
|
|
218
|
+
vendor: ['react', 'react-dom'],
|
|
219
|
+
utils: ['lodash-es', 'date-fns'],
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
test: {
|
|
225
|
+
globals: true,
|
|
226
|
+
environment: 'jsdom',
|
|
227
|
+
setupFiles: ['./src/test/setup.ts'],
|
|
228
|
+
},
|
|
229
|
+
})
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Library Mode
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
// vite.config.ts for library
|
|
236
|
+
import { defineConfig } from 'vite'
|
|
237
|
+
import dts from 'vite-plugin-dts'
|
|
238
|
+
|
|
239
|
+
export default defineConfig({
|
|
240
|
+
build: {
|
|
241
|
+
lib: {
|
|
242
|
+
entry: './src/index.ts',
|
|
243
|
+
name: 'MyLibrary',
|
|
244
|
+
fileName: 'my-library',
|
|
245
|
+
formats: ['es', 'cjs'],
|
|
246
|
+
},
|
|
247
|
+
rollupOptions: {
|
|
248
|
+
external: ['react', 'react-dom'],
|
|
249
|
+
output: {
|
|
250
|
+
globals: {
|
|
251
|
+
react: 'React',
|
|
252
|
+
'react-dom': 'ReactDOM',
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
plugins: [dts({ insertTypesEntry: true })],
|
|
258
|
+
})
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Linting (ESLint 9)
|
|
264
|
+
|
|
265
|
+
### Flat Config Format
|
|
266
|
+
|
|
267
|
+
```javascript
|
|
268
|
+
// eslint.config.js
|
|
269
|
+
import eslint from '@eslint/js'
|
|
270
|
+
import tseslint from 'typescript-eslint'
|
|
271
|
+
import reactPlugin from 'eslint-plugin-react'
|
|
272
|
+
import reactHooksPlugin from 'eslint-plugin-react-hooks'
|
|
273
|
+
|
|
274
|
+
export default tseslint.config(
|
|
275
|
+
// Base ESLint recommendations
|
|
276
|
+
eslint.configs.recommended,
|
|
277
|
+
|
|
278
|
+
// TypeScript strict type-checking
|
|
279
|
+
...tseslint.configs.strictTypeChecked,
|
|
280
|
+
...tseslint.configs.stylisticTypeChecked,
|
|
281
|
+
|
|
282
|
+
// TypeScript parser options
|
|
283
|
+
{
|
|
284
|
+
languageOptions: {
|
|
285
|
+
parserOptions: {
|
|
286
|
+
projectService: true,
|
|
287
|
+
tsconfigRootDir: import.meta.dirname,
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
// React configuration
|
|
293
|
+
{
|
|
294
|
+
files: ['**/*.tsx'],
|
|
295
|
+
plugins: {
|
|
296
|
+
react: reactPlugin,
|
|
297
|
+
'react-hooks': reactHooksPlugin,
|
|
298
|
+
},
|
|
299
|
+
rules: {
|
|
300
|
+
...reactPlugin.configs.recommended.rules,
|
|
301
|
+
...reactHooksPlugin.configs.recommended.rules,
|
|
302
|
+
'react/react-in-jsx-scope': 'off',
|
|
303
|
+
},
|
|
304
|
+
settings: {
|
|
305
|
+
react: { version: 'detect' },
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
|
|
309
|
+
// Custom rules
|
|
310
|
+
{
|
|
311
|
+
rules: {
|
|
312
|
+
'@typescript-eslint/no-unused-vars': [
|
|
313
|
+
'error',
|
|
314
|
+
{
|
|
315
|
+
argsIgnorePattern: '^_',
|
|
316
|
+
varsIgnorePattern: '^_',
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
'@typescript-eslint/consistent-type-imports': [
|
|
320
|
+
'error',
|
|
321
|
+
{
|
|
322
|
+
prefer: 'type-imports',
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
'@typescript-eslint/no-floating-promises': 'error',
|
|
326
|
+
'@typescript-eslint/await-thenable': 'error',
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
|
|
330
|
+
// Ignore patterns
|
|
331
|
+
{
|
|
332
|
+
ignores: ['dist/**', 'node_modules/**', '*.config.js'],
|
|
333
|
+
}
|
|
334
|
+
)
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Common Rules Explained
|
|
338
|
+
|
|
339
|
+
```javascript
|
|
340
|
+
// Important TypeScript ESLint rules
|
|
341
|
+
{
|
|
342
|
+
rules: {
|
|
343
|
+
// Enforce type imports for better tree-shaking
|
|
344
|
+
'@typescript-eslint/consistent-type-imports': 'error',
|
|
345
|
+
|
|
346
|
+
// Prevent unhandled promises
|
|
347
|
+
'@typescript-eslint/no-floating-promises': 'error',
|
|
348
|
+
'@typescript-eslint/no-misused-promises': 'error',
|
|
349
|
+
|
|
350
|
+
// Prevent awaiting non-promises
|
|
351
|
+
'@typescript-eslint/await-thenable': 'error',
|
|
352
|
+
|
|
353
|
+
// Require return types on functions
|
|
354
|
+
'@typescript-eslint/explicit-function-return-type': ['error', {
|
|
355
|
+
allowExpressions: true
|
|
356
|
+
}],
|
|
357
|
+
|
|
358
|
+
// Prefer nullish coalescing
|
|
359
|
+
'@typescript-eslint/prefer-nullish-coalescing': 'error',
|
|
360
|
+
|
|
361
|
+
// Prefer optional chaining
|
|
362
|
+
'@typescript-eslint/prefer-optional-chain': 'error',
|
|
363
|
+
|
|
364
|
+
// No any type
|
|
365
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
366
|
+
|
|
367
|
+
// Enforce strict boolean expressions
|
|
368
|
+
'@typescript-eslint/strict-boolean-expressions': 'error'
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## Testing (Vitest)
|
|
376
|
+
|
|
377
|
+
### Vitest Configuration
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
// vitest.config.ts
|
|
381
|
+
import { defineConfig } from 'vitest/config'
|
|
382
|
+
import react from '@vitejs/plugin-react'
|
|
383
|
+
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
384
|
+
|
|
385
|
+
export default defineConfig({
|
|
386
|
+
plugins: [react(), tsconfigPaths()],
|
|
387
|
+
test: {
|
|
388
|
+
globals: true,
|
|
389
|
+
environment: 'jsdom',
|
|
390
|
+
setupFiles: ['./src/test/setup.ts'],
|
|
391
|
+
include: ['src/**/*.{test,spec}.{ts,tsx}'],
|
|
392
|
+
coverage: {
|
|
393
|
+
provider: 'v8',
|
|
394
|
+
reporter: ['text', 'json', 'html'],
|
|
395
|
+
exclude: ['**/*.d.ts', '**/*.config.*', '**/test/**'],
|
|
396
|
+
},
|
|
397
|
+
typecheck: {
|
|
398
|
+
enabled: true,
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
})
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Test Setup
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
// src/test/setup.ts
|
|
408
|
+
import '@testing-library/jest-dom/vitest'
|
|
409
|
+
import { cleanup } from '@testing-library/react'
|
|
410
|
+
import { afterEach, beforeAll, afterAll, vi } from 'vitest'
|
|
411
|
+
|
|
412
|
+
// Cleanup after each test
|
|
413
|
+
afterEach(() => {
|
|
414
|
+
cleanup()
|
|
415
|
+
})
|
|
416
|
+
|
|
417
|
+
// Mock environment variables
|
|
418
|
+
beforeAll(() => {
|
|
419
|
+
vi.stubEnv('API_URL', 'http://localhost:3000')
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
afterAll(() => {
|
|
423
|
+
vi.unstubAllEnvs()
|
|
424
|
+
})
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
### Example Tests
|
|
428
|
+
|
|
429
|
+
```typescript
|
|
430
|
+
// src/utils/format.test.ts
|
|
431
|
+
import { describe, it, expect } from 'vitest';
|
|
432
|
+
import { formatCurrency, formatDate } from './format';
|
|
433
|
+
|
|
434
|
+
describe('formatCurrency', () => {
|
|
435
|
+
it('formats USD correctly', () => {
|
|
436
|
+
expect(formatCurrency(1234.56, 'USD')).toBe('$1,234.56');
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('handles zero', () => {
|
|
440
|
+
expect(formatCurrency(0, 'USD')).toBe('$0.00');
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
// src/components/Button.test.tsx
|
|
445
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
446
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
447
|
+
import { Button } from './Button';
|
|
448
|
+
|
|
449
|
+
describe('Button', () => {
|
|
450
|
+
it('renders with label', () => {
|
|
451
|
+
render(<Button label="Click me" onClick={() => {}} />);
|
|
452
|
+
expect(screen.getByRole('button')).toHaveTextContent('Click me');
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it('calls onClick when clicked', () => {
|
|
456
|
+
const handleClick = vi.fn();
|
|
457
|
+
render(<Button label="Click" onClick={handleClick} />);
|
|
458
|
+
|
|
459
|
+
fireEvent.click(screen.getByRole('button'));
|
|
460
|
+
|
|
461
|
+
expect(handleClick).toHaveBeenCalledOnce();
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
---
|
|
467
|
+
|
|
468
|
+
## Formatting (Prettier)
|
|
469
|
+
|
|
470
|
+
### Prettier Configuration
|
|
471
|
+
|
|
472
|
+
```json
|
|
473
|
+
// .prettierrc
|
|
474
|
+
{
|
|
475
|
+
"semi": true,
|
|
476
|
+
"singleQuote": true,
|
|
477
|
+
"tabWidth": 2,
|
|
478
|
+
"trailingComma": "es5",
|
|
479
|
+
"printWidth": 100,
|
|
480
|
+
"bracketSpacing": true,
|
|
481
|
+
"arrowParens": "always",
|
|
482
|
+
"endOfLine": "lf"
|
|
483
|
+
}
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
### Integration with ESLint
|
|
487
|
+
|
|
488
|
+
```javascript
|
|
489
|
+
// eslint.config.js
|
|
490
|
+
import eslintConfigPrettier from 'eslint-config-prettier'
|
|
491
|
+
|
|
492
|
+
export default tseslint.config(
|
|
493
|
+
// ... other configs
|
|
494
|
+
eslintConfigPrettier // Must be last to disable conflicting rules
|
|
495
|
+
)
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### Package Scripts
|
|
499
|
+
|
|
500
|
+
```json
|
|
501
|
+
// package.json
|
|
502
|
+
{
|
|
503
|
+
"scripts": {
|
|
504
|
+
"format": "prettier --write .",
|
|
505
|
+
"format:check": "prettier --check .",
|
|
506
|
+
"lint": "eslint .",
|
|
507
|
+
"lint:fix": "eslint --fix .",
|
|
508
|
+
"typecheck": "tsc --noEmit"
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
---
|
|
514
|
+
|
|
515
|
+
## Complete Project Setup
|
|
516
|
+
|
|
517
|
+
### Quick Start Script
|
|
518
|
+
|
|
519
|
+
```bash
|
|
520
|
+
#!/bin/bash
|
|
521
|
+
# setup-ts-project.sh
|
|
522
|
+
|
|
523
|
+
PROJECT_NAME=${1:-my-app}
|
|
524
|
+
|
|
525
|
+
# Create project with Vite
|
|
526
|
+
pnpm create vite@latest $PROJECT_NAME --template react-ts
|
|
527
|
+
cd $PROJECT_NAME
|
|
528
|
+
|
|
529
|
+
# Install dependencies
|
|
530
|
+
pnpm install
|
|
531
|
+
|
|
532
|
+
# Add development dependencies
|
|
533
|
+
pnpm add -D \
|
|
534
|
+
typescript-eslint \
|
|
535
|
+
@eslint/js \
|
|
536
|
+
eslint-plugin-react \
|
|
537
|
+
eslint-plugin-react-hooks \
|
|
538
|
+
eslint-config-prettier \
|
|
539
|
+
prettier \
|
|
540
|
+
vitest \
|
|
541
|
+
@vitest/coverage-v8 \
|
|
542
|
+
@testing-library/react \
|
|
543
|
+
@testing-library/jest-dom \
|
|
544
|
+
vite-tsconfig-paths
|
|
545
|
+
|
|
546
|
+
echo "Project setup complete! Run: cd $PROJECT_NAME && pnpm dev"
|
|
547
|
+
```
|