No slash command · from web-tasuke
Prefer the most specific built-in method over general-purpose ones in TypeScript/JavaScript. Use includes over indexOf, some over filter().length, find over filter()[0], flatMap over map().flat(), at(-1) over length-based access, startsWith/endsWith/includes over indexOf on strings, structuredClone over JSON round-trip. Use when writing or reviewing code that searches, tests, transforms arrays, objects, or strings.
Ships in web-tasuke. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
同じ結果が得られる方法が複数ある場合は、 やりたいことに最も特化した関数を選んでください。
特化した関数は名前そのものが意図を表すので、 読み手が「この比較は何のためか」を推測せずに済みます。 汎用的な関数を条件式と組み合わせて目的を表現すると、 意図が式の形に埋もれて読みにくくなります。
これはavoid-forでforを高抽象度の関数に置き換えるのと同じ発想を、
関数同士の選択にも広げたものです。
要素が含まれるかを知りたいだけなら、
位置を返すindexOfではなく、
真偽値を返すincludesを使います。
// 避ける
if (items.indexOf(target) !== -1) {
}
// 良い
if (items.includes(target)) {
}
includesは意図が明確なだけでなく、
NaNを正しく見つけられるという正確性の利点もあります。
indexOfは厳密等価(===)で比較するためNaNを見つけられませんが、
includesはSameValueZeroで比較するためNaNも見つけられます。
[NaN].indexOf(NaN); // -1 (見つからない)
[NaN].includes(NaN); // true
絞り込んだ結果の件数を見るのではなく、
someやeveryで真偽を直接求めます。
// 避ける
if (0 < users.filter((user) => user.active).length) {
}
// 良い
if (users.some((user) => user.active)) {
}
someは最初に条件を満たした時点で打ち切るので、
全件を絞り込むfilterより無駄がありません。
「すべてが条件を満たすか」はeveryを使います。
絞り込んでから先頭を取るのではなく、
findで直接取り出します。
// 避ける
const found = users.filter((user) => user.id === targetId)[0];
// 良い
const found = users.find((user) => user.id === targetId);
最後の要素が欲しい場合はfindLast、
位置が欲しい場合はfindIndexやfindLastIndexを使います。
mapしてからflatするのではなく、
flatMapを使います。
// 避ける
const tags = posts.map((post) => post.tags).flat();
// 良い
const tags = posts.flatMap((post) => post.tags);
lengthを使った添字計算ではなく、
atを使います。
// 避ける
const last = items[items.length - 1];
// 良い
const last = items.at(-1);
atは文字列にもあります。
位置を計算するのではなく、 専用のメソッドを使います。
// 避ける
if (path.indexOf("/etc/") === 0) {
}
if (name.lastIndexOf("hosts") === name.length - "hosts".length) {
}
// 良い
if (path.startsWith("/etc/")) {
}
if (name.endsWith("hosts")) {
}
文字列に部分文字列が含まれるかも、
indexOfではなくincludesで調べます。
グローバルフラグ付きの正規表現ではなく、
replaceAllで意図を示せます。
// 避ける
const escaped = text.replace(/&/g, "&");
// 良い
const escaped = text.replaceAll("&", "&");
正規表現が不要な単純な文字列置換では、
replaceAllに文字列を直接渡せます。
filterとindexOfを組み合わせるのではなく、
Setを使います。
// 避ける
const unique = items.filter((item, index) => items.indexOf(item) === index);
// 良い
const unique = [...new Set(items)];
Setを使う方が意図が明確で、
計算量の面でも有利です。
JSONの往復ではなく、
structuredCloneを使います。
// 避ける
const copy = JSON.parse(JSON.stringify(original));
// 良い
const copy = structuredClone(original);
JSONの往復はundefinedやDateやMapなどを正しく扱えませんが、
structuredCloneはこれらに対応します。
汎用的な関数に条件式やフラグを足して目的を表現できると気づいたら、 その目的そのものを名前に持つ関数がないか確認してください。
特化した関数は意図が明確になるだけでなく、 途中で打ち切る、 エッジケースを正しく扱うなど、 実装上の利点も持つことが多いです。
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
17 skills in this plugin
/any-typeAvoid using any type in TypeScript. Use unknown, generics, or proper type definitions instead. Use when writing or reviewing TypeScript type annotations./aria-usageWAI-ARIA usage guidelines. Avoid redundant ARIA attributes. No ARIA is better than Bad ARIA. Use when writing or reviewing HTML/JSX with accessibility attributes./as-const-satisfiesUse `as const` and `as const satisfies Type` for constant definitions in TypeScript. Use when defining constants, config objects, or string union types./async-state-typeAvoid contradictory state types for async data fetching. Use Suspense or discriminated unions instead. Use when writing or reviewing async data fetching code in React/TypeScript./avoid-forAvoid for loops (C-style, for...of, for...in) in TypeScript/JavaScript. Prefer higher-order Array methods like map, filter, find, some, every, reduce. Use when writing or reviewing loops or iteration over arrays, objects, Map, Set, or String./dynamic-importPrefer static import over dynamic import() in TypeScript/JavaScript. Use when writing or reviewing import statements.npx claudepluginhub ncaq/konoka --plugin web-tasuke