Loading...
Loading...
Use when naming or renaming TypeScript identifiers, especially cryptic names, ambiguous parameters, I-prefixed interfaces, Hungarian notation, misleading side effects, or requests for clearer names.
npx skill4agent add gosukiwi/clean-code-react clean-typescript-names// Bad - what is d?
const d = 86400;
// Good - obvious meaning
const SECONDS_PER_DAY = 86400;
// Bad - what does this function do?
function proc(values: number[]) {
return values.filter((value) => value > 0);
}
// Good - intent is clear
function filterPositiveNumbers(numbers: number[]) {
return numbers.filter((number) => number > 0);
}// Bad - too implementation-specific
function getMapOfUserIdsToNames() {
// ...
}
// Good - abstracts the data structure
function getUserDirectory() {
// ...
}// Good - uses pattern name
class UserFactory {
create(data: unknown) {
// ...
}
}
// Good - uses domain term
function calculateAmortization(principal: number, rate: number, term: number) {
// ...
}// Bad - ambiguous
function rename(source: string, target: string) {
// ...
}
// Good - clear what's being renamed
function renameFile(oldPath: string, newPath: string) {
// ...
}// Good - short name for tiny scope
const total = numbers.reduce((sum, n) => sum + n, 0);
// Good - longer name for module-level constant
const MAX_RETRY_ATTEMPTS_BEFORE_FAILURE = 5;
// Bad - short name at module level
const MAX = 5;// Bad - Hungarian notation
const strName = "Alice";
const arrUsers: string[] = [];
const nCount = 0;
// Good - clean names
const name = "Alice";
const users: string[] = [];
const count = 0;
// Bad - interface prefix
interface IUserRepository {
findById(id: string): Promise<unknown>;
}
// Good - just name it
interface UserRepository {
findById(id: string): Promise<unknown>;
}const configStore = new Map<string, string>();
// Bad - name doesn't mention file creation
function getConfig(configPath: string) {
if (!configStore.has(configPath)) {
configStore.set(configPath, "{}"); // Hidden side effect!
}
return JSON.parse(configStore.get(configPath) ?? "{}");
}
// Good - name reveals behavior
function getOrCreateConfig(configPath: string) {
if (!configStore.has(configPath)) {
configStore.set(configPath, "{}");
}
return JSON.parse(configStore.get(configPath) ?? "{}");
}