Names should clearly convey their semantic purpose and avoid conflicts that reduce code readability. This applies to imports, types, variables, and methods.
Key principles:
Examples:
Import naming to avoid conflicts:
// Problematic - naming conflict
import Parser from 'web-tree-sitter';
const Parser: typeof Parser = await import('..').then(m => m.default);
// Better - clear, distinct names
import TSParser from 'web-tree-sitter';
const Parser: typeof TSParser = await import('..').then(m => m.default);
Type naming for semantic clarity:
// Problematic - same interface for different concepts
interface QueryResult {
pattern: number;
captures: { name: string; node: SyntaxNode }[];
}
// Better - distinct names for different concepts
interface QueryMatch {
pattern: number;
captures: QueryCapture[];
}
interface QueryCapture {
name: string;
node: SyntaxNode;
}
This prevents confusion and makes the codebase more maintainable by ensuring each name has a clear, unambiguous meaning.
Enter the URL of a public GitHub repository