Loading...
Loading...
Apply language-agnostic naming conventions using the A/HC/LC pattern. Use when naming variables, functions, or reviewing code for naming consistency.
npx skill4agent add flpbalada/my-opencode-config naming-cheatsheet| Principle | Description |
|---|---|
| Short | Not take long to type and remember |
| Intuitive | Read naturally, close to common speech |
| Descriptive | Reflect what it does/possesses in the most efficient way |
/* Bad */
const a = 5 // "a" could mean anything
const isPaginatable = a > 10 // sounds unnatural
const shouldPaginatize = a > 10 // made-up verb
/* Good */
const postCount = 5
const hasPagination = postCount > 10
const shouldPaginate = postCount > 10prefix? + action (A) + high context (HC) + low context? (LC)| Name | Prefix | Action (A) | High Context (HC) | Low Context (LC) |
|---|---|---|---|---|
| | | ||
| | | | |
| | | | |
| | | |
shouldUpdateComponentshouldComponentUpdategetfunction getFruitCount() {
return this.fruits.length
}
async function getUser(id) {
const user = await fetch(`/api/user/${id}`)
return user
}setlet fruits = 0
function setFruits(nextFruits) {
fruits = nextFruits
}resetconst initialFruits = 5
let fruits = initialFruits
function resetFruits() {
fruits = initialFruits
}removedelete| Action | Use Case | Opposite |
|---|---|---|
| Removes something from a collection | |
| Completely erases from existence | |
// remove - from a collection (paired with add)
function removeFilter(filterName, filters) {
return filters.filter((name) => name !== filterName)
}
// delete - permanent erasure (paired with create)
function deletePost(id) {
return database.find({ id }).delete()
}addcreateremoveadddeletecreatecomposefunction composePageUrl(pageName, pageId) {
return pageName.toLowerCase() + '-' + pageId
}handlefunction handleLinkClick() {
console.log('Clicked a link!')
}
link.addEventListener('click', handleLinkClick)| Prefix | Usage | Example |
|---|---|---|
| Describes characteristic or state | |
| Describes possession of value or state | |
| Positive conditional coupled with action | |
/* Bad */
const isProductsExist = productsCount > 0
const areProductsPresent = productsCount > 0
/* Good */
const hasProducts = productsCount > 0| Prefix | Usage | Example |
|---|---|---|
| Minimum or maximum value | |
| Previous or next state | |
function renderPosts(posts, minPosts, maxPosts) {
return posts.slice(0, randomBetween(minPosts, maxPosts))
}
async function getPosts() {
const prevPosts = this.state.posts
const latestPosts = await fetch('...')
const nextPosts = concat(prevPosts, latestPosts)
this.setState({ posts: nextPosts })
}/* Bad */
const primerNombre = 'Gustavo'
const amigos = ['Kate', 'John']
/* Good */
const firstName = 'Gustavo'
const friends = ['Kate', 'John']camelCasePascalCasesnake_case/* Bad - inconsistent */
const page_count = 5
const shouldUpdate = true
/* Good - consistent */
const pageCount = 5
const shouldUpdate = true/* Bad */
const onItmClk = () => {}
/* Good */
const onItemClick = () => {}class MenuItem {
/* Bad - duplicates context */
handleMenuItemClick = (event) => { ... }
/* Good - reads as MenuItem.handleClick() */
handleClick = (event) => { ... }
}/* Bad */
const isEnabled = itemCount > 3
return <Button disabled={!isEnabled} />
/* Good */
const isDisabled = itemCount <= 3
return <Button disabled={isDisabled} />/* Bad */
const friends = 'Bob'
const friend = ['Bob', 'Tony', 'Tanya']
/* Good */
const friend = 'Bob'
const friends = ['Bob', 'Tony', 'Tanya']| Pattern | Example |
|---|---|
| Get single item | |
| Get collection | |
| Get nested | |
| Set value | |
| Reset to initial | |
| Add to collection | |
| Remove from collection | |
| Create new entity | |
| Delete permanently | |
| Compose/build | |
| Handle event | |
| Boolean state | |
| Boundaries | |
| State transitions | |