Skip to content

Commit cce224d

Browse files
committed
added cursor rules
1 parent 3bf0c83 commit cce224d

File tree

11 files changed

+264
-1
lines changed

11 files changed

+264
-1
lines changed

packages/pwa-kit-create-app/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## v3.12.0-dev.0
2-
- Add development guidelines and create page Cursor rules for generated project
2+
- Add development guidelines and create page Cursor rules for generated project [2786](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2786)
33

44
## v3.11.0-dev.0 (May 23, 2025)
55
- Fix exiting before `program.json` content can be flushed [#2699](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2699)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
description: Check and verify accessibility on local project
3+
globs:
4+
alwaysApply: false
5+
---
6+
To check accessibility of a project, use the accessibility rules defined in PROJECT_ROOT/.cursor/rules/cursor-accessibility-mdc/ directory.
7+
Run an automated scan for the entire codebase within the project and check for any violations.
8+
Show the scanned results in summary and detailed violations if any.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
description: When accessibility is checked. Check if Buttons must have a discernible name using text or aria attributes
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
# Rule: accessibility-button-name
8+
9+
Buttons must have a discernible name using text or aria attributes
10+
11+
## 🔍 Pattern
12+
13+
```regex
14+
<button(?![^>]*\b(aria-label|aria-labelledby|title|name)=)
15+
```
16+
17+
## 📍 Examples
18+
19+
```tsx
20+
// ❌ Bad
21+
<button></button>
22+
// ✅ Good
23+
<button>Submit</button>
24+
// ✅ Good
25+
<button aria-label="Close dialog"><XIcon /></button>
26+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
description: When accessibility is checked. Check if heading levels should increase sequentially for semantic structure
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
# Rule: accessibility-heading-order
8+
9+
Heading levels should increase sequentially for semantic structure
10+
11+
## 🔍 Pattern
12+
13+
```regex
14+
<h([3-6])>
15+
```
16+
17+
## 📍 Examples
18+
19+
```tsx
20+
// ❌ Bad
21+
<h1>Main Title</h1>
22+
<h4>Subsection</h4>
23+
// ✅ Good
24+
<h1>Main Title</h1>
25+
<h2>Subsection</h2>
26+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
description: When accessibility is checked. Ensure all <img> tags include descriptive alt attributes
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
# Rule: accessibility-image-alt
8+
9+
Ensure all <img> tags include descriptive alt attributes
10+
11+
## 🔍 Pattern
12+
13+
```regex
14+
<img(?![^>]*\balt=)
15+
```
16+
17+
## 📍 Examples
18+
19+
```tsx
20+
// ❌ Bad
21+
<img src="photo.jpg" />
22+
// ✅ Good
23+
<img src="photo.jpg" alt="Company logo" />
24+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
description: When accessibility is checked. Check if Input fields must have a label or aria-label for screen readers
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
# Rule: accessibility-input-label
8+
9+
Input fields must have a label or aria-label for screen readers
10+
11+
## 🔍 Pattern
12+
13+
```regex
14+
<input(?![^>]*(aria-label|aria-labelledby|id=))
15+
```
16+
17+
## 📍 Examples
18+
19+
```tsx
20+
// ❌ Bad
21+
<input type="text" />
22+
// ✅ Good
23+
<input aria-label="Search" />
24+
// ✅ Good with label
25+
<label htmlFor="email">Email</label>
26+
<input id="email" type="text" />
27+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
description: When accessibility is checked. Check if Anchor tags must have accessible names
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
# Rule: accessibility-link-name
8+
9+
Anchor tags must have accessible names
10+
11+
## 🔍 Pattern
12+
13+
```regex
14+
<a(?![^>]*\b(aria-label|aria-labelledby|title)=)(?![^>]*>\s*\w+\s*</a>)
15+
```
16+
17+
## 📍 Examples
18+
19+
```tsx
20+
// ❌ Bad
21+
<a href="/profile"></a>
22+
// ✅ Good
23+
<a href="/profile">Your Profile</a>
24+
// ✅ Good
25+
<a href="/profile" aria-label="Profile page"><UserIcon /></a>
26+
```
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
description: How to add or edit Cursor rules in our project
3+
globs:
4+
alwaysApply: false
5+
---
6+
# Cursor Rules Location
7+
8+
How to add new cursor rules to the project
9+
10+
1. Always place rule files in PROJECT_ROOT/.cursor/rules/:
11+
```
12+
.cursor/rules/
13+
├── your-rule-name.mdc
14+
├── another-rule.mdc
15+
└── ...
16+
```
17+
18+
2. Follow the naming convention:
19+
- Use kebab-case for filenames
20+
- Always use .mdc extension
21+
- Make names descriptive of the rule's purpose
22+
23+
3. Directory structure:
24+
```
25+
PROJECT_ROOT/
26+
├── .cursor/
27+
│ └── rules/
28+
│ ├── your-rule-name.mdc
29+
│ └── ...
30+
└── ...
31+
```
32+
33+
4. Never place rule files:
34+
- In the project root
35+
- In subdirectories outside .cursor/rules
36+
- In any other location
37+
38+
5. Cursor rules have the following structure:
39+
40+
````
41+
---
42+
description: Short description of the rule's purpose
43+
globs: optional/path/pattern/**/*
44+
alwaysApply: false
45+
---
46+
# Rule Title
47+
48+
Main content explaining the rule with markdown formatting.
49+
50+
1. Step-by-step instructions
51+
2. Code examples
52+
3. Guidelines
53+
54+
Example:
55+
```typescript
56+
// Good example
57+
function goodExample() {
58+
// Implementation following guidelines
59+
}
60+
61+
// Bad example
62+
function badExample() {
63+
// Implementation not following guidelines
64+
}
65+
```
66+
````
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
description: Salesforce Commerce Composable Storefront Development Guidelines
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
# Commerce Composable Storefront Development Guidelines
8+
9+
## Overview
10+
Guidelines for Salesforce Commerce Composable Storefront development using PWA Kit, Retail React App, and Chakra UI.
11+
12+
## Core Principles
13+
- Analyze requirements and existing codebase thoroughly
14+
- Use existing components and hooks when possible
15+
- Plan before implementing
16+
- Test comprehensively with Jest
17+
18+
## PWA Kit Essentials
19+
20+
### Architecture
21+
- Server-side rendering (SSR) for initial loads
22+
- Client-side rendering (CSR) for interactions
23+
- Isomorphic code (works on server and client)
24+
- Proxy requests via `/mobify/proxy/<PROXY_PATH>`
25+
26+
### Special Components
27+
- Components starting with `_` are special PWA Kit components
28+
- `_app-config`: Top-level app configuration
29+
- `_app`: Persistent layout (header, footer, sidebar)
30+
- `_error`: 404 and error pages
31+
32+
## Development Rules
33+
- Use kebab-case for file names (except special components with `_`)
34+
- Use Chakra UI and existing components
35+
- Create modular, reusable components
36+
- Use React Hooks for state management
37+
- Access data via commerce-sdk-react hooks
38+
- Ensure mobile-friendly and accessible components
39+
- Maintain consistent code formatting using project standards
40+
- Write comprehensive test coverage
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
description: Page Creation Rule - automatically apply when user asks to create new page, add page, make page, build page, generate page
3+
globs:
4+
alwaysApply: false
5+
---
6+
USE WHEN create a new page, add a new page, make a new page, build a new page, generate a new page, create page, add page, make page, build page, generate page
7+
8+
**Mandatory**
9+
- DO ask user to clarify page name and page route before proceed
10+
- ONLY Create a bare minimum page component
11+
- Do NOT include other project components or hooks unless specifically requested
12+
- Do NOT add extra styling, layout, or features unless explicitly asked
13+
14+
## Implementation Steps
15+
1. Create simple component in `app/pages/[page-name]/index.jsx`
16+
2. Add route to `app/routes.jsx`

0 commit comments

Comments
 (0)