Rules for naming files, functions, classes, methods, variables, etc.
The generic advice is as follows: write new code in the same way the existing code is written.
If something isn’t explicitly specified, it doesn’t mean it’s not important. The naming of files, functions, CSS classes, formatting, and even the order of attributes are all important and should follow the same systematic approach. It’s just not written down.
Intermittent failures are failures that happen sometimes, but not always, and usually cannot be reproduced consistently.
They appear to be random or unpredictable — sometimes the system works perfectly, and sometimes it fails — even though you didn’t change anything.
This inconsistency is what makes intermittent failures annoying and hard to debug.
Intermittent failures usually come from:
Because:
// Sometimes fetch() returns slow, causing timeout.
// Sometimes it's fast. So the test occasionally fails.
test("API returns data", async function () {
const data = await fetch("/api/data");
expect(data.ok).toBe(true);
});
If network is slow → test fails If network is normal → test passes → intermittent failure
For lists of selectable options (select, dropdown, radio, tabs, etc.) always use:
{value: <internal>, label: <display>}
| Form | Meaning |
|---|---|
*_group_by_* |
a verb/operation (function that performs grouping) |
*_grouped_by_* |
a noun/grouped result (data structure) |
const inventory = [
{name: 'asparagus', type: 'vegetables', quantity: 9},
{name: 'bananas', type: 'fruit', quantity: 5},
{name: 'goat', type: 'meat', quantity: 23},
{name: 'cherries', type: 'fruit', quantity: 12},
{name: 'fish', type: 'meat', quantity: 22},
];
console.log(Object.groupBy(inventory, v => v.type));
console.log(Map.groupBy(inventory, v => v.type));
const items_grouped_by_anim = items_group_by_anim(items);
A variable named as a plural noun represents an array of rows:
item_types
users
banners
Shape:
Row[]
When a collection is reindexed by a unique property:
item_types_by_name
users_by_id
banners_by_uid
Shape:
Record<key, Row>
Rule:
<table_plural>_by_<unique_property>
This means:
When multiple rows can share the same property:
banners_grouped_by_status
users_grouped_by_role
Shape:
Record<key, Row[]>
Rule:
<table_plural>_grouped_by_<property>
When exposing behavior instead of structure:
item_type_by_name(name)
user_by_id(id)
banner_by_uid(uid)
Rule:
<singular_table>_by_<property>(property)
This performs lookup and typically wraps an indexed collection.
Use _from_ only when something is computed, parsed, or constructed:
item_type_from_json(data)
user_from_token(token)
date_from_timestamp(ts)
Rule:
<singular>_from_<input>
Do not use _from_ for indexing.
| Shape | Naming |
|---|---|
| Array | item_types |
| Indexed map | item_types_by_name |
| Grouped map | item_types_grouped_by_status |
| Lookup fn | item_type_by_name(name) |
| Derived value | item_type_from_json(data) |