Command Palette

Search for a command to run...

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

hoc-prohibit-native-features

The native JavaScript features this library does not use, and why each is refused. Use as the criterion whenever code is about to reach for a native feature…

БесплатноБез исполняемых скриптов
openreachtechот openreachtech★ 17 звёзд на GitHub

Установить hoc-prohibit-native-features в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Prohibit Native Features

The native features below are not used. Each one does a job this library's design already does another way — immutability held by convention, a class that can be overridden in part — and each costs something that way of working depends on.

  • A class field (x = 1) is refused too, by the class design principles convention (/hoc-classes-principles): what it rules out is part of what a property is, so it stays with the definition of a property.

Object literals shared across scopes

An object literal is not shared across scopes on the strength of its shape. Built and used up where it stands, a literal is fine. Handed out — returned, kept in a property, passed on to be read elsewhere — it becomes a value whose reader trusts only that it has the right keys, and what holds values is a class. Why a shape is not a value belongs to the class design principles convention (/hoc-classes-principles).

  • A named-argument object is not sharing. fn({ title }) hands a literal across a call, and the callee destructures it on arrival into separate parameters; nothing keeps it as a value.
  • A @typedef naming the shape does not change this. It describes the literal, and the reader still holds a nameless object.
// NG: a literal leaves the method, and its reader relies on the shape
computeTotalPerRegion () {
  return this.extractKeptSales()
    .reduce((totals, it) => ({
      ...totals,
      [it.region]: (totals[it.region] ?? 0) + it.amount,
    }), {})
}

// OK: what leaves the method is an instance of a class
computeRegionTotals () {
  const keptSales = this.extractKeptSales()

  return [
    ...new Set(
      keptSales.map(it => it.region)
    ),
  ]
    .map(region => this.Ctor.RegionTotalCtor.create({
      region,
      amount: keptSales
        .filter(sale => sale.region === region)
        .reduce((total, sale) => total + sale.amount, 0),
    }))
}

Map

  • In an application, Map is never needed (enforced by ESLint). What Map is first for is a table keyed by objects, and that job is WeakMap's: it holds a value against an object, and lets the value go when the object is released. Map holds on to both, and gives nothing WeakMap does not.
  • The one place Map may stand is a module isolated in a repository of its own, and only for a special reason. No such reason is known today. The exception is left open only because one may be met some day, however unlikely; it is not a door to reach for. A Map written there carries its reason beside it, and the use stays inside that module.
  • A Map keyed by a string or a number is a misuse, not a second purpose. It is a mutable aggregate that dodges the prohibitions on reassignment and on mutable objects, and it is the only way Map has been reached for in application code.
  • WeakMap may be used freely. Associating objects by identity is its responsibility, and it does not enumerate; where the keys have to be walked, hold them in an Array and traverse that.
  • If a mutable aggregate seems necessary, reconsider the design (assemble it via a higher-order function and return it, or generate a new instance via a factory method).
  • A Map handed in from outside is only read. A library may pass one — a record of what changed, a decoded payload — and its get() and has() are called. Nothing is written to it: the map is not the receiver's to change.
  • Test code is outside the prohibition. A fixture a library takes only as a Map, such as a CBOR map whose keys are integers, is written as one there.

Looking up by a string or a number

A lookup by a string or a number is what Map has been reached for, and it needs no Map. The elements are held in an Array, and the one asked for is found with find().

  • No object keyed by a string is built to look elements up, inside a method or kept beside the collection. Built within a method, it walks every element to answer one lookup, which is already more than find() does. Kept beside the collection, it is a copy built again whenever the elements change — the mutable aggregate refused above, reached by another route.
  • Speed is not a reason to avoid find(). Entries written in the source code are never so many that walking them is worth a second structure, and a Map is not reached for to make it faster.
  • Entries too many for find() to keep up with belong in a database, and are looked up there.
// NG: an index object is built again from the elements on every lookup
extractMemberByEmail ({
  email,
}) {
  const memberPerEmail = Object.fromEntries(
    this.members.map(it => [it.email, it])
  )

  return memberPerEmail[email]
}

// OK: the elements are asked directly
extractMemberByEmail ({
  email,
}) {
  return this.members
    .find(it => it.email === email)
}

Native private members (#x)

Under an immutable property design, **there is no

Полный SKILL.md на GitHub

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

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

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

FAQ

Что делает скилл hoc-prohibit-native-features?

The native JavaScript features this library does not use, and why each is refused. Use as the criterion whenever code is about to reach for a native feature — `Map`, `Object.freeze()`, a `#` private member, a decorator, an object literal handed across scopes — or when reviewing code that does. A class field is refused by the class design principles, which define what a property is.

Как установить скилл hoc-prohibit-native-features?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл hoc-prohibit-native-features запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

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

Сравнить hoc-prohibit-native-features с