Back to all reviewers

Names reveal semantic purpose

microsoft/typescript
Based on 7 comments
Typescript

Choose names that clearly communicate the semantic purpose and behavior of code elements. Variable and function names should precisely reflect their role, return type, and intended usage.

Naming Conventions Typescript

Reviewer Prompt

Choose names that clearly communicate the semantic purpose and behavior of code elements. Variable and function names should precisely reflect their role, return type, and intended usage.

Key guidelines:

  1. Function names should indicate their behavior and return type
  2. Use distinct names for related but different concepts
  3. Choose specific over generic names
  4. Fix misleading names immediately

Example:

// Poor naming
function isGlobalType(checker: TypeChecker, symbol: Symbol) {
    return checker.resolveName(symbol.name, undefined, SymbolFlags.Type, false);
}

// Better naming - reflects actual behavior
function canResolveTypeGlobally(checker: TypeChecker, typeName: string) {
    return checker.resolveName(typeName, undefined, SymbolFlags.Type, false);
}

// Poor naming - reusing variable
let initializer = getCandidateVariableDeclarationInitializer(declaration);
if (initializer) { ... }
initializer = getDestructuredInitializer(declaration);

// Better naming - distinct purposes
let directInit = getCandidateVariableDeclarationInitializer(declaration);
if (directInit) { ... }
let destructuredInit = getDestructuredInitializer(declaration);
7
Comments Analyzed
Typescript
Primary Language
Naming Conventions
Category

Source Discussions