Naming Conventions
This guide outlines the standard naming conventions used in our codebase to maintain consistency and readability.
Variables
- Use camelCase for variable names
- Choose descriptive names that indicate the purpose
- Avoid single-letter names except for loops
// Good
const firstName = 'John';
const userAge = 25;
const isActive = true;
// Bad
const fn = 'John';
const a = 25;
const flag = true;
Functions
- Use camelCase for function names
- Start with a verb that describes the action
- Be specific about what the function does
// Good
function calculateTotalPrice() { }
function getUserById() { }
function validateEmail() { }
// Bad
function price() { }
function user() { }
function check() { }
Classes
- Use PascalCase for class names
- Use nouns or noun phrases
- Be descriptive and specific
// Good
class UserProfile { }
class PaymentProcessor { }
class DatabaseConnection { }
// Bad
class Data { }
class Process { }
class Handler { }
Constants
- Use UPPER_SNAKE_CASE for constant names
- Use meaningful names that describe the value
// Good
const MAX_RETRY_ATTEMPTS = 3;
const API_BASE_URL = 'https://api.example.com';
const DEFAULT_TIMEOUT = 5000;
// Bad
const MAX = 3;
const URL = 'https://api.example.com';
const TIME = 5000;
File Names
- Use kebab-case for file names
- Be descriptive and indicate the file's purpose
// Good
user-profile.component.ts
payment-service.ts
database-config.ts
// Bad
userprofile.ts
payment.ts
config.ts
Interfaces and Types
- Use PascalCase
- Prefix interfaces with 'I' (optional)
- Be descriptive about the structure
// Good
interface IUserData { }
type ResponsePayload = { }
interface ApiResponse { }
// Bad
interface data { }
type resp = { }
Testing Files
- Add
.test
or.spec
before the file extension - Match the name of the file being tested
// Good
user-service.test.ts
payment-processor.spec.ts
// Bad
test.ts
user.test.ts
Edit this file on GitHub