hoc-statements
Conventions for statements and control flow inside a function or method body, test files included. Use when writing or reviewing any body of code, a…
от openreachtech★ 17 звёзд на GitHub
Установить hoc-statements в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Shared: Statements
Summarizes conventions for statements and control flow. Applied across both functions and methods.
Do not write the literal text undefined in production code
- Do not write the literal text
undefined(as a literal or identifier) in real code files (production code). - Reason:
undefinedis not a "value." Ifundefinedis used intentionally as a value, it becomes impossible to distinguish between "a bug" and "intentional logic." - When you intentionally want to express "no value," use
nullinstead ofundefined. Sincenulldoes not arise naturally in context, it can be used as an intentional value. - How a JSDoc type expresses "no value" —
nullrather thanundefined, and the exception a third-party module forces — belongs to/hoc-jsdoc. - This convention is enforced by ESLint's
no-undefinedrule. However, ineslint.config.js,no-undefined: 'off'is set fortests/**/*.js, so writingundefinedin test files is exempt from this prohibition.
Cannot distinguish between a bug and an intentional value
Using undefined as an intentional value makes it impossible to distinguish between "a bug" and "intentional logic" in cases like the following.
const object = {
alpha: undefined, // NG: undefined is written as an intentional value
}
console.log(object.alpha) // undefined
console.log(object.beta) // undefined
console.log('alpha' in object) // true 🔥 (the key ends up existing)
console.log('beta' in object) // false
// ---------------
function extractAlpha (object) {
object.alpha // <-- ❌️ Forgot to write return (a bug)
}
console.log(
extractAlpha({})
) // undefined (a bug, but indistinguishable from a normal return value)
Use null instead of undefined
Since null does not arise naturally depending on context, it can be used as an intentional value.
// NG: writing undefined
function extractAlpha (object) {
return object.alpha
}
// OK: resolve to null with ?? null (expresses an intentional "no value")
function extractAlpha (object) {
return object.alpha
?? null
}
console.log(
extractAlpha({})
) // null
let is prohibited; declare every variable with const
letis not written. Every variable is declared withconst;varis already an error under lint (no-var).- A
letexists in order to be reassigned, and a reassigned binding is sequential processing held in one name: what the name means depends on how far down the function the reader has got. Every rule below this one — higher-order functions in place of loops, a conditional expression in place of a branch that assigns — exists so that a value is computed once and named once. - Lint enforces it.
@openreachtech/eslint-configcarriesNever use letamong itsno-restricted-syntaxoptions, so aleterrors whatever it is for.prefer-constwould have caught only the ones never reassigned — that is, exactly the harmless ones — which is why the prohibition is written as syntax rather than left to it. - Where a
letlooks unavoidable, what sits underneath it is one of these:
The let |
What replaces it |
|---|---|
| Accumulating through a loop | map / filter / reduce / Array.from |
Assigned in each branch of an if |
A conditional expression, or ?? |
| Assigned later, once a guard has passed | An early return, or a function that returns the value |
// NG: one name, two meanings
let endpoint = config.graphqlEndpoint
if (config.prefix) {
endpoint = `${config.prefix}${endpoint}`
}
// OK: computed once, named once
const endpoint = config.prefix
? `${config.prefix}${config.graphqlEndpoint}`
: config.graphqlEndpoint
An instance is never taken apart by destructuring
The members of an instance are not destructured — not on the right of a destructuring
assignment, and not in a parameter. An instance of a class, this included, is asked for what
it holds. Destructuring is left for data: a named-argument object, a payload being read.
// NG: an instance taken apart on the right of an assignment
const {
send,
} = this.mailClient
// NG: an instance taken apart in a parameter
.filter(({ account }) => account.isActive())
// OK: the instance asked, and answering for itself
.filter(it => it.hasActiveAccount())
- A method taken out of its instance no longer has it. Called as
send(), the method runs withthisunbound, and the first line of it that reachesthisfails. - A member taken out states what the instance holds inside. The local is a second name for one value from then on, and the code around it now depends on the instance's insides.
- The named-argument object is opened at the entry of a method, and what lies beneath it is
not, unless it is certainly a value object.
{ request, response, next }is destructured where the method begins: a method whose arguments could not be opened would be tedious to call
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл hoc-statements?
Conventions for statements and control flow inside a function or method body, test files included. Use when writing or reviewing any body of code, a destructuring or a method read out of its receiver included. How a higher-order function is used belongs to the higher-order function convention; where an expression is wrapped across lines, to the coding style convention; a method's signature, to the methods convention.
Как установить скилл hoc-statements?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл hoc-statements запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…