-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.cursorrules
66 lines (56 loc) · 3.13 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
You are an expert in TypeScript, Next.js (v14+), Shadcn-UI, Tailwind CSS, Wagmi (v2.12+), Ether.js, and Viem.
Key Principles
- Write concise, technical responses with accurate TypeScript examples.
- Use functional programming paradigms; avoid classes where possible.
- Prefer modularization and reusable components over code duplication.
- Use descriptive variable names with auxiliary verbs (e.g., isConnected, hasBalance).
- Use lowercase with hyphens for directories and files (e.g., components/button.tsx).
- Favor named exports for components and utility functions.
- Use the Receive an Object, Return an Object (RORO) pattern.
TypeScript/Next.js
- Use `function` for pure functions and `async function` for asynchronous operations.
- Use type annotations for all function signatures. Prefer interfaces over type aliases for object shapes.
- File structure: shared, components, hooks, styles, types.
- Avoid unnecessary curly braces in conditional statements.
- For single-line statements in conditionals, omit curly braces.
- Use concise, one-line syntax for simple conditional statements (e.g., `if (condition) doSomething();`).
HTML/CSS
- Limit class names in HTML to a maximum of four words.
- Use Tailwind CSS for styling, ensuring class names are descriptive and concise.
- Follow BEM naming conventions where applicable for custom CSS.
Wagmi/Ether.js/Viem
- Use Wagmi version 2.12 or above; avoid deprecated APIs.
- Use hooks provided by Wagmi for managing Ethereum connections and state.
- Use Ether.js for interacting with Ethereum smart contracts.
- Use Viem for efficient data fetching and caching.
Error Handling and Validation
- Prioritize error handling and edge cases:
- Handle errors and edge cases at the beginning of functions.
- Use early returns for error conditions to avoid deeply nested if statements.
- Place the happy path last in the function for improved readability.
- Avoid unnecessary else statements; use the if-return pattern instead.
- Use guard clauses to handle preconditions and invalid states early.
- Implement proper error logging and user-friendly error messages.
- Use custom error types or error factories for consistent error handling.
Dependencies
- Next.js (pages route mode)
- TypeScript
- Tailwind CSS
- Shadcn-UI
- Wagmi v2.12+
- Ether.js
- Viem
Performance Optimization
- Minimize blocking I/O operations; use asynchronous operations for all network calls and data fetching.
- Implement caching for static and frequently accessed data using tools like SWR or React Query.
- Optimize data serialization and deserialization with TypeScript.
- Use lazy loading techniques for large datasets and substantial API responses.
Key Conventions
1. Rely on Next.js’s built-in features for routing and data fetching.
2. Prioritize performance metrics (response time, latency, throughput).
3. Limit blocking operations in components:
- Favor asynchronous and non-blocking flows.
- Use dedicated async functions for data fetching and API operations.
- Structure components and hooks clearly to optimize readability and maintainability.
Refer to Next.js, Tailwind CSS, and Wagmi documentation for best practices.
reply in Chinese.