Cursor rule
.cursor/rules/typescript.mdcTypeScript strict mode standards and naming conventions
Cursor rules
Quality
70/100
Scores the file, not the repository.Length
724 words
33 headings · 17 code blocksRepository
14
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1234567# TypeScript Standards89## Configuration1011### Standard Configuration (All Packages)12```json13{14 "compilerOptions": {15 "declaration": true,16 "importHelpers": true,17 "module": "commonjs",18 "outDir": "lib",19 "rootDir": "src",20 "strict": false, // Relaxed for compatibility21 "target": "es2017",22 "sourceMap": false,23 "allowJs": true, // Mixed JS/TS support24 "skipLibCheck": true,25 "esModuleInterop": true26 },27 "include": ["src/**/*"]28}29```3031### Root Configuration32```json33// tsconfig.json - Baseline configuration34{35 "compilerOptions": {36 "strict": false,37 "module": "commonjs",38 "target": "es2017",39 "declaration": true,40 "outDir": "lib",41 "rootDir": "src"42 }43}44```4546## Naming Conventions (Actual Usage)4748### Files49- **Primary pattern**: `kebab-case.ts` (e.g., `base-command.ts`, `config-handler.ts`)50- **Single-word modules**: `index.ts`, `types.ts`51- **Commands**: Follow OCLIF topic structure (`cm/auth/login.ts`, `cm/config/region.ts`)5253### Classes54```typescript55// ✅ GOOD - PascalCase for classes56export default class ConfigCommand extends Command { }57export class AuthService { }58export class ValidationError extends Error { }59```6061### Functions and Methods62```typescript63// ✅ GOOD - camelCase for functions64export async function loadConfig(): Promise<Config> { }65async validateInput(input: string): Promise<boolean> { }66createCommandContext(): CommandContext { }67```6869### Constants70```typescript71// ✅ GOOD - SCREAMING_SNAKE_CASE for constants72const DEFAULT_REGION = 'us';73const MAX_RETRIES = 3;74const API_BASE_URL = 'https://api.contentstack.io';75```7677### Interfaces and Types78```typescript79// ✅ GOOD - PascalCase for types80export interface CommandConfig {81 region: string;82 alias?: string;83}8485export type CommandResult = {86 success: boolean;87 message?: string;88};89```9091## Import/Export Patterns9293### ES Modules (Preferred)94```typescript95// ✅ GOOD - ES import/export syntax96import { Command } from '@oclif/core';97import type { CommandConfig } from '../types';98import { loadConfig } from '../utils';99100export default class ConfigCommand extends Command { }101export { CommandConfig };102```103104### Default Exports105```typescript106// ✅ GOOD - Default export for commands and main classes107export default class ConfigCommand extends Command { }108```109110### Named Exports111```typescript112// ✅ GOOD - Named exports for utilities and types113export async function delay(ms: number): Promise<void> { }114export interface CommandOptions { }115export type ActionResult = 'success' | 'failure';116```117118## Type Definitions119120### Local Types121```typescript122// ✅ GOOD - Define types close to usage123export interface AuthOptions {124 email: string;125 password: string;126 token?: string;127}128129export type ConfigResult = {130 success: boolean;131 config?: Record<string, unknown>;132};133```134135### Type Organization136```typescript137// ✅ GOOD - Organize types in dedicated files138// src/types/index.ts139export interface CommandConfig { }140export interface AuthConfig { }141export type ConfigValue = string | number | boolean;142```143144## Null Safety145146### Function Return Types147```typescript148// ✅ GOOD - Explicit return types149export async function getConfig(): Promise<CommandConfig> {150 return await this.loadFromFile();151}152153export function createDefaults(): CommandConfig {154 return {155 region: 'us',156 timeout: 30000,157 };158}159```160161### Null/Undefined Handling162```typescript163// ✅ GOOD - Handle null/undefined explicitly164function processConfig(config: CommandConfig | null): void {165 if (!config) {166 throw new Error('Configuration is required');167 }168 // Process config safely169}170```171172## Error Handling Types173174### Custom Error Classes175```typescript176// ✅ GOOD - Typed error classes177export class ValidationError extends Error {178 constructor(179 message: string,180 public readonly code?: string181 ) {182 super(message);183 this.name = 'ValidationError';184 }185}186```187188### Error Union Types189```typescript190// ✅ GOOD - Model expected errors191type AuthResult<T> = {192 success: true;193 data: T;194} | {195 success: false;196 error: string;197};198```199200## Strict Mode Adoption201202### Current Status203- Most packages use `strict: false` for compatibility204- Gradual migration path available205- Team working toward stricter TypeScript206207### Gradual Adoption208```typescript209// ✅ ACCEPTABLE - Comments for known issues210// TODO: Fix type issues in legacy code211const legacyData = unknownData as unknown;212```213214## Package-Specific Patterns215216### Command Packages (auth, config)217- Extend `@oclif/core` Command218- Define command flags with `static flags`219- Use @oclif/core flag utilities220- Define command-specific types221222### Library Packages (command, utilities)223- No OCLIF dependencies224- Pure TypeScript interfaces225- Consumed by command packages226- Focus on type safety for exports227228### Main Package (contentstack)229- Aggregates command plugins230- May have common types231- Shared interfaces for plugin integration232233## Export Patterns234235### Package Exports (lib/index.js)236```typescript237// ✅ GOOD - Barrel exports for libraries238export { Command } from './command';239export { loadConfig } from './config';240export type { CommandConfig, AuthOptions } from './types';241```242243### Entry Points244- Libraries export from `lib/index.js`245- Commands export directly as default classes246- Type definitions included via `types` field in package.json247
Also in contentstack/cli
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| contentstack/cli.cursor/rules/contentstack-core.mdc · 14 | Cursor rules | buildteststylearch+3 | 69/100 | 3 days ago | |
| contentstack/cli.cursor/rules/oclif-commands.mdc · 14 | Cursor rules | setupteststylearch | 74/100 | 3 days ago | |
| contentstack/cli.cursor/rules/testing.mdc · 14 | Cursor rules | setupteststylearch+3 | 89/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
