agentleFS
lxsmnsyclxsmnsyc/agent-skills/skills/ts-style/SKILL.md

ts-style

Skill4 starsChanged 16 days agoMITView on GitHub

Style rules for this user's TypeScript code, and for `.js` files too. Write for-of loops instead of callback-taking Array methods (map, filter, forEach, reduce, some, every, find, flatMap and the like), write named functions as function declarations with action names (never `<noun>Of`), comment the steps inside a function rather than the function itself, and run the repo's linter and formatter after editing. Use this skill whenever writing, editing or reviewing TypeScript, `.ts`, `.tsx`, `.js` or `.jsx` code, unless the repo's own style rules say otherwise.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. cloudflare/workerd★ 9.1ksame name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository10 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 0 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Do not claim the loop is faster.

    line 14
  2. Very specific:

    Test files are exempt. expect(units.map((unit) => unit.id)).toEqual(...) is fine in a test.

    line 16
  3. Very specific:

    When the linter's prefer-find flags filter(...)[0], write a loop with break, not find.

    line 27
  4. Very specific:

    Write a named function as a function declaration, not as a const holding an arrow function.

    line 63
  5. Very specific:

    Do not name functions <noun>Of (keyOf, fileOf, ownerOf).

    line 103
  6. Very specific:

    Search the lines your change added for callback Array methods, for example with git diff -U0 | grep -E …

    line 111

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

TypeScript style

Rules that apply to every repo of this user with .ts, .tsx, .js or .jsx code. A repo's own conventions (a CLAUDE.md, a lint config, the existing code) win when they disagree.

Prefer for-of over Array methods

Iterate with for...of instead of an Array method that takes a callback. This is the user's style: their code has far more for-of loops than callback methods. A chain of methods walks the array once per method, and a loop does the work in one pass.

Do not claim the loop is faster. A single map over a small array is often faster than a loop with push. When speed matters, measure it with the perf-pass skill.

Test files are exempt. expect(units.map((unit) => unit.id)).toEqual(...) is fine in a test.

What becomes a loop

map, filter, forEach, reduce, reduceRight, some, every, find, findIndex, findLast, findLastIndex, flatMap, and Array.from(items, mapper). The same goes for forEach on a Map or a Set.

  • A chain becomes one loop: filter then map is one pass with a continue.
  • some, every and find keep their short circuit with return or break.
  • A callback that reads the index iterates entries(), or uses a counted for.
  • Promise.all(items.map(async ...)) becomes a loop that pushes the promises, then Promise.all over them.
  • new Map(items.map(...)) becomes an empty Map filled in the loop.
  • When the linter's prefer-find flags filter(...)[0], write a loop with break, not find.
// Before
const names = party.filter((unit) => unit.alive).map((unit) => unit.name);
const fainted = party.some((unit) => unit.hp === 0);

// After
const names: string[] = [];
let fainted = false;

for (const unit of party) {
  if (unit.hp === 0) {
    fainted = true;
  }
  if (unit.alive) {
    names.push(unit.name);
  }
}

What stays

  • Methods with no per-item callback: sort, join, slice, includes, indexOf, concat, push, at.
  • A sort comparator, which no loop replaces.
  • A framework's list rendering idiom: <For each={...}> in Solid, items.map(...) inside React JSX.
  • Anything that only shares a name with an Array method: a promise's .then(...), a string's .includes(...).

Traps

  • Reactivity. In Solid and other signal-based code, a loop hoisted out of a JSX expression, a memo or an effect stops being tracked. Keep the loop inside the same tracked scope, as the body of the accessor or memo it came from.
  • Types. Give the accumulator its type (const names: string[] = []), so callers still see what the method inferred.
  • Fresh results. Where the method returned a fresh array the caller may keep, the loop builds a fresh array too, never a shared one.

Function declarations

Write a named function as a function declaration, not as a const holding an arrow function.

// Before
export const heal = (unit: Unit, amount: number): void => { ... };

// After
export function heal(unit: Unit, amount: number): void { ... }

Inline callbacks, sort comparators, JSX event handlers and functions passed straight to another call stay arrows.

Comments

Comment the steps inside a function, not the function. Split a body of more than a few lines into sections, one blank line apart. Open each section with a comment that says what the step does, and why when that is not obvious. A reader should be able to follow the function by reading only its section comments.

function applyDamage(battle: Battle, hit: Hit): void {
  // Shields absorb the hit first, and only the rest reaches the hp.
  const absorbed = Math.min(hit.target.shield, hit.amount);
  hit.target.shield -= absorbed;
  const rest = hit.amount - absorbed;

  // A unit at 0 hp faints at once, before the next hit in the same turn.
  hit.target.hp = Math.max(0, hit.target.hp - rest);
  if (hit.target.hp === 0) {
    faint(battle, hit.target);
  }

  // The log keeps the absorbed part, so the replay can draw the shield breaking.
  battle.log.push({ kind: 'damage', target: hit.target.id, absorbed, rest });
}
  • A function of one step needs no section comment.
  • A doc block goes on exported functions and types only. It says what the thing is for, not what its name already says.
  • The wording follows the plain-writing skill: short, full sentences, no history.

Naming

Do not name functions <noun>Of (keyOf, fileOf, ownerOf). Name the action. Use getKey(unit) for a plain read, or a verb that says the work, such as findFile, readFile or createKey.

Lint and format

Most repos of this user extend @lxsmnsyc/oxlint-config and format with oxfmt. That config enforces about 150 rules, such as braces on every if, prefer-const and explicit return types. This skill does not repeat them. After editing, run the repo's lint script (often pnpm lint, which runs oxlint --type-aware) and its formatter, and fix what they report.

Before finishing

Search the lines your change added for callback Array methods, for example with git diff -U0 | grep -E '^\+.*\.(map|filter|forEach|reduce|some|every|find|findIndex|flatMap)\('. Turn each hit outside tests and the "What stays" list into a loop. Search the same lines for function \w+Of( and rename each hit.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.