Hoc methods

From openreachtech/hora-skills-ort-core · View interactive version

Hoc methods is an AI agent skill from the GitHub repository openreachtech/hora-skills-ort-core. Conventions for class method definitions and their signatures. Use when defining, calling or reviewing a method. Method names belong to the naming convention; what the body is written with, to the statements convention; how a factory method builds a dependency, to the dependency-wiring convention; h

How to use this skill

Skill file

Classes: Members / Methods

This summarizes conventions related to class method definitions.

Arguments should be a single named-argument object

named arguments (destructuring assignment).

// NG: positional arguments
generate (length) {
  // ...
}

// OK: single named-argument object, chopped down
generate ({
  length,
}) {
  // ...
}

Exception: binding (inflator) methods pass arguments flat

subclass, such as .use() / .of() / .to() — is the exception to the rule above. What it

receives instead, the exceptions to that, and its naming belong to /hoc-classes-inflators.

Do not pass properties directly to private methods

internal method.

// NG: passing your own property into an internal method
buildKey () {
  return this.formatName({
    name: this.name,
  })
}

// OK: the internal method references `this` directly
buildKey () {
  return this.formatName()
}

formatName () {
  return this.name.toUpperCase()
}

A method that extracts resolves the value; it does not interpret it

**Where a method's job is to take a value out of something — a config, a payload, a

response — it returns what is there, and null where nothing is.** What absence means is

the caller's to decide, and deciding it inside the extractor hides the decision in the one

member whose name promises not to make any.

// NG: the extractor decides that no cap means an unreachable one
static extractMaxDocumentDepth ({
  config,
}) {
  return config.maxDocumentDepth
    ?? Infinity
}

// OK: it resolves, and leaves the meaning to whoever asked
static extractMaxDocumentDepth ({
  config: {
    maxDocumentDepth = null,
  },
}) {
  return maxDocumentDepth
}

absent key and an explicit null arrive the same way; ?? Infinity states what absence

is worth, which is a different claim.

Where the value is absent, the member that would have used it returns early, and the

behaviour that depends on it does not run.

// The consumer decides what an absent cap means
exceedsMaxDocumentDepth ({
  depth,
}) {
  if (!this.maxDocumentDepth) {
    return false
  }

  return depth > this.maxDocumentDepth
}

the consumer holds what its absence does. A substitute value inside the extractor merges

the two, and the merged version reads as though no decision had been made.

A recursion sits behind an entry point of its own

where the accumulator's initial value is written — belongs to /hoc-methods-recursion.

point and the deep~ member each take a single named-argument object, the accumulator

included.

Factory methods must be defined without exception

(When inheriting, the parent class's create is inherited, so it doesn't need to be redefined.)

(static create (...)).

Division of responsibility between the constructor and `static create (...)`

/hoc-classes-constructor. It is read here for the two things that land in

static create (...): a value the caller did not supply gets its default here, and where the

constructor's parameter list divides what goes up to the base from what the class keeps, the

factory method's parameter list repeats that division.

Variations should be distinguished by suffix

(e.g. .createAsAlpha() / .createWithBeta())

Placement order

JSDoc format

(Replace ThisClass with the name of the class being defined.)

/**
 * Factory method.
 *
 * @template {X extends typeof ThisClass ? X : never} T, X
 * @param {...} [params] - Parameters for the factory method.
 * @returns {InstanceType<T>} Instance of this class.
 * @this {T}
 * @public
 */

Instantiation

— why a static member refers to its own class through this belongs to /hoc-scope.

(The exception is new this(...) inside .create(...). This creates an instance of the class itself using this, not the class name.)

// NG
static create (...) {
  return new RandomTextGenerator({ characters })
}

// OK
static create (...) {
  return new this({ characters })
}
Exception: direct `new` for built-in classes and third-party modules

A dependency is built in a factory method of its own

read here because the default arguments of static create (...) are where a dependency is most

often built by hand.

When asynchronous creation is needed, define `.createAsync(...)`

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.