Skip to content

Commit fd28063

Browse files
committed
docs: add rules for Cursor
1 parent 7b9d239 commit fd28063

File tree

8 files changed

+645
-0
lines changed

8 files changed

+645
-0
lines changed

.cursor/rules/architecture.mdc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
alwaysApply: true
3+
description: Project Overview
4+
---
5+
6+
# Project Overview
7+
8+
This project is a Rust library for formatting SQL queries. It is intended to support all mainstream SQL dialects. The crate exposes one interface for consumers, which is the `format` function exported at the top level of the crate.

.cursor/rules/code-testing.mdc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
description: Code Testing Best Practices
3+
alwaysApply: false
4+
---
5+
6+
# Code Testing Best Practices
7+
8+
## Test Structure & Organization
9+
10+
- Write descriptive test names that clearly explain what is being tested
11+
- Follow the AAA pattern: Arrange, Act, Assert
12+
- Group related tests together in logical test suites
13+
- Keep tests independent - each test should be able to run in isolation
14+
15+
## Test Coverage & Scope
16+
17+
- Write tests for both happy path and edge cases
18+
- Include tests for error conditions and invalid inputs
19+
- Test boundary conditions (empty strings, null values, maximum/minimum values)
20+
- All tests should have at least one assertion. Always use assertions instead of console logging to validate test results.
21+
- Aim for meaningful coverage, not just high percentage coverage
22+
23+
## Test Quality
24+
25+
- Keep tests simple and focused - test one thing at a time
26+
- Make tests deterministic - avoid randomness or time-dependent behavior
27+
- Use clear, descriptive assertions with helpful error messages
28+
- Avoid testing implementation details; focus on behavior and outcomes
29+
30+
## Test Data & Setup
31+
32+
- Use minimal test data that clearly demonstrates the test case
33+
- Create reusable test fixtures and helper functions for common setup
34+
- Clean up resources after tests (database records, files, network connections)
35+
- Use test doubles (mocks, stubs, fakes) to isolate units under test
36+
37+
## Performance & Maintenance
38+
39+
- Keep tests fast - slow tests discourage frequent running
40+
- Make tests easy to read and maintain
41+
- Remove or update obsolete tests when code changes
42+
- Run tests frequently during development
43+
44+
## Documentation & Communication
45+
46+
- Write tests that serve as documentation for expected behavior
47+
- Include comments for complex test logic or non-obvious test scenarios
48+
- Ensure test failures provide clear information about what went wrong
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
alwaysApply: true
3+
description: Guidelines for writing meaningful and maintainable code comments
4+
---
5+
6+
# Guidelines for writing meaningful and maintainable code comments
7+
8+
You are an expert in clean code practices, documentation, and code readability.
9+
10+
## When to Comment
11+
12+
- Explain WHY, not WHAT the code does
13+
- Document complex business logic or algorithms
14+
- Clarify non-obvious implementations
15+
- Warn about potential gotchas or side effects
16+
- Provide context for future maintainers
17+
18+
## Comment Types and Usage
19+
20+
### Good Comments
21+
22+
```javascript
23+
// Using exponential backoff to avoid overwhelming the API
24+
// during high traffic periods (see incident report #1234)
25+
const delay = Math.min(1000 * Math.pow(2, retryCount), 30000);
26+
27+
// WORKAROUND: Chrome bug #123456 requires explicit height
28+
// Remove when Chrome 120+ adoption reaches 95%
29+
element.style.height = "auto";
30+
31+
// Performance: Caching results reduces API calls by ~70%
32+
// based on production metrics from 2023-Q4
33+
const cachedResult = cache.get(key);
34+
```
35+
36+
### Bad Comments
37+
38+
```javascript
39+
// BAD: Obvious comment
40+
// Increment counter by 1
41+
counter++;
42+
43+
// BAD: Outdated comment
44+
// Send email to user (actually sends SMS now)
45+
await notificationService.send(user);
46+
47+
// BAD: Commented-out code without context
48+
// user.setStatus('active');
49+
// user.save();
50+
```
51+
52+
## Documentation Comments
53+
54+
### JavaScript/TypeScript
55+
56+
```typescript
57+
/**
58+
* Calculates compound interest with monthly contributions.
59+
* Uses the formula: A = P(1 + r/n)^(nt) + PMT × (((1 + r/n)^(nt) - 1) / (r/n))
60+
*
61+
* @param principal - Initial investment amount
62+
* @param rate - Annual interest rate (as decimal, e.g., 0.05 for 5%)
63+
* @param time - Investment period in years
64+
* @param contribution - Monthly contribution amount
65+
* @returns Total value after the investment period
66+
*
67+
* @example
68+
* // Calculate 10-year investment with 5% annual return
69+
* const total = calculateCompoundInterest(10000, 0.05, 10, 500);
70+
* console.log(total); // 96,859.57
71+
*/
72+
function calculateCompoundInterest(
73+
principal: number,
74+
rate: number,
75+
time: number,
76+
contribution: number
77+
): number {
78+
// Implementation
79+
}
80+
```
81+
82+
### Python
83+
84+
```python
85+
def process_transaction(transaction: Transaction) -> ProcessResult:
86+
"""
87+
Process a financial transaction with fraud detection and validation.
88+
89+
This method performs multiple checks before processing:
90+
1. Validates transaction format and required fields
91+
2. Checks against fraud detection rules
92+
3. Verifies account balance and limits
93+
4. Processes through payment gateway
94+
95+
Args:
96+
transaction: Transaction object containing payment details
97+
98+
Returns:
99+
ProcessResult with status and any error messages
100+
101+
Raises:
102+
ValidationError: If transaction format is invalid
103+
FraudException: If transaction triggers fraud rules
104+
InsufficientFundsError: If account balance is too low
105+
106+
Note:
107+
Transactions over $10,000 require additional verification
108+
per compliance policy FIN-2023-001.
109+
"""
110+
```
111+
112+
## TODO Comments
113+
114+
```python
115+
# TODO(john): Implement retry logic for network failures
116+
# TODO(security): Add rate limiting before v2.0 release
117+
# FIXME: Handle edge case when user has multiple accounts
118+
# HACK: Temporary fix until database migration completes
119+
```
120+
121+
## Best Practices
122+
123+
- Keep comments concise and relevant
124+
- Update comments when code changes
125+
- Use consistent comment style across the codebase
126+
- Avoid humor or cultural references that may not translate
127+
- Review comments during code reviews

.cursor/rules/github-actions.mdc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
alwaysApply: false
3+
description: Best practices for GitHub Actions workflows
4+
globs: .github/workflows/*.yml, .github/workflows/*.yaml
5+
---
6+
7+
# Best practices for GitHub Actions workflows
8+
9+
You are an expert in CI/CD, GitHub Actions, and DevOps automation.
10+
11+
## Workflow Structure
12+
13+
- Use descriptive workflow and job names
14+
- Organize workflows by purpose (ci.yml, deploy.yml, release.yml)
15+
- Implement proper job dependencies with needs
16+
- Use matrix builds for testing multiple versions
17+
- Keep workflows DRY using reusable workflows
18+
19+
## Security Best Practices
20+
21+
- Use GitHub Secrets for sensitive data
22+
- Implement least privilege for GITHUB_TOKEN permissions
23+
- Pin action versions to specific commits or tags
24+
- Use OIDC for cloud provider authentication
25+
- Scan for vulnerabilities in dependencies
26+
27+
## Performance Optimization
28+
29+
- Cache dependencies appropriately (npm, pip, etc.)
30+
- Use artifacts efficiently between jobs
31+
- Parallelize independent jobs
32+
- Implement conditional workflows to avoid unnecessary runs
33+
- Use concurrency groups to cancel outdated runs
34+
35+
## Error Handling
36+
37+
- Implement proper timeout values
38+
- Add retry logic for flaky steps
39+
- Use continue-on-error strategically
40+
- Create informative failure messages
41+
- Set up notifications for critical failures
42+
43+
## Best Practices
44+
45+
- Use composite actions for repeated tasks
46+
- Document workflows with comments
47+
- Implement branch protection rules
48+
- Use environments for deployment stages
49+
- Monitor workflow metrics and costs

.cursor/rules/project-readme.mdc

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
alwaysApply: false
3+
description: Guidelines for creating comprehensive project README files
4+
globs: README.md
5+
---
6+
7+
# Guidelines for creating comprehensive project README files
8+
9+
You are an expert in technical documentation, open source best practices, and developer experience.
10+
11+
## README Structure
12+
13+
A well-structured README should include these sections in order:
14+
15+
1. Project Title and Description
16+
2. Badges (build status, version, license)
17+
3. Key Features
18+
4. Screenshots/Demo (if applicable)
19+
5. Quick Start
20+
6. Installation
21+
7. Usage Examples
22+
8. API Reference (or link to docs)
23+
9. Configuration
24+
10. Contributing
25+
11. License
26+
27+
## Essential Sections
28+
29+
### Project Header
30+
31+
```markdown
32+
# Project Name
33+
34+
> One-line description of what this project does
35+
36+
[![Build Status](https://img.shields.io/github/actions/workflow/status/user/repo/ci.yml)](https://github.com/user/repo/actions)
37+
[![npm version](https://img.shields.io/npm/v/package-name)](https://www.npmjs.com/package/package-name)
38+
[![License](https://img.shields.io/github/license/user/repo)](LICENSE)
39+
40+
Brief paragraph explaining the project's purpose, main features, and why someone would want to use it.
41+
```
42+
43+
### Quick Start
44+
45+
```markdown
46+
## Quick Start
47+
48+
Get up and running in less than 5 minutes:
49+
50+
\`\`\`bash
51+
npm install package-name
52+
npm run dev
53+
\`\`\`
54+
55+
Visit http://localhost:3000 to see the application.
56+
```
57+
58+
### Installation
59+
60+
```markdown
61+
## Installation
62+
63+
### Prerequisites
64+
65+
- Node.js 18+
66+
- PostgreSQL 14+
67+
- Redis 6.2+
68+
69+
### Install from npm
70+
71+
\`\`\`bash
72+
npm install package-name
73+
\`\`\`
74+
75+
### Install from source
76+
77+
\`\`\`bash
78+
git clone https://github.com/user/repo.git
79+
cd repo
80+
npm install
81+
npm run build
82+
\`\`\`
83+
```
84+
85+
### Usage Examples
86+
87+
```markdown
88+
## Usage
89+
90+
### Basic Example
91+
92+
\`\`\`javascript
93+
import { Widget } from 'package-name';
94+
95+
const widget = new Widget({
96+
apiKey: 'your-api-key',
97+
theme: 'dark'
98+
});
99+
100+
widget.render('#app');
101+
\`\`\`
102+
103+
### Advanced Example
104+
105+
\`\`\`javascript
106+
// Custom configuration with error handling
107+
const widget = new Widget({
108+
apiKey: process.env.API_KEY,
109+
theme: 'dark',
110+
onError: (error) => {
111+
console.error('Widget error:', error);
112+
}
113+
});
114+
115+
// Add custom event handlers
116+
widget.on('ready', () => {
117+
console.log('Widget is ready');
118+
});
119+
120+
widget.render('#app');
121+
\`\`\`
122+
```
123+
124+
## Best Practices
125+
126+
- Keep the README focused and concise
127+
- Use clear, simple language
128+
- Include code examples that actually work
129+
- Add visuals when they help understanding
130+
- Link to more detailed documentation
131+
- Keep examples up-to-date with the code
132+
- Test your installation instructions regularly
133+
134+
## Common Mistakes to Avoid
135+
136+
- Don't assume reader knowledge
137+
- Don't skip the Quick Start section
138+
- Don't use jargon without explanation
139+
- Don't forget to update version numbers
140+
- Don't include sensitive information
141+
142+
## Formatting Tips
143+
144+
- Use consistent heading levels
145+
- Include a table of contents for long READMEs
146+
- Use code blocks with language highlighting
147+
- Add alt text to images
148+
- Use tables for comparing options
149+
- Include emoji sparingly and purposefully

0 commit comments

Comments
 (0)