codingwithagent 1.0.0 → 1.1.1
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/CHANGELOG.md +28 -0
- package/LICENSE +21 -21
- package/README.md +131 -37
- package/bin/init.js +257 -257
- package/package.json +56 -56
- package/templates/accessibility/.cursorrules +342 -342
- package/templates/accessibility/README.md +47 -47
- package/templates/antigravity/accessibility/.agent/rules/accessibility.md +501 -501
- package/templates/antigravity/accessibility/.agent/rules/aria-patterns.md +568 -568
- package/templates/antigravity/accessibility/.agent/rules/wcag-standard.md +225 -225
- package/templates/antigravity/accessibility/README.md +42 -42
- package/templates/antigravity/minimal/.agent/rules/accessibility.md +53 -53
- package/templates/antigravity/minimal/.agent/rules/code-quality.md +86 -86
- package/templates/antigravity/minimal/.agent/rules/react-components.md +164 -164
- package/templates/antigravity/minimal/README.md +34 -34
- package/templates/antigravity/standard/.agent/rules/accessibility.md +98 -98
- package/templates/antigravity/standard/.agent/rules/code-quality.md +166 -166
- package/templates/antigravity/standard/.agent/rules/pull-request-review.md +192 -192
- package/templates/antigravity/standard/.agent/rules/react-components.md +204 -204
- package/templates/antigravity/standard/.agent/rules/testing.md +197 -197
- package/templates/antigravity/standard/README.md +39 -39
- package/templates/antigravity/strict/.agent/README.md +46 -46
- package/templates/antigravity/strict/.agent/rules/accessibility.md +199 -199
- package/templates/antigravity/strict/.agent/rules/code-quality.md +268 -268
- package/templates/antigravity/strict/.agent/rules/pull-request-review.md +114 -114
- package/templates/antigravity/strict/.agent/rules/react-components.md +423 -423
- package/templates/antigravity/strict/.agent/rules/security.md +483 -483
- package/templates/antigravity/strict/.agent/rules/testing.md +280 -280
- package/templates/minimal/.cursorrules +48 -48
- package/templates/minimal/README.md +40 -40
- package/templates/standard/.cursorrules +184 -184
- package/templates/standard/README.md +43 -43
- package/templates/strict/.cursorrules +227 -227
- package/templates/strict/README.md +47 -47
|
@@ -1,204 +1,204 @@
|
|
|
1
|
-
---
|
|
2
|
-
trigger: always_on
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# React Component Standards
|
|
6
|
-
|
|
7
|
-
## Component Architecture
|
|
8
|
-
|
|
9
|
-
### Separation of Concerns
|
|
10
|
-
|
|
11
|
-
- **Containers**: Connect to Redux, handle business logic, pass props to components
|
|
12
|
-
- **Components**: Pure presentational, receive data via props only
|
|
13
|
-
- **Utils**: Pure functions, no side effects, reusable across project
|
|
14
|
-
- **Selectors**: Data transformation and derivation from Redux state
|
|
15
|
-
- **Sagas**: Side effects and async operations
|
|
16
|
-
|
|
17
|
-
### Component Design Principles
|
|
18
|
-
|
|
19
|
-
- Keep components stateless whenever possible
|
|
20
|
-
- Single Responsibility Principle: One component, one purpose
|
|
21
|
-
- Composition over inheritance
|
|
22
|
-
- Allow containment through props.children
|
|
23
|
-
- No dependencies on rest of app outside props
|
|
24
|
-
|
|
25
|
-
## Functional vs Class Components
|
|
26
|
-
|
|
27
|
-
### Use Functional Components
|
|
28
|
-
|
|
29
|
-
- All new components must be functional with hooks
|
|
30
|
-
- Class components supported but not recommended
|
|
31
|
-
- Lifecycle methods replaced with useEffect
|
|
32
|
-
- Local state managed with useState
|
|
33
|
-
|
|
34
|
-
### Hooks Usage
|
|
35
|
-
|
|
36
|
-
#### Standard Hooks
|
|
37
|
-
|
|
38
|
-
- **useState**: Local UI state only
|
|
39
|
-
- **useEffect**: Side effects, subscriptions, API calls
|
|
40
|
-
- Be explicit with dependency array
|
|
41
|
-
- Return cleanup functions for subscriptions
|
|
42
|
-
- Avoid infinite loops by managing dependencies carefully
|
|
43
|
-
- **useMemo**: Expensive calculations only (don't overuse)
|
|
44
|
-
- **useCallback**: Prevent unnecessary child re-renders
|
|
45
|
-
- **useRef**: DOM access, storing mutable values that don't trigger re-renders
|
|
46
|
-
|
|
47
|
-
#### Custom Hooks
|
|
48
|
-
|
|
49
|
-
- Declare in `/hooks` directory or component-level
|
|
50
|
-
- Prefix with "use" (e.g., useFormValidation)
|
|
51
|
-
- Extract reusable stateful logic
|
|
52
|
-
- Return values and functions for component use
|
|
53
|
-
|
|
54
|
-
## JSX Standards
|
|
55
|
-
|
|
56
|
-
### What TO Put in JSX
|
|
57
|
-
|
|
58
|
-
- Presentational markup and structure
|
|
59
|
-
- Props destructuring and usage
|
|
60
|
-
- Conditional rendering (boolean only)
|
|
61
|
-
- Event handler bindings
|
|
62
|
-
- Component composition
|
|
63
|
-
- Rendering logic from props
|
|
64
|
-
|
|
65
|
-
### What NOT TO Put in JSX
|
|
66
|
-
|
|
67
|
-
- Business logic - belongs in selectors or utils
|
|
68
|
-
- API calls - belongs in sagas or useEffect
|
|
69
|
-
- Complex data transformations - belongs in selectors
|
|
70
|
-
- Direct DOM manipulation - use refs sparingly
|
|
71
|
-
- State mutations - use setState or Redux actions
|
|
72
|
-
|
|
73
|
-
### JSX Best Practices
|
|
74
|
-
|
|
75
|
-
- Destructure props at function signature: `const Component = ({prop1, prop2}) => {}`
|
|
76
|
-
- Return early for null/loading states
|
|
77
|
-
- Extract complex conditional JSX to separate components
|
|
78
|
-
- Use ternary or && for simple conditionals only
|
|
79
|
-
- Avoid inline functions in render (use useCallback)
|
|
80
|
-
- Add comments for unclear rendering logic only
|
|
81
|
-
|
|
82
|
-
## Props Management
|
|
83
|
-
|
|
84
|
-
### Props Access and Destructuring
|
|
85
|
-
|
|
86
|
-
```javascript
|
|
87
|
-
// GOOD: Destructure at signature level
|
|
88
|
-
const Component = ({ title, onClick, children }) => {
|
|
89
|
-
return <button onClick={onClick}>{title}</button>;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// BAD: Accessing props object
|
|
93
|
-
const Component = (props) => {
|
|
94
|
-
return <button onClick={props.onClick}>{props.title}</button>;
|
|
95
|
-
};
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### Prop Types
|
|
99
|
-
|
|
100
|
-
- Define PropTypes for ALL components
|
|
101
|
-
- Mark required props with .isRequired
|
|
102
|
-
- Use shape() for complex objects
|
|
103
|
-
- Extract shared PropTypes to shapes.js file
|
|
104
|
-
- Provide defaultProps for optional props
|
|
105
|
-
|
|
106
|
-
### Props Drilling
|
|
107
|
-
|
|
108
|
-
- Maximum 3 levels of prop drilling
|
|
109
|
-
- Beyong 3 levels: Create intermediate container
|
|
110
|
-
- Consider React Context for deep tree data
|
|
111
|
-
- Use Redux for truly global state
|
|
112
|
-
|
|
113
|
-
## Local State
|
|
114
|
-
|
|
115
|
-
### When to Use Local State
|
|
116
|
-
|
|
117
|
-
- UI-only concerns (modal open/closed, input focus)
|
|
118
|
-
- Temporary form data before submission
|
|
119
|
-
- Component-specific toggles and flags
|
|
120
|
-
- Animation states
|
|
121
|
-
|
|
122
|
-
### When NOT to Use Local State
|
|
123
|
-
|
|
124
|
-
- Data from API responses - use Redux
|
|
125
|
-
- Shared data between components - use Redux
|
|
126
|
-
- Form data managed by react-redux-form - use model
|
|
127
|
-
- Data that needs to persist across component unmounts
|
|
128
|
-
|
|
129
|
-
## Component Complexity
|
|
130
|
-
|
|
131
|
-
### When to Refactor
|
|
132
|
-
|
|
133
|
-
- Component exceeds well over 200 lines
|
|
134
|
-
- More than 10 props being passed
|
|
135
|
-
- Nested ternary operators (>2 levels)
|
|
136
|
-
- Duplicate logic across components
|
|
137
|
-
- Difficult to write tests for
|
|
138
|
-
|
|
139
|
-
### Refactoring Strategies
|
|
140
|
-
|
|
141
|
-
- Extract child components
|
|
142
|
-
- Create custom hooks for complex logic
|
|
143
|
-
- Move business logic to selectors
|
|
144
|
-
- Use composition with props.children
|
|
145
|
-
- Split container and presentational concerns
|
|
146
|
-
|
|
147
|
-
## DOM Access and Manipulation
|
|
148
|
-
|
|
149
|
-
### Avoid Direct DOM Manipulation
|
|
150
|
-
|
|
151
|
-
- Stay in React domain whenever possible
|
|
152
|
-
- Do NOT use document.querySelector
|
|
153
|
-
- Do NOT manipulate DOM with vanilla JS
|
|
154
|
-
- Use React refs only when necessary
|
|
155
|
-
|
|
156
|
-
### When to Use Refs
|
|
157
|
-
|
|
158
|
-
- Focus management
|
|
159
|
-
- Integration with third-party DOM libraries
|
|
160
|
-
- Measuring DOM nodes (scroll position, dimensions)
|
|
161
|
-
- Triggering imperative animations
|
|
162
|
-
|
|
163
|
-
### Ref Best Practices
|
|
164
|
-
|
|
165
|
-
- Use useRef hook in functional components
|
|
166
|
-
- Assign refs to DOM elements, not React components
|
|
167
|
-
- Access refs in useEffect or event handlers, not render
|
|
168
|
-
- Clean up refs in useEffect return function
|
|
169
|
-
|
|
170
|
-
## Methods Returning JSX
|
|
171
|
-
|
|
172
|
-
### Create Proper Components
|
|
173
|
-
|
|
174
|
-
```jsx
|
|
175
|
-
// GOOD: Separate component
|
|
176
|
-
const FeatureDisplay = ({ feature, value }) => (
|
|
177
|
-
<div>
|
|
178
|
-
{feature}: {value}
|
|
179
|
-
</div>
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
const ParentComponent = ({ data }) => (
|
|
183
|
-
<FeatureDisplay feature={data.name} value={data.value} />
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
// BAD: Method returning JSX
|
|
187
|
-
const ParentComponent = ({ data }) => {
|
|
188
|
-
const renderFeature = (name, value) => (
|
|
189
|
-
<div>
|
|
190
|
-
{name}: {value}
|
|
191
|
-
</div>
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
return renderFeature(data.name, data.value);
|
|
195
|
-
};
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### Why Proper Components
|
|
199
|
-
|
|
200
|
-
- Clear component interface (props)
|
|
201
|
-
- Easier to test
|
|
202
|
-
- Avoids stale closures
|
|
203
|
-
- Enables reusability
|
|
204
|
-
- Better React DevTools visibility
|
|
1
|
+
---
|
|
2
|
+
trigger: always_on
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# React Component Standards
|
|
6
|
+
|
|
7
|
+
## Component Architecture
|
|
8
|
+
|
|
9
|
+
### Separation of Concerns
|
|
10
|
+
|
|
11
|
+
- **Containers**: Connect to Redux, handle business logic, pass props to components
|
|
12
|
+
- **Components**: Pure presentational, receive data via props only
|
|
13
|
+
- **Utils**: Pure functions, no side effects, reusable across project
|
|
14
|
+
- **Selectors**: Data transformation and derivation from Redux state
|
|
15
|
+
- **Sagas**: Side effects and async operations
|
|
16
|
+
|
|
17
|
+
### Component Design Principles
|
|
18
|
+
|
|
19
|
+
- Keep components stateless whenever possible
|
|
20
|
+
- Single Responsibility Principle: One component, one purpose
|
|
21
|
+
- Composition over inheritance
|
|
22
|
+
- Allow containment through props.children
|
|
23
|
+
- No dependencies on rest of app outside props
|
|
24
|
+
|
|
25
|
+
## Functional vs Class Components
|
|
26
|
+
|
|
27
|
+
### Use Functional Components
|
|
28
|
+
|
|
29
|
+
- All new components must be functional with hooks
|
|
30
|
+
- Class components supported but not recommended
|
|
31
|
+
- Lifecycle methods replaced with useEffect
|
|
32
|
+
- Local state managed with useState
|
|
33
|
+
|
|
34
|
+
### Hooks Usage
|
|
35
|
+
|
|
36
|
+
#### Standard Hooks
|
|
37
|
+
|
|
38
|
+
- **useState**: Local UI state only
|
|
39
|
+
- **useEffect**: Side effects, subscriptions, API calls
|
|
40
|
+
- Be explicit with dependency array
|
|
41
|
+
- Return cleanup functions for subscriptions
|
|
42
|
+
- Avoid infinite loops by managing dependencies carefully
|
|
43
|
+
- **useMemo**: Expensive calculations only (don't overuse)
|
|
44
|
+
- **useCallback**: Prevent unnecessary child re-renders
|
|
45
|
+
- **useRef**: DOM access, storing mutable values that don't trigger re-renders
|
|
46
|
+
|
|
47
|
+
#### Custom Hooks
|
|
48
|
+
|
|
49
|
+
- Declare in `/hooks` directory or component-level
|
|
50
|
+
- Prefix with "use" (e.g., useFormValidation)
|
|
51
|
+
- Extract reusable stateful logic
|
|
52
|
+
- Return values and functions for component use
|
|
53
|
+
|
|
54
|
+
## JSX Standards
|
|
55
|
+
|
|
56
|
+
### What TO Put in JSX
|
|
57
|
+
|
|
58
|
+
- Presentational markup and structure
|
|
59
|
+
- Props destructuring and usage
|
|
60
|
+
- Conditional rendering (boolean only)
|
|
61
|
+
- Event handler bindings
|
|
62
|
+
- Component composition
|
|
63
|
+
- Rendering logic from props
|
|
64
|
+
|
|
65
|
+
### What NOT TO Put in JSX
|
|
66
|
+
|
|
67
|
+
- Business logic - belongs in selectors or utils
|
|
68
|
+
- API calls - belongs in sagas or useEffect
|
|
69
|
+
- Complex data transformations - belongs in selectors
|
|
70
|
+
- Direct DOM manipulation - use refs sparingly
|
|
71
|
+
- State mutations - use setState or Redux actions
|
|
72
|
+
|
|
73
|
+
### JSX Best Practices
|
|
74
|
+
|
|
75
|
+
- Destructure props at function signature: `const Component = ({prop1, prop2}) => {}`
|
|
76
|
+
- Return early for null/loading states
|
|
77
|
+
- Extract complex conditional JSX to separate components
|
|
78
|
+
- Use ternary or && for simple conditionals only
|
|
79
|
+
- Avoid inline functions in render (use useCallback)
|
|
80
|
+
- Add comments for unclear rendering logic only
|
|
81
|
+
|
|
82
|
+
## Props Management
|
|
83
|
+
|
|
84
|
+
### Props Access and Destructuring
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
// GOOD: Destructure at signature level
|
|
88
|
+
const Component = ({ title, onClick, children }) => {
|
|
89
|
+
return <button onClick={onClick}>{title}</button>;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// BAD: Accessing props object
|
|
93
|
+
const Component = (props) => {
|
|
94
|
+
return <button onClick={props.onClick}>{props.title}</button>;
|
|
95
|
+
};
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Prop Types
|
|
99
|
+
|
|
100
|
+
- Define PropTypes for ALL components
|
|
101
|
+
- Mark required props with .isRequired
|
|
102
|
+
- Use shape() for complex objects
|
|
103
|
+
- Extract shared PropTypes to shapes.js file
|
|
104
|
+
- Provide defaultProps for optional props
|
|
105
|
+
|
|
106
|
+
### Props Drilling
|
|
107
|
+
|
|
108
|
+
- Maximum 3 levels of prop drilling
|
|
109
|
+
- Beyong 3 levels: Create intermediate container
|
|
110
|
+
- Consider React Context for deep tree data
|
|
111
|
+
- Use Redux for truly global state
|
|
112
|
+
|
|
113
|
+
## Local State
|
|
114
|
+
|
|
115
|
+
### When to Use Local State
|
|
116
|
+
|
|
117
|
+
- UI-only concerns (modal open/closed, input focus)
|
|
118
|
+
- Temporary form data before submission
|
|
119
|
+
- Component-specific toggles and flags
|
|
120
|
+
- Animation states
|
|
121
|
+
|
|
122
|
+
### When NOT to Use Local State
|
|
123
|
+
|
|
124
|
+
- Data from API responses - use Redux
|
|
125
|
+
- Shared data between components - use Redux
|
|
126
|
+
- Form data managed by react-redux-form - use model
|
|
127
|
+
- Data that needs to persist across component unmounts
|
|
128
|
+
|
|
129
|
+
## Component Complexity
|
|
130
|
+
|
|
131
|
+
### When to Refactor
|
|
132
|
+
|
|
133
|
+
- Component exceeds well over 200 lines
|
|
134
|
+
- More than 10 props being passed
|
|
135
|
+
- Nested ternary operators (>2 levels)
|
|
136
|
+
- Duplicate logic across components
|
|
137
|
+
- Difficult to write tests for
|
|
138
|
+
|
|
139
|
+
### Refactoring Strategies
|
|
140
|
+
|
|
141
|
+
- Extract child components
|
|
142
|
+
- Create custom hooks for complex logic
|
|
143
|
+
- Move business logic to selectors
|
|
144
|
+
- Use composition with props.children
|
|
145
|
+
- Split container and presentational concerns
|
|
146
|
+
|
|
147
|
+
## DOM Access and Manipulation
|
|
148
|
+
|
|
149
|
+
### Avoid Direct DOM Manipulation
|
|
150
|
+
|
|
151
|
+
- Stay in React domain whenever possible
|
|
152
|
+
- Do NOT use document.querySelector
|
|
153
|
+
- Do NOT manipulate DOM with vanilla JS
|
|
154
|
+
- Use React refs only when necessary
|
|
155
|
+
|
|
156
|
+
### When to Use Refs
|
|
157
|
+
|
|
158
|
+
- Focus management
|
|
159
|
+
- Integration with third-party DOM libraries
|
|
160
|
+
- Measuring DOM nodes (scroll position, dimensions)
|
|
161
|
+
- Triggering imperative animations
|
|
162
|
+
|
|
163
|
+
### Ref Best Practices
|
|
164
|
+
|
|
165
|
+
- Use useRef hook in functional components
|
|
166
|
+
- Assign refs to DOM elements, not React components
|
|
167
|
+
- Access refs in useEffect or event handlers, not render
|
|
168
|
+
- Clean up refs in useEffect return function
|
|
169
|
+
|
|
170
|
+
## Methods Returning JSX
|
|
171
|
+
|
|
172
|
+
### Create Proper Components
|
|
173
|
+
|
|
174
|
+
```jsx
|
|
175
|
+
// GOOD: Separate component
|
|
176
|
+
const FeatureDisplay = ({ feature, value }) => (
|
|
177
|
+
<div>
|
|
178
|
+
{feature}: {value}
|
|
179
|
+
</div>
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
const ParentComponent = ({ data }) => (
|
|
183
|
+
<FeatureDisplay feature={data.name} value={data.value} />
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
// BAD: Method returning JSX
|
|
187
|
+
const ParentComponent = ({ data }) => {
|
|
188
|
+
const renderFeature = (name, value) => (
|
|
189
|
+
<div>
|
|
190
|
+
{name}: {value}
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
return renderFeature(data.name, data.value);
|
|
195
|
+
};
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Why Proper Components
|
|
199
|
+
|
|
200
|
+
- Clear component interface (props)
|
|
201
|
+
- Easier to test
|
|
202
|
+
- Avoids stale closures
|
|
203
|
+
- Enables reusability
|
|
204
|
+
- Better React DevTools visibility
|