Naming Conventions
This guide documents our established naming patterns across the codebase, with examples from our actual implementation.
Component Names
Section titled “Component Names”File Names
Section titled “File Names”components/ newsletterForm/ # camelCase for directories newsletterForm.tsx # camelCase.tsx for component files newsletterForm.test.ts # camelCase.test.ts for test files index.ts # index.ts for exports🤔 Why This Pattern?
- Consistent file organization
- Clear component boundaries
- Easy imports
- Testability focus
Component Functions
Section titled “Component Functions”// ✅ Do: PascalCase for component functionsexport function NewsletterForm(props: NewsletterFormProps) { // ...}
// ✅ Do: PascalCase for compound componentsNewsletterForm.Header = function NewsletterHeader() { // ...};
// ❌ Don't: camelCase for component functionsexport function newsletterForm() { // wrong // ...}State Management
Section titled “State Management”Signal Names
Section titled “Signal Names”// ✅ Do: Descriptive pairs with clear intentconst [isLoading, setIsLoading] = createSignal(false);const [activeTab, setActiveTab] = createSignal("overview");const [hasError, setHasError] = createSignal(false);
// ❌ Don't: Unclear or abbreviated namesconst [l, setL] = createSignal(false); // wrongconst [tab, setTab] = createSignal("overview"); // too vagueconst [error, setError] = createSignal(false); // prefer isError for booleansEvent Handlers
Section titled “Event Handlers”// ✅ Do: handle[Event] patternconst handleSubmit = (e: Event) => { // ...};
const handleTagClick = (tag: string) => { // ...};
// ❌ Don't: Inconsistent patternsconst submit = (e: Event) => { // wrong // ...};
const clickTag = (tag: string) => { // wrong // ...};GraphQL Operations
Section titled “GraphQL Operations”Query Files
Section titled “Query Files”pages/articles/[slug]/ _graphql/ page.query.graphql # Main query validate.query.graphql # Validation query api.ts # API functions transform.ts # Data transformationsFunction Names
Section titled “Function Names”// ✅ Do: Descriptive action-based namesexport async function getArticleBySlug(slug: string) { // ...}
export async function validateArticlePageAPI(slug: string) { // ...}
// ❌ Don't: Vague or inconsistent namesexport async function article(slug: string) { // wrong // ...}
export async function checkArticle(slug: string) { // wrong // ...}Utility Functions
Section titled “Utility Functions”Transform Functions
Section titled “Transform Functions”// ✅ Do: Clear transformation intentfunction formatReadingTime(minutes: number): string { return `${minutes} min read`;}
function transformArticleData(raw: RawArticle): Article { // ...}
// ❌ Don't: Ambiguous namesfunction format(minutes: number): string { // wrong // ...}
function articleTransform(raw: RawArticle): Article { // wrong // ...}Helper Functions
Section titled “Helper Functions”// ✅ Do: Action-based names for helpersfunction validateEmail(email: string): boolean { // ...}
function sanitizeHtml(content: string): string { // ...}
// ❌ Don't: Unclear purposefunction checkInput(value: string): boolean { // wrong // ...}
function clean(content: string): string { // wrong // ...}Constants and Types
Section titled “Constants and Types”Constants
Section titled “Constants”// ✅ Do: UPPER_SNAKE_CASE for constantsexport const MAX_ITEMS_PER_PAGE = 20;export const DEFAULT_LOCALE = "en-US";
// ❌ Don't: Inconsistent casingexport const maxItemsPerPage = 20; // wrongexport const DefaultLocale = "en-US"; // wrongTypes and Interfaces
Section titled “Types and Interfaces”// ✅ Do: PascalCase for types/interfacesexport interface ArticleProps { title: string; content: string;}
export type LoadingState = "idle" | "loading" | "error" | "success";
// ❌ Don't: Non-PascalCaseexport interface articleProps { // wrong // ...}
export type loadingState = "idle" | "loading"; // wrongBest Practices
Section titled “Best Practices”-
Consistency
- Follow established patterns
- Use consistent casing
- Match file names to exports
- Group related names
-
Clarity
- Use descriptive names
- Avoid abbreviations
- Indicate boolean nature
- Show clear intent
-
Organization
- Group related files
- Use consistent directory structure
- Follow component boundaries
- Maintain test naming
-
Documentation
- Document unusual names
- Explain abbreviations
- Note naming patterns
- Keep README updated
Decision Checklist
Section titled “Decision Checklist”When naming new code elements, ask:
-
Component Names
- Is it PascalCase?
- Does it match the file name?
- Is it descriptive?
- Does it follow team patterns?
-
Function Names
- Does it describe the action?
- Is it consistently cased?
- Is it clear and specific?
- Does it match similar functions?
-
File Structure
- Does it follow directory patterns?
- Are test files named correctly?
- Are GraphQL files organized?
- Is the index.ts present?
-
State and Props
- Are signal pairs clear?
- Do boolean names indicate state?
- Are prop names consistent?
- Are types properly cased?