generated from alexanderop/starter-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.cursorrules
171 lines (145 loc) · 3.43 KB
/
.cursorrules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Vue.js & TypeScript Style Guide (cursor.rules)
This style guide provides rules and patterns for modern Vue.js development combining Vue 3.5, TypeScript, and best practices for maintainable codebases.
## Core Technologies
- Vue 3.5 with Composition API
- TypeScript 5.6
- Vite 5
- Pinia
- Shadcn-Vue
- TailwindCSS
- Vitest & Playwright
## TypeScript Rules
1. Embrace const assertions for type inference
2. Use Readonly and ReadonlyArray for data immutability
3. Make object properties required by default
4. Leverage discriminated unions
5. Avoid type assertions
6. Write pure, stateless functions
7. Keep naming conventions consistent
8. Use named exports over default
9. Group code by feature
## Error Handling
```typescript
type Success<T> = { kind: "success"; value: T }
type Failure<E> = { kind: "failure"; error: E }
type Result<T, E> = Success<T> | Failure<E>
// Example usage
function divide(a: number, b: number): Result<number, string> {
if (b === 0) {
return { kind: "failure", error: "Cannot divide by zero" }
}
return { kind: "success", value: a / b }
}
```
## Vue Component Structure
```vue
<script setup lang="ts">
// 1. Type imports
// 2. Component imports
// 3. Composable imports
// 4. Interface/type definitions
// 5. Props/emits
// 6. Component logic
// 7. Computed properties
// 8. Watchers
</script>
<template>
<!-- 1. Root container with semantic class names -->
<!-- 2. Layout components -->
<!-- 3. UI components -->
<!-- 4. Interactive elements -->
</template>
```
## Vue Features Usage
### Props
```typescript
const {
count = 0,
message = 'hello'
} = defineProps<{
count?: number
message?: string
}>()
```
### Template Refs
```typescript
import { useTemplateRef } from 'vue'
const inputRef = useTemplateRef('input')
```
### State Management
```typescript
const counter = {
count: ref(0),
increment() {
this.count.value += 1
},
decrement() {
this.count.value -= 1
}
}
```
## Composable Rules
1. File Structure:
- Place in `src/composables/`
- Use `use` prefix: `useCounter.ts`
- Give descriptive names
2. Anatomy:
- Primary State (main reactive state)
- Supportive State (loading, errors)
- Methods (state updates)
- Follow consistent ordering:
* Initializing code
* Refs
* Computed
* Methods
* Lifecycle
* Watch
3. Parameters:
```typescript
// Use object for 4+ params
useUserData({
id: 1,
fetchOnMount: true,
token: "abc",
locale: "en"
})
```
4. Error Handling:
```typescript
const error = ref(null)
try {
// Logic
} catch (err) {
error.value = err
}
return { error }
```
5. Separation of Concerns:
- Keep UI logic in components
- Business logic in composables
- Single responsibility principle
6. Functional Pattern:
```typescript
// Functional core
const calculate = (a, b) => a + b
// Imperative shell
export function useCalculator() {
const result = ref(0)
const add = (a, b) => {
result.value = calculate(a, b)
}
return { result, add }
}
```
## Styling Rules
1. Use semantic tokens over raw colors
2. Use HSL variables for custom colors
3. Follow container > section > component hierarchy
4. Use Tailwind's spacing scale
5. Maintain dark mode compatibility
## Testing Requirements
1. Unit tests with Vitest
2. E2E tests with Playwright
3. Test composables in isolation
4. Mock API calls and side effects
5. Test error states explicitly