Identifiers (variables, properties, keys, IDs) should accurately reflect their semantic purpose and context. Names should be chosen to clearly communicate the meaning and role of the element within its specific context, not just its technical type or generic purpose.
Identifiers (variables, properties, keys, IDs) should accurately reflect their semantic purpose and context. Names should be chosen to clearly communicate the meaning and role of the element within its specific context, not just its technical type or generic purpose.
Examples:
// Incorrect: Name doesn't match context
const hasCustomTemperature = value !== undefined
// Correct: Name reflects actual context
const hasCustomMaxContext = value !== undefined
// Incorrect: Generic/mismatched test ID
data-testid="open-tabs-limit-slider"
// Correct: ID reflects component purpose
data-testid="markdown-lineheight-slider"
// Incorrect: Inconsistent API property naming
interface Props {
apiRequestFailedMessage: string;
apiReqStreamingFailedMessage: string; // Inconsistent abbreviation
}
// Correct: Consistent naming pattern
interface Props {
apiRequestFailedMessage: string;
apiRequestStreamingFailedMessage: string;
}
This standard helps maintain code clarity, improves maintainability, and reduces cognitive load by ensuring names accurately represent their purpose within the codebase.
Enter the URL of a public GitHub repository