Skip to content

Commit c659e87

Browse files
authored
chore: Add cursor rules. (#864)
Adds an initial set of cursor rules. These rules can be changes if issues are encountered. The goal is to make cursor more adept at working in this repository.
1 parent 99af055 commit c659e87

File tree

5 files changed

+195
-0
lines changed

5 files changed

+195
-0
lines changed

.cursor/rules/dependencies.mdc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
description: Rules about dependencies.
3+
globs: *
4+
alwaysApply: true
5+
---
6+
# Dependency Management Guidelines
7+
8+
## General Principles
9+
- Dependencies should be avoided unless absolutely necessary
10+
- Consider the following factors when evaluating dependencies:
11+
- Size: Impact on final bundle size (especially important for browser SDK)
12+
- Maintenance: Risk of becoming unmaintained or deprecated
13+
- Security: Potential security vulnerabilities
14+
- Compatibility: Support across all target platforms
15+
- Conflicts: Potential conflicts with application dependencies
16+
17+
## Package-Specific Guidelines
18+
- Most important to avoid dependencies in:
19+
- common package
20+
- sdk-client package
21+
- sdk-server package
22+
- Individual SDK packages may have specific platform dependencies
23+
- Edge SDKs must use their provider's edge store and may require specific dependencies
24+
25+
## Dependency Selection Criteria
26+
- Only use dependencies for functionality with:
27+
- Highly-specified behavior
28+
- Wide usage
29+
- Active maintenance
30+
- Large community support

.cursor/rules/development.mdc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
description: Rules for building and understanding the repository.
3+
globs: *
4+
alwaysApply: true
5+
---
6+
# General Development Guidelines
7+
8+
## Project Structure
9+
- This is a monorepo containing multiple JavaScript SDK packages
10+
- Packages are organized into categories:
11+
- Shared packages (common code)
12+
- SDK packages (platform-specific implementations)
13+
- Store packages (persistent storage)
14+
- Telemetry packages (monitoring)
15+
- Tooling packages (development tools)
16+
17+
## Build Requirements
18+
- Node environment version 16 required, this is a minimum.
19+
- yarn required
20+
- Some projects may have specific environment prerequisites
21+
22+
## Build Process
23+
- Use `yarn` to install dependencies from project root
24+
- Use `yarn build` to build all projects
25+
- For single project builds:
26+
```
27+
yarn workspaces foreach -pR --topological-dev --from '@launchdarkly/js-client-sdk' run build
28+
```
29+
- Replace package name as needed
30+
- Running `yarn build` in individual packages won't rebuild dependencies

.cursor/rules/linting.mdc

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
description: Rules for finding and addressing linting issues.
3+
globs: *.ts
4+
alwaysApply: true
5+
---
6+
# Linting Guidelines
7+
8+
## Running Lint Checks
9+
10+
Lint checks can be run for any package using the following command:
11+
12+
```bash
13+
yarn workspace <package name> lint
14+
```
15+
16+
For example, to lint the common SDK package:
17+
18+
```bash
19+
yarn workspace @launchdarkly/js-sdk-common lint
20+
```
21+
22+
## Fixing Lint Issues
23+
24+
Many lint issues can be automatically fixed using the `--fix` flag:
25+
26+
```bash
27+
yarn workspace <package name> lint --fix
28+
```
29+
30+
For example:
31+
32+
```bash
33+
yarn workspace @launchdarkly/js-sdk-common lint --fix
34+
```
35+
36+
## Manual Fixes
37+
38+
If automatic fixes don't resolve all issues, you should fix them manually. Pay special attention to:
39+
40+
- TypeScript type errors
41+
- ESLint rule violations
42+
- Code style inconsistencies
43+
44+
## Mock Type Handling
45+
46+
When working with mocks in tests, it's acceptable to use ESLint ignore or TypeScript ignore comments if typing issues arise. This is only appropriate for test mocks, not for implementation code.
47+
48+
Example:
49+
50+
```typescript
51+
// @ts-ignore - Mock implementation doesn't need full typing
52+
const mockClient = {
53+
// mock implementation
54+
};
55+
```
56+
57+
## Package Names
58+
59+
Package names can be found in the respective `package.json` files. Always use the exact package name as specified there when running lint commands.
60+
61+
## When to Run Lint
62+
63+
- Run lint checks on any package you've modified

.cursor/rules/testing.mdc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
description: Rules for running and developing tests.
3+
globs: *
4+
alwaysApply: true
5+
---
6+
# Testing Guidelines
7+
8+
## Test Structure
9+
- Unit tests should be implemented in a `__tests__` folder in the root of the package
10+
- The directory structure inside of `__tests__` should mirror that of the source directory
11+
- Tests should only be run for single projects
12+
13+
## Test Naming and Organization
14+
- Test cases should be written using `it` and should read as a sentence including the `it`
15+
- Example: `it('does not load flags prior to start', async () => {/* test code */})`
16+
- Describe blocks should ONLY be used for common setup for a series of tests
17+
- Example: `describe('given a mock filesystem and memory feature store', { /* tests */})`
18+
- If there is no shared configuration, do not use a describe block
19+
- Combined test names should be understandable: `given a mock filesystem and memory feature store > it does not load flags prior to start`
20+
21+
- Example of proper describe usage:
22+
```javascript
23+
describe('given a mock filesystem and memory feature store', () => {
24+
// Shared setup code here
25+
26+
it('does not load flags prior to start', async () => {
27+
// Test code
28+
});
29+
30+
it('loads flags after start', async () => {
31+
// Test code
32+
});
33+
});
34+
```
35+
- Example of when not to use describe:
36+
```javascript
37+
// No shared configuration, so no describe block needed
38+
it('returns true when flag is enabled', () => {
39+
// Test code
40+
});
41+
42+
it('returns false when flag is disabled', () => {
43+
// Test code
44+
});
45+
```
46+
47+
## Running Tests
48+
- Tests should be run using `yarn workspace <package name> test`
49+
- The package name can be found in the package.json file
50+
- Unit tests should be run for any packages that have been modified
51+
52+

.cursor/rules/typescript.mdc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
description: Rules for typescript development.
3+
globs: *.ts
4+
alwaysApply: true
5+
---
6+
# TypeScript Guidelines
7+
8+
## TypeScript vs JavaScript
9+
- While we develop in TypeScript, aim for compiled JavaScript to not be substantially different than if written as JavaScript
10+
- Consider JavaScript consumers when making TypeScript decisions
11+
12+
## TypeScript Best Practices
13+
- Avoid using TypeScript enumerations. Instead use unions of strings
14+
- Bad: `enum ValueType { Bool = 'bool', Int = 'int' }`
15+
- Good: `type ValueType = 'bool' | 'int'`
16+
- Prefer interfaces over classes when reasonable, especially if publicly exposed
17+
- Bad: Using classes for simple data structures
18+
- Good: Using interfaces with factory functions
19+
- Remember that `private` and `readonly` only affect TypeScript - JavaScript can still access and mutate
20+
- For private members that need to be minified, prefix with underscore

0 commit comments

Comments
 (0)