Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .cursor/rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"rules": [
{
"path": "core.mdc",
"globs": ["src/**/*.ts", "!src/**/*.test.ts", "!src/**/*.spec.ts"],
"description": "Core project overview and development guidelines"
},
{
"path": "generators.mdc",
"globs": ["src/codegen/generators/**/*.ts"],
"description": "Generator implementation patterns and requirements"
},
{
"path": "inputs.mdc",
"globs": ["src/codegen/inputs/**/*.ts"],
"description": "Input processing patterns and requirements"
},
{
"path": "quality.mdc",
"globs": ["src/**/*.ts", "!src/**/*.test.ts", "!src/**/*.spec.ts"],
"description": "Code quality, security, and performance standards"
},
{
"path": "testing.mdc",
"globs": ["test/**/*.ts", "test/**/*.js", "test/**/*.spec.ts", "test/**/*.test.ts"],
"description": "Testing strategies and requirements"
},
{
"path": "core.mdc",
"globs": ["src/codegen/types.ts", "src/codegen/configurations.ts"],
"description": "Core type definitions and configuration management"
},
{
"path": "instructions.mdc",
"globs": ["test/blackbox/**/*.ts", "test/blackbox/**/*.js"],
"description": "Blackbox testing guidance and workflows"
},
{
"path": "instructions.mdc",
"globs": ["test/runtime/**/*.ts", "test/runtime/**/*.js"],
"description": "Runtime testing guidance and workflows"
},
{
"path": "core.mdc",
"globs": ["src/commands/**/*.ts"],
"description": "CLI command implementation patterns"
},
{
"path": "instructions.mdc",
"globs": ["examples/**/*.js", "examples/**/*.mjs", "examples/**/*.ts"],
"description": "Example project configuration guidance"
},
{
"path": "core.mdc",
"globs": ["docs/**/*.md"],
"description": "Documentation standards and requirements"
},
{
"path": "instructions.mdc",
"globs": ["scripts/**/*.js", "scripts/**/*.ts"],
"description": "Build and utility script guidance"
},
{
"path": "core.mdc",
"globs": ["schemas/**/*.json"],
"description": "JSON schema management patterns"
}
]
}
237 changes: 237 additions & 0 deletions .cursor/rules/code-style.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
# Code Style and API Design Rules

## Object Parameters Pattern (MANDATORY)

### **ALWAYS Use Object Parameters for Functions with Multiple Parameters**

**RULE**: When a function has 2 or more parameters, especially callback functions, use object parameters instead of positional parameters.

#### ✅ **GOOD: Object Parameters**
```typescript
// Callback functions
callback: (params: {error?: Error, data?: SomeType, metadata?: MetaType}) => void

// Regular functions
function processMessage({
message,
headers,
options,
skipValidation = false
}: {
message: MessageType;
headers?: HeaderType;
options: ProcessOptions;
skipValidation?: boolean;
}) {
// Implementation
}

// Function calls
processMessage({
message: myMessage,
headers: myHeaders,
options: { timeout: 5000 },
skipValidation: true
});
```

#### ❌ **BAD: Positional Parameters**
```typescript
// Callback functions
callback: (error?: Error, data?: SomeType, metadata?: MetaType) => void

// Regular functions
function processMessage(
message: MessageType,
headers?: HeaderType,
options: ProcessOptions,
skipValidation: boolean = false
) {
// Implementation
}

// Function calls
processMessage(myMessage, myHeaders, { timeout: 5000 }, true);
```

### **Benefits of Object Parameters**

1. **Self-Documenting**: Parameter names are explicit at call site
2. **Maintainable**: Adding parameters doesn't break existing calls
3. **Type Safe**: TypeScript provides better intellisense and validation
4. **Flexible**: Optional parameters can be omitted naturally
5. **Readable**: Clear intent at both definition and usage sites

### **When Object Parameters Are REQUIRED**

- ✅ **Callback functions** with multiple parameters
- ✅ **Generator functions** with configuration options
- ✅ **API functions** with more than 2 parameters
- ✅ **Event handlers** with multiple data points
- ✅ **Validation functions** with options and data
- ✅ **Protocol functions** (publish/subscribe) with headers, options, etc.

### **Exceptions (Use Positional Parameters)**

- ✅ **Single parameter functions**: `validate(data)`
- ✅ **Simple utility functions**: `pascalCase(str)`
- ✅ **Mathematical operations**: `add(a, b)`
- ✅ **Constructor-like functions**: `new User(id, name)` (but prefer object for 3+ params)

### **Migration Strategy for Existing Code**

When updating existing functions to use object parameters:

1. **Update the function signature** to accept an object
2. **Update all function calls** to use object syntax
3. **Update JSDoc** to reflect new parameter structure
4. **Update tests** to use new calling convention
5. **Regenerate code** if it's generator-produced
6. **Run tests** to ensure compatibility

### **Generator Implementation Requirements**

All code generators MUST follow object parameter patterns:

```typescript
// Generator function signatures
export function renderSomeFunction({
topic,
messageType,
channelParameters,
channelHeaders,
functionName,
payloadGenerator
}: RenderParameters): SingleFunctionRenderType {
// Implementation
}

// Generated callback signatures
const callbackType = `callback: (params: {${parameterList}}) => void`;

// Generated function calls
const functionCall = `callback({error: undefined, data: result, metadata: meta});`;
```

### **Testing Requirements**

All tests MUST use object parameter patterns:

```typescript
// Test callback usage
it('should handle callback with object parameters', () => {
const callback = ({error, data, headers}) => {
expect(error).toBeUndefined();
expect(data).toBeDefined();
expect(headers?.someHeader).toEqual('expected-value');
};

someFunction({
message: testMessage,
headers: testHeaders,
callback
});
});
```

### **Documentation Requirements**

- **JSDoc**: Document object parameter structure clearly
- **Examples**: Always show object parameter usage in examples
- **Migration Notes**: Document any breaking changes from positional to object parameters

### **Enforcement**

- **Code Reviews**: Reject PRs that introduce new positional parameter patterns
- **Linting**: Configure ESLint rules to prefer object parameters where applicable
- **Testing**: Ensure all tests use object parameter patterns
- **Generation**: All generators must produce object parameter code

## Function Naming Conventions

### **Callback Parameter Names**

Use consistent naming for callback parameters:

- **Error**: `error` (not `err` unless legacy compatibility required)
- **Data/Message**: Use descriptive names like `message`, `data`, `result`
- **Metadata**: Use specific names like `headers`, `options`, `metadata`
- **Protocol-specific**: Use protocol conventions like `amqpMsg`, `kafkaMessage`

### **Function Parameter Names**

Use descriptive, unabbreviated names:

- ✅ `message` (not `msg`)
- ✅ `headers` (not `hdrs`)
- ✅ `options` (not `opts`)
- ✅ `parameters` (not `params` unless in callback context)
- ✅ `callback` (not `cb`)

## Type Safety Requirements

### **Strict Typing for Object Parameters**

Always provide explicit types for object parameters:

```typescript
// REQUIRED: Explicit interface or inline type
interface ProcessMessageParams {
message: MessageType;
headers?: HeaderType;
options: ProcessOptions;
skipValidation?: boolean;
}

function processMessage(params: ProcessMessageParams) {
// Implementation
}

// OR inline type (for smaller functions)
function processMessage({
message,
headers,
options,
skipValidation = false
}: {
message: MessageType;
headers?: HeaderType;
options: ProcessOptions;
skipValidation?: boolean;
}) {
// Implementation
}
```

### **Default Values**

Provide default values in the destructuring assignment:

```typescript
function processMessage({
message,
headers,
options = {},
skipValidation = false,
timeout = 5000
}: ProcessMessageParams) {
// Implementation uses defaults automatically
}
```

## Consistency Requirements

### **Project-Wide Consistency**

- **All new code** MUST use object parameters for multi-parameter functions
- **All generators** MUST produce object parameter code
- **All tests** MUST use object parameter patterns
- **All examples** MUST demonstrate object parameter usage

### **Legacy Code**

- **Existing code** should be migrated to object parameters when modified
- **Breaking changes** should be documented in migration guides
- **Backward compatibility** may be maintained during transition periods

This rule ensures consistency, maintainability, and readability across the entire codebase.
Loading
Loading