@riebeckite/plugin-diagnostics 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +132 -132
- package/README_ja.md +103 -103
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
# @riebeckite/plugin-diagnostics
|
|
2
|
-
|
|
3
|
-
Content diagnostics for Obsidian vaults / Riebeckite content: broken links,
|
|
4
|
-
frontmatter issues, orphan notes, unused assets, and more. Usable as a build
|
|
5
|
-
plugin, a programmatic API, and a CLI.
|
|
6
|
-
|
|
7
|
-
[日本語](./README_ja.md)
|
|
8
|
-
|
|
9
|
-
## Overview
|
|
10
|
-
|
|
11
|
-
`diagnostics()` analyzes the content directory and reports problems as
|
|
12
|
-
diagnostics during the build. The same checks are available through
|
|
13
|
-
`runDiagnostics()` and the `riebeckite-diagnostics` CLI.
|
|
14
|
-
|
|
15
|
-
## Usage (plugin)
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import { defineConfig } from "@riebeckite/core";
|
|
19
|
-
import { diagnostics } from "@riebeckite/plugin-diagnostics";
|
|
20
|
-
|
|
21
|
-
export default defineConfig({
|
|
22
|
-
// ...
|
|
23
|
-
plugins: [
|
|
24
|
-
diagnostics({
|
|
25
|
-
reportUnusedAssets: true,
|
|
26
|
-
reportOrphans: true,
|
|
27
|
-
requiredFrontmatter: ["title"],
|
|
28
|
-
}),
|
|
29
|
-
],
|
|
30
|
-
});
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
- `addDiagnostics` — runs the analysis at build time; results go to
|
|
34
|
-
`manifest.diagnostics`
|
|
35
|
-
- `onBuildEnd` — with `failOnError: true`, throws `DiagnosticsFailure` when
|
|
36
|
-
error-level diagnostics exist
|
|
37
|
-
|
|
38
|
-
## Checks
|
|
39
|
-
|
|
40
|
-
| Code | Default severity | What it detects |
|
|
41
|
-
| ---- | ---------------- | --------------- |
|
|
42
|
-
| `broken-wikilink` | `error` | Wikilink target or fragment does not resolve |
|
|
43
|
-
| `broken-image` | `error` | Embedded image or image link does not exist |
|
|
44
|
-
| `broken-link` | `error` | Markdown link points to a missing or excluded note/file |
|
|
45
|
-
| `unused-asset` | `warning` | Image never referenced by any note (`reportUnusedAssets`) |
|
|
46
|
-
| `orphan-note` | `info` | Published note has no incoming links (`reportOrphans`) |
|
|
47
|
-
| `missing-frontmatter` | `warning` | No frontmatter, or required fields missing |
|
|
48
|
-
| `publish-conflict` | `warning` | `publish: true` combined with `draft: true` / `private: true` |
|
|
49
|
-
| `duplicate-title` | `warning` | Multiple published notes share a title |
|
|
50
|
-
| `slug-collision` | `error` | Slugs collide case-insensitively |
|
|
51
|
-
| `duplicate-content-id` | `error` | Published notes share a stable content ID (`id`/`uid`) |
|
|
52
|
-
| `invalid-content-id` | `error` | `id`/`uid` frontmatter violates the stable content ID contract |
|
|
53
|
-
| `excluded-public` | `warning` | Excluded note is marked `publish: true` |
|
|
54
|
-
| `publish-boundary` | `warning` | Published content links to or embeds non-published content |
|
|
55
|
-
| `analytics-untracked` | `info` | Published note has no stable `id` and the analytics plugin will not track it (enabled with `reportAnalyticsCoverage`, or automatically when the config enables the analytics plugin) |
|
|
56
|
-
| `internal-error` | `error` | Content analysis failed |
|
|
57
|
-
|
|
58
|
-
## Options
|
|
59
|
-
|
|
60
|
-
| Option | Type | Default | Description |
|
|
61
|
-
| ------ | ---- | ------- | ----------- |
|
|
62
|
-
| `failOnError` | `boolean` | `false` | Fail the build on error-level diagnostics |
|
|
63
|
-
| `reportUnusedAssets` | `boolean` | `false` | Report unreferenced images |
|
|
64
|
-
| `reportOrphans` | `boolean` | `false` | Report published notes without incoming links |
|
|
65
|
-
| `reportAnalyticsCoverage` | `boolean` | `false` | Report published notes the analytics plugin will not track (auto-enabled when the resolved config enables the analytics plugin) |
|
|
66
|
-
| `requiredFrontmatter` | `string[]` | `[]` | Required frontmatter fields |
|
|
67
|
-
| `severity` | `Partial<Record<DiagnosticCode, DiagnosticSeverity>>` | table above | Override severity per code |
|
|
68
|
-
| `exclude` | `string[]` | `[]` | Extra exclude globs |
|
|
69
|
-
| `publishStrategy` | `"explicit" \| "selective"` | from config | Publication filter strategy |
|
|
70
|
-
|
|
71
|
-
## CLI
|
|
72
|
-
|
|
73
|
-
```bash
|
|
74
|
-
riebeckite-diagnostics --config riebeckite.config.ts
|
|
75
|
-
riebeckite-diagnostics --content ./content --report-orphans
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
| Option | Description |
|
|
79
|
-
| ------ | ----------- |
|
|
80
|
-
| `--config <path>` | Path to `riebeckite.config.ts` (loaded under tsx) |
|
|
81
|
-
| `--content <dir>` | Content directory to analyze (default: `.`) |
|
|
82
|
-
| `--exclude <glob>` | Extra exclude glob (repeatable) |
|
|
83
|
-
| `--publish-strategy <mode>` | `explicit` \| `selective` (default: `selective`) |
|
|
84
|
-
| `--report-unused-assets` | Report images never referenced by any note |
|
|
85
|
-
| `--report-orphans` | Report published notes with no incoming links |
|
|
86
|
-
| `--report-analytics-coverage` | Report published notes without a stable content ID (auto-enabled for `--config` when the config enables the analytics plugin) |
|
|
87
|
-
| `--required-frontmatter <f>` | Comma-separated required frontmatter fields |
|
|
88
|
-
| `--fail-on-error` | Exit with code 1 when errors are found (default) |
|
|
89
|
-
| `--exit-on <severity>` | Exit with code 1 at/above severity (`info` \| `warning` \| `error`) |
|
|
90
|
-
| `--format <text\|json>` | Output format (default: `text`) |
|
|
91
|
-
| `--no-color` | Disable ANSI colors |
|
|
92
|
-
| `-h`, `--help` | Show help |
|
|
93
|
-
|
|
94
|
-
Exit codes: `0` no errors, `1` errors reported (or `--exit-on` threshold met),
|
|
95
|
-
`2` invalid arguments.
|
|
96
|
-
|
|
97
|
-
With `--config`, options from the config's `diagnostics` plugin are used as
|
|
98
|
-
defaults; explicit CLI flags override them, and `exclude` lists are merged.
|
|
99
|
-
|
|
100
|
-
## Programmatic API
|
|
101
|
-
|
|
102
|
-
```ts
|
|
103
|
-
import {
|
|
104
|
-
assertNoErrors,
|
|
105
|
-
formatDiagnostics,
|
|
106
|
-
runDiagnostics,
|
|
107
|
-
} from "@riebeckite/plugin-diagnostics";
|
|
108
|
-
|
|
109
|
-
const report = await runDiagnostics("./content", { reportOrphans: true });
|
|
110
|
-
console.log(formatDiagnostics(report));
|
|
111
|
-
assertNoErrors(report);
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
`runDiagnostics(config | path, options?)` returns a `DiagnosticsReport` with
|
|
115
|
-
`diagnostics`, `errors`, `warnings`, `infos`, `hasErrors`, `hasWarnings`,
|
|
116
|
-
`summary`, and `byCode`.
|
|
117
|
-
|
|
118
|
-
## Exports
|
|
119
|
-
|
|
120
|
-
- `diagnostics(options?)` / `diagnosticsPlugin` — plugin factory
|
|
121
|
-
- `runDiagnostics(target, options?)` — run the analysis directly
|
|
122
|
-
- `analyzeContent(config, options?)` — raw analysis returning `Diagnostic[]`
|
|
123
|
-
- `hasEnabledAnalyticsPlugin(config?)` — whether the resolved config enables the analytics plugin
|
|
124
|
-
- Report helpers: `buildReport`, `formatDiagnostics`, `groupByCode`,
|
|
125
|
-
`summarize`, `assertNoErrors`, `DiagnosticsFailure`
|
|
126
|
-
- Types: `DiagnosticsOptions`, `DiagnosticsReport`, `DiagnosticsSummary`,
|
|
127
|
-
`AnalyzerContentConfig`
|
|
128
|
-
- CLI: `riebeckite-diagnostics`
|
|
129
|
-
|
|
130
|
-
## See also
|
|
131
|
-
|
|
132
|
-
- [Plugin guide](../../../docs/en/plugin-
|
|
1
|
+
# @riebeckite/plugin-diagnostics
|
|
2
|
+
|
|
3
|
+
Content diagnostics for Obsidian vaults / Riebeckite content: broken links,
|
|
4
|
+
frontmatter issues, orphan notes, unused assets, and more. Usable as a build
|
|
5
|
+
plugin, a programmatic API, and a CLI.
|
|
6
|
+
|
|
7
|
+
[日本語](./README_ja.md)
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
`diagnostics()` analyzes the content directory and reports problems as
|
|
12
|
+
diagnostics during the build. The same checks are available through
|
|
13
|
+
`runDiagnostics()` and the `riebeckite-diagnostics` CLI.
|
|
14
|
+
|
|
15
|
+
## Usage (plugin)
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { defineConfig } from "@riebeckite/core";
|
|
19
|
+
import { diagnostics } from "@riebeckite/plugin-diagnostics";
|
|
20
|
+
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
// ...
|
|
23
|
+
plugins: [
|
|
24
|
+
diagnostics({
|
|
25
|
+
reportUnusedAssets: true,
|
|
26
|
+
reportOrphans: true,
|
|
27
|
+
requiredFrontmatter: ["title"],
|
|
28
|
+
}),
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
- `addDiagnostics` — runs the analysis at build time; results go to
|
|
34
|
+
`manifest.diagnostics`
|
|
35
|
+
- `onBuildEnd` — with `failOnError: true`, throws `DiagnosticsFailure` when
|
|
36
|
+
error-level diagnostics exist
|
|
37
|
+
|
|
38
|
+
## Checks
|
|
39
|
+
|
|
40
|
+
| Code | Default severity | What it detects |
|
|
41
|
+
| ---- | ---------------- | --------------- |
|
|
42
|
+
| `broken-wikilink` | `error` | Wikilink target or fragment does not resolve |
|
|
43
|
+
| `broken-image` | `error` | Embedded image or image link does not exist |
|
|
44
|
+
| `broken-link` | `error` | Markdown link points to a missing or excluded note/file |
|
|
45
|
+
| `unused-asset` | `warning` | Image never referenced by any note (`reportUnusedAssets`) |
|
|
46
|
+
| `orphan-note` | `info` | Published note has no incoming links (`reportOrphans`) |
|
|
47
|
+
| `missing-frontmatter` | `warning` | No frontmatter, or required fields missing |
|
|
48
|
+
| `publish-conflict` | `warning` | `publish: true` combined with `draft: true` / `private: true` |
|
|
49
|
+
| `duplicate-title` | `warning` | Multiple published notes share a title |
|
|
50
|
+
| `slug-collision` | `error` | Slugs collide case-insensitively |
|
|
51
|
+
| `duplicate-content-id` | `error` | Published notes share a stable content ID (`id`/`uid`) |
|
|
52
|
+
| `invalid-content-id` | `error` | `id`/`uid` frontmatter violates the stable content ID contract |
|
|
53
|
+
| `excluded-public` | `warning` | Excluded note is marked `publish: true` |
|
|
54
|
+
| `publish-boundary` | `warning` | Published content links to or embeds non-published content |
|
|
55
|
+
| `analytics-untracked` | `info` | Published note has no stable `id` and the analytics plugin will not track it (enabled with `reportAnalyticsCoverage`, or automatically when the config enables the analytics plugin) |
|
|
56
|
+
| `internal-error` | `error` | Content analysis failed |
|
|
57
|
+
|
|
58
|
+
## Options
|
|
59
|
+
|
|
60
|
+
| Option | Type | Default | Description |
|
|
61
|
+
| ------ | ---- | ------- | ----------- |
|
|
62
|
+
| `failOnError` | `boolean` | `false` | Fail the build on error-level diagnostics |
|
|
63
|
+
| `reportUnusedAssets` | `boolean` | `false` | Report unreferenced images |
|
|
64
|
+
| `reportOrphans` | `boolean` | `false` | Report published notes without incoming links |
|
|
65
|
+
| `reportAnalyticsCoverage` | `boolean` | `false` | Report published notes the analytics plugin will not track (auto-enabled when the resolved config enables the analytics plugin) |
|
|
66
|
+
| `requiredFrontmatter` | `string[]` | `[]` | Required frontmatter fields |
|
|
67
|
+
| `severity` | `Partial<Record<DiagnosticCode, DiagnosticSeverity>>` | table above | Override severity per code |
|
|
68
|
+
| `exclude` | `string[]` | `[]` | Extra exclude globs |
|
|
69
|
+
| `publishStrategy` | `"explicit" \| "selective"` | from config | Publication filter strategy |
|
|
70
|
+
|
|
71
|
+
## CLI
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
riebeckite-diagnostics --config riebeckite.config.ts
|
|
75
|
+
riebeckite-diagnostics --content ./content --report-orphans
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
| Option | Description |
|
|
79
|
+
| ------ | ----------- |
|
|
80
|
+
| `--config <path>` | Path to `riebeckite.config.ts` (loaded under tsx) |
|
|
81
|
+
| `--content <dir>` | Content directory to analyze (default: `.`) |
|
|
82
|
+
| `--exclude <glob>` | Extra exclude glob (repeatable) |
|
|
83
|
+
| `--publish-strategy <mode>` | `explicit` \| `selective` (default: `selective`) |
|
|
84
|
+
| `--report-unused-assets` | Report images never referenced by any note |
|
|
85
|
+
| `--report-orphans` | Report published notes with no incoming links |
|
|
86
|
+
| `--report-analytics-coverage` | Report published notes without a stable content ID (auto-enabled for `--config` when the config enables the analytics plugin) |
|
|
87
|
+
| `--required-frontmatter <f>` | Comma-separated required frontmatter fields |
|
|
88
|
+
| `--fail-on-error` | Exit with code 1 when errors are found (default) |
|
|
89
|
+
| `--exit-on <severity>` | Exit with code 1 at/above severity (`info` \| `warning` \| `error`) |
|
|
90
|
+
| `--format <text\|json>` | Output format (default: `text`) |
|
|
91
|
+
| `--no-color` | Disable ANSI colors |
|
|
92
|
+
| `-h`, `--help` | Show help |
|
|
93
|
+
|
|
94
|
+
Exit codes: `0` no errors, `1` errors reported (or `--exit-on` threshold met),
|
|
95
|
+
`2` invalid arguments.
|
|
96
|
+
|
|
97
|
+
With `--config`, options from the config's `diagnostics` plugin are used as
|
|
98
|
+
defaults; explicit CLI flags override them, and `exclude` lists are merged.
|
|
99
|
+
|
|
100
|
+
## Programmatic API
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import {
|
|
104
|
+
assertNoErrors,
|
|
105
|
+
formatDiagnostics,
|
|
106
|
+
runDiagnostics,
|
|
107
|
+
} from "@riebeckite/plugin-diagnostics";
|
|
108
|
+
|
|
109
|
+
const report = await runDiagnostics("./content", { reportOrphans: true });
|
|
110
|
+
console.log(formatDiagnostics(report));
|
|
111
|
+
assertNoErrors(report);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`runDiagnostics(config | path, options?)` returns a `DiagnosticsReport` with
|
|
115
|
+
`diagnostics`, `errors`, `warnings`, `infos`, `hasErrors`, `hasWarnings`,
|
|
116
|
+
`summary`, and `byCode`.
|
|
117
|
+
|
|
118
|
+
## Exports
|
|
119
|
+
|
|
120
|
+
- `diagnostics(options?)` / `diagnosticsPlugin` — plugin factory
|
|
121
|
+
- `runDiagnostics(target, options?)` — run the analysis directly
|
|
122
|
+
- `analyzeContent(config, options?)` — raw analysis returning `Diagnostic[]`
|
|
123
|
+
- `hasEnabledAnalyticsPlugin(config?)` — whether the resolved config enables the analytics plugin
|
|
124
|
+
- Report helpers: `buildReport`, `formatDiagnostics`, `groupByCode`,
|
|
125
|
+
`summarize`, `assertNoErrors`, `DiagnosticsFailure`
|
|
126
|
+
- Types: `DiagnosticsOptions`, `DiagnosticsReport`, `DiagnosticsSummary`,
|
|
127
|
+
`AnalyzerContentConfig`
|
|
128
|
+
- CLI: `riebeckite-diagnostics`
|
|
129
|
+
|
|
130
|
+
## See also
|
|
131
|
+
|
|
132
|
+
- [Plugin guide](../../../docs/en/reference/plugin-api.md)
|
package/README_ja.md
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
# @riebeckite/plugin-diagnostics
|
|
2
|
-
|
|
3
|
-
コンテンツのリンク切れ、公開設定の矛盾、frontmatter の不足などを検出するプラグインです。ビルド時の診断だけでなく、CLI とプログラムからの実行にも対応します。
|
|
4
|
-
|
|
5
|
-
[English](./README.md)
|
|
6
|
-
|
|
7
|
-
## まずはビルドに診断を加える
|
|
8
|
-
|
|
9
|
-
通常は `diagnostics()` を設定に登録します。診断結果は manifest に入り、`failOnError` を有効にするとエラーがあったビルドを失敗させられます。
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
import { defineConfig } from "@riebeckite/core";
|
|
13
|
-
import { diagnostics } from "@riebeckite/plugin-diagnostics";
|
|
14
|
-
|
|
15
|
-
export default defineConfig({
|
|
16
|
-
// ...
|
|
17
|
-
plugins: [
|
|
18
|
-
diagnostics({
|
|
19
|
-
reportUnusedAssets: true,
|
|
20
|
-
reportOrphans: true,
|
|
21
|
-
requiredFrontmatter: ["title"],
|
|
22
|
-
}),
|
|
23
|
-
],
|
|
24
|
-
});
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## 検出する問題
|
|
28
|
-
|
|
29
|
-
| コード | 既定の重要度 | 内容 |
|
|
30
|
-
| --- | --- | --- |
|
|
31
|
-
| `broken-wikilink` | error | Wikiリンクの参照先またはフラグメントを解決できない |
|
|
32
|
-
| `broken-image` | error | 埋め込み画像または画像リンクの参照先がない |
|
|
33
|
-
| `broken-link` | error | Markdown リンクが存在しない、または除外されたノートを指す |
|
|
34
|
-
| `unused-asset` | warning | どのノートからも参照されない画像 |
|
|
35
|
-
| `orphan-note` | info | 公開ノートのうち、他のノートからリンクされていないもの |
|
|
36
|
-
| `missing-frontmatter` | warning | frontmatter がない、または必須フィールドが欠けている |
|
|
37
|
-
| `publish-conflict` | warning | `publish: true` と `draft: true` または `private: true` が同居している |
|
|
38
|
-
| `duplicate-title` | warning | 公開ノート同士でタイトルが重複している |
|
|
39
|
-
| `slug-collision` | error | 大文字・小文字を区別しない slug が衝突している |
|
|
40
|
-
| `duplicate-content-id` | error | 公開ノート同士で安定コンテンツ ID(`id`/`uid`)が重複している |
|
|
41
|
-
| `invalid-content-id` | error | `id`/`uid` の frontmatter が安定コンテンツ ID の契約を満たしていない |
|
|
42
|
-
| `excluded-public` | warning | 除外されたノートに `publish: true` が指定されている |
|
|
43
|
-
| `publish-boundary` | warning | 公開コンテンツから非公開コンテンツへリンク・埋め込みしている |
|
|
44
|
-
| `analytics-untracked` | info | 安定 `id` のない公開ノートは analytics プラグインで計測されない(`reportAnalyticsCoverage` で有効化。設定で analytics プラグインが有効な場合は自動で有効化) |
|
|
45
|
-
| `internal-error` | error | コンテンツ解析中に処理できないエラーが発生した |
|
|
46
|
-
|
|
47
|
-
未使用アセットと孤立ノートは、明示的に有効化した場合だけ確認します。意図的に孤立させるトップページなどがあるなら、`reportOrphans` の結果を公開方針と照らして判断してください。
|
|
48
|
-
|
|
49
|
-
## 設定項目
|
|
50
|
-
|
|
51
|
-
| 項目 | 既定値 | 説明 |
|
|
52
|
-
| --- | --- | --- |
|
|
53
|
-
| `failOnError` | `false` | error レベルの診断があればビルドを失敗させる |
|
|
54
|
-
| `reportUnusedAssets` | `false` | 未参照画像を報告する |
|
|
55
|
-
| `reportOrphans` | `false` | 孤立した公開ノートを報告する |
|
|
56
|
-
| `reportAnalyticsCoverage` | `false` | analytics プラグインで計測されない公開ノートを報告する(解決済み設定で analytics プラグインが有効なら自動で有効化) |
|
|
57
|
-
| `requiredFrontmatter` | `[]` | 必須にする frontmatter フィールド |
|
|
58
|
-
| `severity` | コードごとの既定値 | 診断コード別の重要度を上書きする |
|
|
59
|
-
| `exclude` | `[]` | 解析対象から追加で除外する glob |
|
|
60
|
-
| `publishStrategy` | 設定ファイルの値 | 公開ノートの判定方法 |
|
|
61
|
-
|
|
62
|
-
## CI や編集時には CLI を使う
|
|
63
|
-
|
|
64
|
-
設定を読み込んで実行する場合は、次のようにします。
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
riebeckite-diagnostics --config riebeckite.config.ts
|
|
68
|
-
riebeckite-diagnostics --content ./content --report-orphans
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
`--format json` は機械処理用、`--exit-on warning` は警告以上を CI の失敗条件にしたい場合に使います。終了コードは、問題なしが `0`、指定したしきい値以上の診断があれば `1`、引数の誤りは `2` です。`--config` 使用時は設定内のオプションを既定値にし、CLI で明示した値を優先します。
|
|
72
|
-
|
|
73
|
-
## アプリケーションから実行する
|
|
74
|
-
|
|
75
|
-
エディタ連携や独自のレポートには `runDiagnostics()` を使えます。
|
|
76
|
-
|
|
77
|
-
```ts
|
|
78
|
-
import {
|
|
79
|
-
assertNoErrors,
|
|
80
|
-
formatDiagnostics,
|
|
81
|
-
runDiagnostics,
|
|
82
|
-
} from "@riebeckite/plugin-diagnostics";
|
|
83
|
-
|
|
84
|
-
const report = await runDiagnostics("./content", { reportOrphans: true });
|
|
85
|
-
console.log(formatDiagnostics(report));
|
|
86
|
-
assertNoErrors(report);
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
`DiagnosticsReport` には診断の一覧に加え、エラー・警告・情報の件数、コード別の集計、`hasErrors` と `hasWarnings` が入ります。
|
|
90
|
-
|
|
91
|
-
## 主なエクスポート
|
|
92
|
-
|
|
93
|
-
- `diagnostics(options?)` / `diagnosticsPlugin`: プラグインを作成する
|
|
94
|
-
- `runDiagnostics(target, options?)`: 診断と集計を実行する
|
|
95
|
-
- `analyzeContent(config, options?)`: 生の `Diagnostic[]` を取得する
|
|
96
|
-
- `hasEnabledAnalyticsPlugin(config?)`: 解決済み設定で analytics プラグインが有効かを判定する
|
|
97
|
-
- `formatDiagnostics`、`summarize`、`groupByCode`、`assertNoErrors`: レポート処理用の補助関数
|
|
98
|
-
- `DiagnosticsFailure`: `failOnError` または `assertNoErrors` が送出するエラー
|
|
99
|
-
- `riebeckite-diagnostics`: CLI
|
|
100
|
-
|
|
101
|
-
## 関連資料
|
|
102
|
-
|
|
103
|
-
- [プラグインシステム](../../../docs/ja/plugin-
|
|
1
|
+
# @riebeckite/plugin-diagnostics
|
|
2
|
+
|
|
3
|
+
コンテンツのリンク切れ、公開設定の矛盾、frontmatter の不足などを検出するプラグインです。ビルド時の診断だけでなく、CLI とプログラムからの実行にも対応します。
|
|
4
|
+
|
|
5
|
+
[English](./README.md)
|
|
6
|
+
|
|
7
|
+
## まずはビルドに診断を加える
|
|
8
|
+
|
|
9
|
+
通常は `diagnostics()` を設定に登録します。診断結果は manifest に入り、`failOnError` を有効にするとエラーがあったビルドを失敗させられます。
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { defineConfig } from "@riebeckite/core";
|
|
13
|
+
import { diagnostics } from "@riebeckite/plugin-diagnostics";
|
|
14
|
+
|
|
15
|
+
export default defineConfig({
|
|
16
|
+
// ...
|
|
17
|
+
plugins: [
|
|
18
|
+
diagnostics({
|
|
19
|
+
reportUnusedAssets: true,
|
|
20
|
+
reportOrphans: true,
|
|
21
|
+
requiredFrontmatter: ["title"],
|
|
22
|
+
}),
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 検出する問題
|
|
28
|
+
|
|
29
|
+
| コード | 既定の重要度 | 内容 |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| `broken-wikilink` | error | Wikiリンクの参照先またはフラグメントを解決できない |
|
|
32
|
+
| `broken-image` | error | 埋め込み画像または画像リンクの参照先がない |
|
|
33
|
+
| `broken-link` | error | Markdown リンクが存在しない、または除外されたノートを指す |
|
|
34
|
+
| `unused-asset` | warning | どのノートからも参照されない画像 |
|
|
35
|
+
| `orphan-note` | info | 公開ノートのうち、他のノートからリンクされていないもの |
|
|
36
|
+
| `missing-frontmatter` | warning | frontmatter がない、または必須フィールドが欠けている |
|
|
37
|
+
| `publish-conflict` | warning | `publish: true` と `draft: true` または `private: true` が同居している |
|
|
38
|
+
| `duplicate-title` | warning | 公開ノート同士でタイトルが重複している |
|
|
39
|
+
| `slug-collision` | error | 大文字・小文字を区別しない slug が衝突している |
|
|
40
|
+
| `duplicate-content-id` | error | 公開ノート同士で安定コンテンツ ID(`id`/`uid`)が重複している |
|
|
41
|
+
| `invalid-content-id` | error | `id`/`uid` の frontmatter が安定コンテンツ ID の契約を満たしていない |
|
|
42
|
+
| `excluded-public` | warning | 除外されたノートに `publish: true` が指定されている |
|
|
43
|
+
| `publish-boundary` | warning | 公開コンテンツから非公開コンテンツへリンク・埋め込みしている |
|
|
44
|
+
| `analytics-untracked` | info | 安定 `id` のない公開ノートは analytics プラグインで計測されない(`reportAnalyticsCoverage` で有効化。設定で analytics プラグインが有効な場合は自動で有効化) |
|
|
45
|
+
| `internal-error` | error | コンテンツ解析中に処理できないエラーが発生した |
|
|
46
|
+
|
|
47
|
+
未使用アセットと孤立ノートは、明示的に有効化した場合だけ確認します。意図的に孤立させるトップページなどがあるなら、`reportOrphans` の結果を公開方針と照らして判断してください。
|
|
48
|
+
|
|
49
|
+
## 設定項目
|
|
50
|
+
|
|
51
|
+
| 項目 | 既定値 | 説明 |
|
|
52
|
+
| --- | --- | --- |
|
|
53
|
+
| `failOnError` | `false` | error レベルの診断があればビルドを失敗させる |
|
|
54
|
+
| `reportUnusedAssets` | `false` | 未参照画像を報告する |
|
|
55
|
+
| `reportOrphans` | `false` | 孤立した公開ノートを報告する |
|
|
56
|
+
| `reportAnalyticsCoverage` | `false` | analytics プラグインで計測されない公開ノートを報告する(解決済み設定で analytics プラグインが有効なら自動で有効化) |
|
|
57
|
+
| `requiredFrontmatter` | `[]` | 必須にする frontmatter フィールド |
|
|
58
|
+
| `severity` | コードごとの既定値 | 診断コード別の重要度を上書きする |
|
|
59
|
+
| `exclude` | `[]` | 解析対象から追加で除外する glob |
|
|
60
|
+
| `publishStrategy` | 設定ファイルの値 | 公開ノートの判定方法 |
|
|
61
|
+
|
|
62
|
+
## CI や編集時には CLI を使う
|
|
63
|
+
|
|
64
|
+
設定を読み込んで実行する場合は、次のようにします。
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
riebeckite-diagnostics --config riebeckite.config.ts
|
|
68
|
+
riebeckite-diagnostics --content ./content --report-orphans
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`--format json` は機械処理用、`--exit-on warning` は警告以上を CI の失敗条件にしたい場合に使います。終了コードは、問題なしが `0`、指定したしきい値以上の診断があれば `1`、引数の誤りは `2` です。`--config` 使用時は設定内のオプションを既定値にし、CLI で明示した値を優先します。
|
|
72
|
+
|
|
73
|
+
## アプリケーションから実行する
|
|
74
|
+
|
|
75
|
+
エディタ連携や独自のレポートには `runDiagnostics()` を使えます。
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import {
|
|
79
|
+
assertNoErrors,
|
|
80
|
+
formatDiagnostics,
|
|
81
|
+
runDiagnostics,
|
|
82
|
+
} from "@riebeckite/plugin-diagnostics";
|
|
83
|
+
|
|
84
|
+
const report = await runDiagnostics("./content", { reportOrphans: true });
|
|
85
|
+
console.log(formatDiagnostics(report));
|
|
86
|
+
assertNoErrors(report);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`DiagnosticsReport` には診断の一覧に加え、エラー・警告・情報の件数、コード別の集計、`hasErrors` と `hasWarnings` が入ります。
|
|
90
|
+
|
|
91
|
+
## 主なエクスポート
|
|
92
|
+
|
|
93
|
+
- `diagnostics(options?)` / `diagnosticsPlugin`: プラグインを作成する
|
|
94
|
+
- `runDiagnostics(target, options?)`: 診断と集計を実行する
|
|
95
|
+
- `analyzeContent(config, options?)`: 生の `Diagnostic[]` を取得する
|
|
96
|
+
- `hasEnabledAnalyticsPlugin(config?)`: 解決済み設定で analytics プラグインが有効かを判定する
|
|
97
|
+
- `formatDiagnostics`、`summarize`、`groupByCode`、`assertNoErrors`: レポート処理用の補助関数
|
|
98
|
+
- `DiagnosticsFailure`: `failOnError` または `assertNoErrors` が送出するエラー
|
|
99
|
+
- `riebeckite-diagnostics`: CLI
|
|
100
|
+
|
|
101
|
+
## 関連資料
|
|
102
|
+
|
|
103
|
+
- [プラグインシステム](../../../docs/ja/reference/plugin-api.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-diagnostics",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"remark-parse": "^11.0.0",
|
|
21
21
|
"unified": "^11.0.5",
|
|
22
22
|
"unist-util-visit": "^5.1.0",
|
|
23
|
-
"@riebeckite/core": "0.0.
|
|
23
|
+
"@riebeckite/core": "0.0.13"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/mdast": "^4.0.4",
|