Output SDK(開発キット)のワークフロープロジェクトにおけるコード記述スタイルの規則です。 TypeScript/JavaScriptのコード作成や見直しを行う際に使用します。 プロジェクト独自のリント規則(コード品質チェック)を優先的に確認し、リンターが設定されていない場合はOutput SDKの規則に従います。
Code style conventions for Output SDK workflow projects. Use when writing or reviewing any TypeScript/JavaScript code. Discovers the project's own linting rules first; falls back to Output SDK conventions when no linter is configured.
生成されたコードは、そのプロジェクトのスタイルに合わせる必要があります。 多くのプロジェクトでは、Output のデフォルトとは異なるルールセットを持つ独自の linter や formatter(ESLint、Prettier、Biome など)を使用しています。 まずプロジェクトのルールを確認し、それに従ってください。 プロジェクトに linter や formatter が設定されていない場合にのみ、以下の Output SDK の規約にフォールバックしてください。
コードの記述またはレビューを行う前に、プロジェクトのスタイルルールを確認してください。
eslint.config.js、.eslintrc.*、biome.json、deno.json などが存在するかを確認します。.prettierrc*、.editorconfig、または package.json 内の formatter 設定を確認します。package.json 内に lint、lint:fix、format などのスクリプトが存在するかを確認します。以下のルールは Output SDK 独自の ESLint 設定を反映したものです。 プロジェクトに linter が設定されておらず、既存のコードに競合する規約が見られない場合にのみ適用してください。
オブジェクト、配列、関数のパラメータ、型定義において、末尾カンマは使用しないでください。
// 正しい
const config = {
name: 'workflow',
timeout: 30000
};
const items = [ 'a', 'b', 'c' ];
export const myStep = step( {
name: 'myStep',
inputSchema: MyInputSchema,
outputSchema: MyOutputSchema,
fn: async input => {
return { result: input.value };
}
} );
// 誤り - 末尾カンマあり
const config = {
name: 'workflow',
timeout: 30000, // <-- 不可
}
const items = [ 'a', 'b', 'c', ] // <-- 不可
let 宣言の禁止let は使用禁止です。const のみを使用してください。
値に条件分岐が必要な場合は、三項演算子、IIFE(即時実行関数式)を使用するか、ロジックを再構成してください。
// 正しい - 三項演算子
const label = count > 1 ? 'items' : 'item';
// 正しい - 複雑なケースには名前付きヘルパーを使用
const fetchWithFallback = async url => {
try {
return await fetchContent( url );
} catch {
return '[Content unavailable]';
}
};
const content = await fetchWithFallback( url );
// 正しい - 関数内での早期リターン
function resolve( input ) {
if ( input.mode === 'fast' ) {
return fastPath( input );
}
return standardPath( input );
}
// 誤り
let content; // <-- 使用禁止
try {
content = await fetchContent( url );
} catch {
content = '[Content unavailable]';
}
let label; // <-- 使用禁止
if ( count > 1 ) {
label = 'items';
} else {
label = 'item';
}
パラメータが1つのアロー関数には括弧を付けないでください。 括弧が必要なのは、パラメータが0個・複数・分割代入の場合、または TypeScript の戻り値型アノテーションがある場合のみです。
// 正しい
items.map( item => item.id )
items.filter( s => s.url )
items.forEach( x => console.log( x ) )
fn: async input => { ... }
// 以下の場合は括弧が必要:
items.reduce( ( acc, item ) => acc + item, 0 )
const run = ( { name, id } ) => `${name}-${id}`;
const noop = () => {};
fn: async ( input ): Promise<WorkflowOutput> => { ... } // 戻り値型アノテーションあり
// 誤り - 1パラメータに不要な括弧
items.map( ( item ) => item.id )
items.filter( ( s ) => s.url )
fn: async ( input ) => { ... }
prefer-const常に const を使用してください。
再代入が行われないバインディングは必ず const にしなければなりません。
式が複数行にまたがる場合、演算子は1行目の末尾に置いてください。
// 正しい
const result = longExpression +
anotherExpression;
const isValid = conditionA &&
conditionB &&
conditionC;
const value = condition ?
trueResult :
falseResult;
// 誤り - 演算子が次の行の先頭
const result = longExpression
+ anotherExpression;
fn( x ) (fn(x) は不可)。ただし空の括弧は fn() とする[ 'a', 'b' ] (['a', 'b'] は不可){ key: value } ({key: value} は不可)snake_case(例: fetch_data.ts、html_renderer.ts)snake_case(例: ai_hn_digest、shared_utils)vitest.config.js、eslint.config.js)| ルール | 正しい | 誤り |
|---|---|---|
| 末尾カンマ | { a: 1 } |
{ a: 1, } |
| 変数宣言 | const x = 1 |
let x = 1 |
| 1パラメータのアロー関数 | x => x.id |
( x ) => x.id |
| 演算子の改行 | a +\n b |
a\n + b |
| 括弧内のスペース | fn( x ) |
fn(x) |
npm run lint、npx eslint など)がある場合は実行し、違反があれば修正してください。npm run format、npx prettier --write など)がある場合は実行してください。Generated code must match the style of the project it lives in. Many projects use their own linter or formatter (ESLint, Prettier, Biome, etc.) with rule sets that differ from Output's defaults. Always discover and follow the project's rules first. Only fall back to the Output SDK conventions below when the project has no linter or formatter configured.
Before writing or reviewing code, determine the project's style rules:
eslint.config.js, .eslintrc.*, biome.json, deno.json, or similar in the project root..prettierrc*, .editorconfig, or formatter settings in package.json.package.json for lint, lint:fix, format, or similar scripts.These rules reflect the Output SDK's own ESLint config. Apply them only when the project has no linter configured and no conflicting conventions are evident in existing code.
Never use trailing commas in objects, arrays, function parameters, or type definitions.
// CORRECT
const config = {
name: 'workflow',
timeout: 30000
};
const items = [ 'a', 'b', 'c' ];
export const myStep = step( {
name: 'myStep',
inputSchema: MyInputSchema,
outputSchema: MyOutputSchema,
fn: async input => {
return { result: input.value };
}
} );
// WRONG - trailing commas
const config = {
name: 'workflow',
timeout: 30000, // <-- not allowed
}
const items = [ 'a', 'b', 'c', ] // <-- not allowed
let Declarationslet is banned. Use const exclusively. When a value needs conditional assignment, use a ternary, an IIFE, or restructure the logic.
// CORRECT - ternary
const label = count > 1 ? 'items' : 'item';
// CORRECT - named helper for complex cases
const fetchWithFallback = async url => {
try {
return await fetchContent( url );
} catch {
return '[Content unavailable]';
}
};
const content = await fetchWithFallback( url );
// CORRECT - early return in a function
function resolve( input ) {
if ( input.mode === 'fast' ) {
return fastPath( input );
}
return standardPath( input );
}
// WRONG
let content; // <-- banned
try {
content = await fetchContent( url );
} catch {
content = '[Content unavailable]';
}
let label; // <-- banned
if ( count > 1 ) {
label = 'items';
} else {
label = 'item';
}
Single-parameter arrow functions must not have parentheses. Use parens only for zero, multiple, destructured parameters, or when a TypeScript return type annotation is present.
// CORRECT
items.map( item => item.id )
items.filter( s => s.url )
items.forEach( x => console.log( x ) )
fn: async input => { ... }
// Parens required for these cases:
items.reduce( ( acc, item ) => acc + item, 0 )
const run = ( { name, id } ) => `${name}-${id}`;
const noop = () => {};
fn: async ( input ): Promise<WorkflowOutput> => { ... } // return type annotation
// WRONG - unnecessary parens on single param
items.map( ( item ) => item.id )
items.filter( ( s ) => s.url )
fn: async ( input ) => { ... }
prefer-constAlways use const. If a binding is never reassigned, it must be const.
When an expression spans multiple lines, the operator stays on the first line.
// CORRECT
const result = longExpression +
anotherExpression;
const isValid = conditionA &&
conditionB &&
conditionC;
const value = condition ?
trueResult :
falseResult;
// WRONG - operator on next line
const result = longExpression
+ anotherExpression;
fn( x ) not fn(x), except empty parens fn()[ 'a', 'b' ] not ['a', 'b']{ key: value } not {key: value}snake_case (e.g., fetch_data.ts, html_renderer.ts)snake_case (e.g., ai_hn_digest, shared_utils)vitest.config.js, eslint.config.js)| Rule | Correct | Wrong |
|---|---|---|
| Trailing comma | { a: 1 } |
{ a: 1, } |
| Variable declaration | const x = 1 |
let x = 1 |
| Single-param arrow | x => x.id |
( x ) => x.id |
| Operator linebreak | a +\n b |
a\n + b |
| Parens spacing | fn( x ) |
fn(x) |
npm run lint, npx eslint, etc.), run it and fix any violations.npm run format, npx prettier --write, etc.), run it.原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。