コンテンツにスキップ

診断と規則のリファレンス

English · 日本語(このファイル)

karasu は問題を 2 つのレイヤーの語彙で報告する。

  • 規則(rule)は 概念 — 言語が何を許し何を禁じるか(「edge はその所属 ブロックの内側から originate する」)。規則は、著者とこの spec が制約を語る ときの単位である。
  • 診断(diagnostic)は メカニズム — 規則の具体的な違反 1 つを検出したとき に発火する、名前付きの検査(edge-source-mismatch)。

1 つの規則はしばしば複数の診断で強制され、1 つの診断はちょうど 1 つの規則に 属する。本書は両者を対応づけるカタログである。

  • 診断コードは安定 API である。 code 文字列(例: edge-source-mismatch) は LSP・app・下流ツールが消費する。規則の言い回しに合わせてコードを rename することはしない。規則名は概念、コードは契約であり、両者は別レイヤー(altitude) に位置する。規則がその診断名とは別の言い回しの方が自然なのは想定どおり。
  • すべての診断コードは下記いずれか 1 つの規則ファミリーに属し、core が定義 する全コード(DiagnosticParamsByCodeWarningKind)が本書に現れる。この 完全性は meta-test で強制される(カタログの完全性 を参照)ため、新規コードは カタログ項目なしには出荷できない。
  • 発火条件 列に具体的なトリガを記す。severity は core が emit する値。

診断は severity を持つ: error / warning / info

  • error — モデルが不正で、該当構文は拒否される。
  • warning — 著者が直すべき実際の欠陥(dangling な参照、スタイル衝突など)。
  • info — 欠陥ではなく 事実。外部の流派が smell と呼びうる構造(共有 database、領域分散など)を、誤りと断じずに surface する。これが 事実 vs 流派 の register 区別である — TPL-20260514-08 を参照。

karasu は未解決参照に対し warn-don’t-error(spec §S6)に従う。未解決の関係は 落とすが、参照元の node は保存し、レンダー全体を失敗させずに warning として報告 する。

何をどこに宣言できるか、edge の起点が何でありうるか。service / domain ブロック 内に書いた edge はそのブロックの id を起点にする。infra ブロックと legend は配置 が固定。sync edge は循環してはならない。

CodeSeverity発火条件
edge-source-mismatcherrorservice / domain ブロック内の explicit な edge source が所属ブロック id と一致しない(edge origin scope 規則)。
ambiguous-edge-basewarning同じ from → to の base を持つ edge が複数あり、識別する author id が無い。
service-outside-systemwarningservicesystem の外で宣言されている。
infra-not-in-contexterrorinfra ブロック(database / queue / storage)が system の直接の子でない。
legend-not-top-levelerrorlegend ブロックがトップレベル以外で宣言されている。
top-level-declarationerroruser またはエッジが system ブロック内ではなくトップレベルで宣言されている。
system-property-conflictwarningmerge された import 間で systemlabel / description が衝突する。
cyclic-dependencywarningsync edge(->)が依存の循環を形成する。

id は宣言 scope 内で一意であること。ownership は primary owner を高々 1 つに割り 当てる。

CodeSeverity発火条件
duplicate-edge-iderrorauthor 指定の edge id が別の edge id と衝突する。
duplicate-node-id-parenterrornode id が直近の親の中で重複する。
duplicate-node-in-systemerrornode id が system 内で重複する。
duplicate-node-in-deployerrornode id が deploy ブロック内で重複する。
duplicate-team-iderrorteam id が重複する。
duplicate-team-in-organizationerrorteam id が organization 内で重複する。
duplicate-resource-operationwarning1 つの resource に CRUD verb が複数回並ぶ。
duplicate-crud-decoration-targetwarningCRUD decoration が同じ operation を複数回対象にする。
duplicate-owner-assignmentinfonode が複数の team に owned として割り当てられる(事実。ADR-20260615-01 参照)。
node-id-multiple-locationswarning同じ node id が複数の場所に現れる。

cross-reference 解決(warn-don’t-error, §S6)

Section titled “cross-reference 解決(warn-don’t-error, §S6)”

参照された id は宣言済み node に解決されること。解決できない場合、参照元 node は 保存し、未解決の関係を報告する(致命的エラーにはしない)— syntax spec §S6 参照。

CodeSeverity発火条件
owns-target-not-foundwarningteam が存在しない service / domain を owns する。
invalid-ownswarningowns 先が所有できない種別に解決される。
import-id-not-founderrornamed import の id パスが解決できない。
import-path-not-founderrorimport パスがいずれかのセグメントで解決できない。
unresolved-edge-endpointwarningedge の端点 id が merge 後のモデルのどこにも見つからない。
unresolved-handleswarninghandles 対象の domain が one-hop expose 規則で到達できない。
unresolved-realizeswarningdeploy node が論理層に無い対象を realizes する。
legend-ref-unresolvedwarninglegendref がどのスタイル規則にも node にも一致しない。
cross-system-ref-unresolvedwarningcross-system edge(Sys.Svc)の対象が見つからない。
cross-system-ref-implicit-externalwarningcross-system edge が [external] 未付与の system に跨る。
delivers-target-not-clientwarningdelivers の対象が client node でない。

infra node は 1 度だけ宣言される。複数 service から参照される store は surface する価値のある事実。

CodeSeverity発火条件
infra-redeclared-across-filesinfo同じ database / queue / storage id が複数の merge 対象ファイルで宣言される。
infra-leaf-redeclared-silentlyinfotable / queue-item / bucket の leaf が親 infra 内で再宣言される。
shared-infra-fan-ininfo2 つ以上の service が 1 つの system 内で同じ store に依存する(欠陥ではなく事実)。

resource への operation / CRUD decoration の文法。

CodeSeverity発火条件
invalid-crud-decorationerrorCRUD decoration が認識されない verb / letter を使う。
empty-crud-decorationwarningverb: decoration の右辺が空。
unknown-resource-operationwarningresource operation の verb が create / read / update / delete のいずれでもない。

構造 node が owner / 親に割り当てられているか、domain と deploy 対象の配線に関する 凝集の事実。

CodeSeverity発火条件
unassigned-servicewarningservice が team 割り当てなしにトップレベルに置かれる。
unassigned-domainwarningdomain が team 割り当てなしにトップレベルに置かれる。
unassigned-usecasewarningusecase が domain の親なしに service の直接の子になる。
unassigned-clientwarningclient が team 割り当てなしにトップレベルに置かれる。
unassigned-databasewarningdatabase が team 割り当てなしにトップレベルに置かれる。
unassigned-queuewarningqueue が team 割り当てなしにトップレベルに置かれる。
unassigned-storagewarningstorage が team 割り当てなしにトップレベルに置かれる。
unassigned-resourcewarningresource が dot-notation の割り当てなしにインラインで宣言される。
domain-dispersalinfo1 つの domain id が scope 内の複数 service にまたがる(事実)。
missing-realizesinfodeploy node に realizes プロパティが無い。
missing-runtimeinfodeploy node に runtime プロパティが無い。

annotation パラメータと、削除・非推奨になったプロパティ。

CodeSeverity発火条件
annotation-param-unsupportedwarningannotation のパラメータ key がその annotation で認識されない。
annotation-possible-typoinfoannotation 名が builtin の near-match(typo の示唆)。
team-property-removederror削除済みの team プロパティが使われる(ADR-20260614-01 参照)。

import 宣言とスタイル import をファイルシステムに対して解決する。

CodeSeverity発火条件
circular-importwarningnode import が循環を形成する。
circular-style-importwarningスタイル import が循環を形成する。
file-not-founderrorimport されたファイルが存在しない。
directory-not-founderrorimport されたディレクトリが存在しない。
style-file-not-foundwarningimport されたスタイルファイルが存在しない。

.krs.style のプロパティ名と値を検証する。

CodeSeverity発火条件
style-unknown-propertywarningスタイルのプロパティ名が認識されない。
style-invalid-enum-valueerrorスタイル値が許可された enum に無い。
style-invalid-hex-colorerrorスタイルの hex color が不正。
style-invalid-length-uniterrorスタイルの length が許可されない単位を使う。
style-missing-length-uniterrorスタイルの length に必要な単位が無い。
style-out-of-rangeerrorスタイルの数値が min / max の範囲外。
style-token-type-mismatcherrorスタイルの token が期待された型と一致しない。
expected-style-property-nameerrorスタイルパーサがプロパティ名を期待した。
expected-semicolon-between-propertieserrorスタイルパーサがプロパティ間の ; を期待した。
unknown-edge-selector-attributeerrorエッジセレクタが from / to 以外の属性を使っている(例: edge[source=X])。
style-conflictwarningセレクタが複数のユーザースタイルシートで定義される。
style-column-invalid-valuewarningスタイル column 値が left / center / right でない。
style-column-ignored-non-system-viewwarningcolumn ヒントが deploy / org ビューに適用される(無視)。
style-grid-columns-invalid-valuewarningスタイル grid-columns 値が正の整数でない(ヒントは破棄され、レイアウトは自動バランスにフォールバック)。

client サブ言語: storage kind と capability。

CodeSeverity発火条件
client-resource-invalid-kinderrorclient の resource storage kind が予約値のいずれでもない。
client-capability-duplicatewarningclient が同じ capability 名を 2 度宣言する。

token が妥当な構文を成さないときに上がる低レベルのパーサエラー。本質的にメカニズム レベルであり、「規則」は文法そのもの。

CodeSeverity発火条件
token-type-mismatcherrortoken がパーサの期待した型と一致しない。
unexpected-token-rooterrorroot レベルに予期しない token。
unexpected-token-in-blockerrorブロック内に予期しない token。
expected-brace-or-stringerrorパーサが { か string literal を期待した。
expected-identifiererrorパーサが identifier を期待した。
expected-string-aftererrorパーサがプロパティ keyword の後に string を期待した。
expected-id-or-stringerrorパーサが id か string を期待した。
expected-node-iderrorパーサが node id を期待した。
expected-property-valueerrorパーサがプロパティ値を期待した。
expected-id-aftererrorパーサがプロパティ keyword の後に id を期待した。
invalid-node-kinderrornode kind の keyword が認識されない。
property-not-for-node-kinderrorプロパティがその node kind に対して妥当でない。
link-url-scheme-not-allowedwarninglink URL の scheme が許可集合(http / https / mailto)に無い。

アプリケーションレベルのフォールバック

Section titled “アプリケーションレベルのフォールバック”

throw された compile / parse エラーを app が包むときに使う合成コード。

CodeSeverity発火条件
app-project-compile-errorerrorcompile() が throw し、app が汎用の compile 失敗を報告する。
app-org-parse-errorerrororg パースが throw し、app が汎用の parse 失敗を報告する。
generic-texterror構造化パラメータを持たない、事前生成のフォールバックメッセージ文字列。

DiagnosticParamsByCodeWarningKindpackages/core/src/types)の全メンバーは、 本書に code として現れなければならない。meta-test (packages/core/src/types/diagnostics-catalog.test.ts)が双方向でこれを assert するため、カタログが emit されるコードから無言で drift することはない。背景の規律は TPL-20260616-02 に記録する。

Related TPLs: TPL-20260616-02(カタログ ↔ コードの完全性), TPL-20260514-08(事実 vs 流派の register), TPL-20260610-02(spec が約束する診断は実装されている), TPL-20260511-02(spec ↔ source-of-truth 同期).

© 2026 Hiroki Kondo · Licensed under Apache-2.0