hoc-accessors
Conventions for class accessors, getters and setters alike. Use when adding or reviewing an accessor — a getter that holds a dependency included — and when…
от openreachtech★ 17 звёзд на GitHub
Установить hoc-accessors в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Classes: Members / Accessors
This summarizes conventions related to class accessor (getter / setter) definitions.
Setters are prohibited
- Do not define setters (
set xxx () {}). - Reason: this codebase implements all classes as immutable (properties are set once in the constructor and never reassigned). A setter would allow reassignment after creation, breaking the premise of immutability.
- When you want to change state, instead of rewriting via a setter, generate a new instance via a factory method (see "Classes are immutable / property reassignment is prohibited" in the property-definition convention).
- Exception: for arguments passed to
Proxy(such as the handler innew Proxy(target, handler)), asettrap may be defined as needed. This is not a reassignment of a class property but the definition ofProxybehavior, and does not conflict with the intent of immutability.
The #get:Ctor getter
#get:Ctoris a getter, so everything below holds for it in full. How it is defined, and why its name is reserved, belong to/hoc-classes-ctor.
Getters that wire dependencies
- A class reaches what it depends on through static getters —
[TargetClassName]Ctorfor a class it instantiates, a getter returning the module as-is for one it uses directly. Which getter a dependency takes, and the factory method beside it, belong to/hoc-wire-dependencies. - They are getters, so everything below holds for them in full. A
Ctorgetter returns the class and nothing else; the.create(...)call belongs in the factory method, never in the getter.
Do not write branching inside a getter
- Do not write branching (
ifstatements, ternary operators, etc.) in the body of a getter. - One of a getter's responsibilities is drilling down into properties to resolve the Law of Demeter. Confine deep property chains within the getter, keeping the caller shallow.
- A getter must not return
undefined. When a value cannot be obtained, resolve it tonullwith?? null.- This
??is itself a kind of branching, but since the condition is limited solely to "identifyingundefined," it is permitted as an exception.
- This
- How a chain is chopped while drilling down belongs to "Write one property per line in a property chain" in
/hoc-coding-styles, withthis.xxxxstanding as the receiver.
// OK: this.entity is the receiver, one property per line. undefined is resolved to null with ?? null
get authorId () {
return this.entity.comment
?.author
?.id
?? null
}
- When drilling down into properties, if the leading lines of the chain recur across multiple getters, extract that leading part into a separate getter. The subsequent getters then continue using the extracted getter as their receiver.
// NG: the leading `this.entity.comment ?.author` is duplicated across multiple getters
get authorId () {
return this.entity.comment
?.author
?.id
?? null
}
get authorName () {
return this.entity.comment
?.author
?.name
?? null
}
// OK: extract the common leading part into a getter, and use it as the receiver from then on
get author () {
return this.entity.comment
?.author
?? null
}
get authorId () {
return this.author?.id
?? null
}
get authorName () {
return this.author?.name
?? null
}
Do not call a method from a getter
- Do not call a method from the body of a getter. The receiver does not matter:
this.xxxx(),this.Ctor.xxxx(), a method on an object reached by drilling down, and a global function are all prohibited. - Reason: from the caller's side, a getter looks like a property access (
this.authorLabel). Calling a method behind it makes it implicit, from the caller's side, that processing is running. What looks like a property must be complete as a property reference alone. - A getter's responsibility is limited to the property drilling of the previous section. When processing is needed, define it as a method and let the caller call it as a method.
// NG: calling a method from a getter. The caller's this.authorLabel looks like a property, yet formatting runs behind it
get authorLabel () {
return this.buildLabel(this.author)
}
// OK: keep the getter to a property reference, and let the caller call the formatting as a method
get author () {
return this.entity.comment
?.author
?? null
}
buildAuthorLabel () {
return this.buildLabel(this.author)
}
- When the value reached by drilling down is a function, returning it without calling it is out of scope. What is prohibited is calling within the getter; returning a function as a value is not restricted.
- Exception: an abstract getter that requires an override and declares itself unimplemented by throwing is out of scope, whichever of the two throws the error-handling convention gives it. **That covers the one that reaches the module's own error class through a factory
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл hoc-accessors?
Conventions for class accessors, getters and setters alike. Use when adding or reviewing an accessor — a getter that holds a dependency included — and when about to write a getter that counts, filters or builds the value it returns. Which getter a dependency takes, and the factory method beside it, belong to the dependency-wiring convention; where members sit in the class body, to the class notation convention.
Как установить скилл hoc-accessors?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл hoc-accessors запускает скрипты?
Нет, скилл состоит только из инструкций (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…