コンテンツにスキップ

JSON 出力

--format json を指定すると、contextlint は人間向けのテキストではなく、機械可読な JSON を標準出力へ書き出します。CI でのアノテーション生成、エディタ拡張のフィードバック、独自のレポーティングツールへの取り込みなどに使います。

Terminal window
npx contextlint --format json

lint(デフォルト)サブコマンドの JSON 出力は、違反のフラットな配列です。

[
{
"file": "docs/requirements.md",
"line": 12,
"severity": "error",
"message": "Required column \"Status\" not found in table",
"ruleId": "TBL-001"
},
{
"file": "docs/design.md",
"line": 24,
"severity": "warning",
"message": "Empty cell in column \"Status\"",
"ruleId": "TBL-002"
}
]

各要素のフィールドは次のとおりです。

フィールド説明
filestring違反が見つかったファイルの相対パス
linenumber違反箇所の行番号(1 始まり)
severity"error" / "warning"重要度
messagestring違反の説明
ruleIdstringハイフン付きのルール ID(例: TBL-001

違反がない場合は空配列 [] が出力されます。

JSON 出力は GitHub Actions のアノテーションや、Slack / Discord 通知のペイロード生成に使えます。

リポジトリ同梱の Composite Action は --format json で contextlint を実行し、結果を PR のインラインアノテーションに変換します。設定例は CI/CD → GitHub Actions を参照してください。

jq などで違反数を集計するシンプルな例です。

Terminal window
npx contextlint --format json | jq 'length'
# => 2

ルール別に件数を出すことも可能です。

Terminal window
npx contextlint --format json | jq 'group_by(.ruleId) | map({rule: .[0].ruleId, count: length})'

グラフ系サブコマンドの JSON 出力

Section titled “グラフ系サブコマンドの JSON 出力”

impact / slice / graph--format json を受け付けますが、出力構造は lint とは異なります。それぞれのサブコマンドの出力例は Concepts を参照してください。