Command Palette

Search for a command to run...

Назад к скиллам
скилл № 83718

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от 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: undefined is not a "value." If undefined is 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 null instead of undefined. Since null does not arise naturally in context, it can be used as an intentional value.
  • How a JSDoc type expresses "no value" — null rather than undefined, and the exception a third-party module forces — belongs to /hoc-jsdoc.
  • This convention is enforced by ESLint's no-undefined rule. However, in eslint.config.js, no-undefined: 'off' is set for tests/**/*.js, so writing undefined in 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

  • let is not written. Every variable is declared with const; var is already an error under lint (no-var).
  • A let exists 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-config carries Never use let among its no-restricted-syntax options, so a let errors whatever it is for. prefer-const would 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 let looks 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 with this unbound, and the first line of it that reaches this fails.
  • 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
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

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), без исполняемых скриптов.

Похожие скиллы

Сравнить hoc-statements с