@wcstack/lint 1.31.0 → 1.33.0
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.ja.md +35 -3
- package/README.md +35 -3
- package/dist/cli.cjs +986 -459
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -26,7 +26,7 @@ npx wcs-validate --errors-only src/**/*.html
|
|
|
26
26
|
`<wcs-state src="...">` で参照される外部 state(`.json` / `.js` / `.ts`)は HTML ファイルからの相対パスで解決され、パス検証の対象になります。URL・絶対パスは読み込まず、読めないファイルはスキップされ、解決できないパスは warning のままです。なお外部 state が**解決できた**ページには通常の検証面が全て適用されるため、error severity の検出(例: 配列でない値への `for:`)が「これまでパス未解決で沈黙していたビルド」を新たに落とすことがあります。
|
|
27
27
|
|
|
28
28
|
```
|
|
29
|
-
wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--errors-only] <file> [<file> ...]
|
|
29
|
+
wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--errors-only] [--strict] <file> [<file> ...]
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
| オプション | 説明 |
|
|
@@ -35,6 +35,7 @@ wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--errors-
|
|
|
35
35
|
| `--state-tag=<name>` | state カスタム要素のタグ名(既定 `wcs-state`) |
|
|
36
36
|
| `--lang=ja\|en` | 診断メッセージの言語。未指定時は環境ロケール(`LC_ALL` / `LC_MESSAGES` / `LANG` → OS ロケール)に従う。code / range は言語に依らず不変 |
|
|
37
37
|
| `--errors-only`(別名 `--quiet`) | error severity の行だけ表示。warning / info の件数と exit code は不変 |
|
|
38
|
+
| `--strict` | warning severity の診断でも exit `1` にする。severity 自体は不変(IDE の表示と同じ)で、exit code の閾値だけを error → warning に下げる。summary 行の末尾に `(strict)` が付く。パスの typo(`wcs/binding-path-missing` は warning)で CI を落としたいときに使う — ただし先に `<wcs-state src>` を全て解決可能にしておくこと(解決できない外部 state が残す warning でも落ちるようになる)。`--errors-only` と併用可: 表示は error のみのまま、exit code は warning を反映する |
|
|
38
39
|
|
|
39
40
|
## 出力と exit code
|
|
40
41
|
|
|
@@ -49,10 +50,41 @@ app.manifest.json:1:3 error wcs/manifest-broken Broken manifest JSON: ...
|
|
|
49
50
|
|
|
50
51
|
| exit code | 意味 |
|
|
51
52
|
|---|---|
|
|
52
|
-
| `0` | error severity の診断なし(warning / info
|
|
53
|
-
| `1` | error severity の診断が 1 件以上 |
|
|
53
|
+
| `0` | error severity の診断なし(warning / info はあってもよい)。`--strict` 時は error も warning もなし |
|
|
54
|
+
| `1` | error severity の診断が 1 件以上。`--strict` 時は error または warning が 1 件以上 |
|
|
54
55
|
| `2` | usage エラー、またはファイル読み取り失敗 |
|
|
55
56
|
|
|
57
|
+
## state の契約を宣言する(`stateSchema`)
|
|
58
|
+
|
|
59
|
+
契約が無いと、validator が解決できないパスは **warning**(`wcs/binding-path-missing`)に留まります: インラインスクリプトが静的に読めなくても `count` は実行時には存在するかもしれないからです。HTML と同じ(または上の)ディレクトリに `application` sidecar を置くと、同じ typo が **error** になります:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"schemaVersion": 1,
|
|
64
|
+
"kind": "application",
|
|
65
|
+
"manifestExtensions": {
|
|
66
|
+
"wcstack.application": {
|
|
67
|
+
"version": 1,
|
|
68
|
+
"states": {
|
|
69
|
+
"default": {
|
|
70
|
+
"stateSchema": {
|
|
71
|
+
"type": "object",
|
|
72
|
+
"properties": {
|
|
73
|
+
"count": { "type": "number" },
|
|
74
|
+
"users": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" } } } }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- **発見**: HTML ファイルから上へ辿って最も近い `wcstack.manifest.json` が自動で使われます — コマンドラインに渡す必要はありません。`application` artifact を含む `*.manifest.json` を引数に渡した場合は、その実行全体で発見を置き換えます。VS Code 拡張も同じファイルを発見するので IDE と CLI の結果は一致します。
|
|
85
|
+
- **効果**: `stateSchema` を持つ state では、schema 上に確定的に存在しないバインドパスは `wcs/path-nonexistent`(**error**・exit `1`)、`for:` に非配列は `wcs/path-type-mismatch`(**error**)になります。schema が開いたままの箇所(素の `{}`)は沈黙し、インラインスクリプトのメソッド / getter / `$listKeys` は引き続き存在扱いです。schema の無い state は従来どおりです。
|
|
86
|
+
- **schema の出どころ**: 手で書く(受け付けるのは JSON-Schema サブセット `type / properties / required / items / enum / const / anyOf / $defs / $ref` のみ)か、TypeScript の state ファイルから `wcs-schema`(`@wcstack/typescript`)で生成します。manifest は派生物なので、CI では `wcs-schema check` で同期を保ってください。
|
|
87
|
+
|
|
56
88
|
## 生成 → 検証 → 修正ループでの利用
|
|
57
89
|
|
|
58
90
|
安定した diagnostic code・`source:line:col` range・exit code 契約により、CI のゲートにも AI コード生成フローにもそのまま組み込めます: HTML を生成 → `npx @wcstack/lint --errors-only` → 診断を読んで修正 → exit code `0` になるまで再実行。
|
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Files ending in `.manifest.json` are validated as sidecar manifests; everything
|
|
|
26
26
|
External state referenced via `<wcs-state src="...">` (`.json` / `.js` / `.ts`) is resolved relative to the HTML file and included in path validation. URLs and absolute paths are never read, unreadable files are skipped, and unresolved paths stay warnings. Note that once external state *does* resolve, the full validation surface applies to those pages — error-severity findings (e.g. `for:` bound to a non-array) can fail a build that was previously silent because the paths could not be checked.
|
|
27
27
|
|
|
28
28
|
```
|
|
29
|
-
wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--errors-only] <file> [<file> ...]
|
|
29
|
+
wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--errors-only] [--strict] <file> [<file> ...]
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
| Option | Description |
|
|
@@ -35,6 +35,7 @@ wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--errors-
|
|
|
35
35
|
| `--state-tag=<name>` | State custom-element tag name (default `wcs-state`) |
|
|
36
36
|
| `--lang=ja\|en` | Diagnostic message language. Defaults to the environment locale (`LC_ALL` / `LC_MESSAGES` / `LANG`, then the OS locale); codes and ranges are language-independent |
|
|
37
37
|
| `--errors-only` (alias `--quiet`) | Print only error-severity lines; warning/info counts and the exit code are unchanged |
|
|
38
|
+
| `--strict` | Exit `1` on warning-severity diagnostics too. Severities are unchanged (the IDE shows the same thing); only the exit-code threshold moves from error to warning. The summary line ends with `(strict)`. Use it to fail CI on a path typo (`wcs/binding-path-missing` is a warning) — but resolve every `<wcs-state src>` first (an unresolvable external state leaves warnings that would now fail the build). Combines with `--errors-only`: output stays error-only, the exit code still reflects warnings |
|
|
38
39
|
|
|
39
40
|
## Output & exit codes
|
|
40
41
|
|
|
@@ -49,10 +50,41 @@ app.manifest.json:1:3 error wcs/manifest-broken Broken manifest JSON: ...
|
|
|
49
50
|
|
|
50
51
|
| Exit code | Meaning |
|
|
51
52
|
|---|---|
|
|
52
|
-
| `0` | No error-severity diagnostics (warnings/info may exist) |
|
|
53
|
-
| `1` | At least one error-severity diagnostic |
|
|
53
|
+
| `0` | No error-severity diagnostics (warnings/info may exist); with `--strict`, no error or warning |
|
|
54
|
+
| `1` | At least one error-severity diagnostic; with `--strict`, at least one error or warning |
|
|
54
55
|
| `2` | Usage error or unreadable file |
|
|
55
56
|
|
|
57
|
+
## Declaring a state contract (`stateSchema`)
|
|
58
|
+
|
|
59
|
+
Without a contract, a path the validator cannot resolve is only a **warning** (`wcs/binding-path-missing`): `count` may well exist at runtime even when the inline script cannot be read statically. Put an `application` sidecar next to (or above) the HTML and the same typo becomes an **error**:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"schemaVersion": 1,
|
|
64
|
+
"kind": "application",
|
|
65
|
+
"manifestExtensions": {
|
|
66
|
+
"wcstack.application": {
|
|
67
|
+
"version": 1,
|
|
68
|
+
"states": {
|
|
69
|
+
"default": {
|
|
70
|
+
"stateSchema": {
|
|
71
|
+
"type": "object",
|
|
72
|
+
"properties": {
|
|
73
|
+
"count": { "type": "number" },
|
|
74
|
+
"users": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" } } } }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- **Discovery**: the nearest `wcstack.manifest.json` walking up from the HTML file is used automatically — nothing to pass on the command line. Passing `*.manifest.json` arguments that contain an `application` artifact replaces discovery for the whole run. The VS Code extension discovers the same file, so IDE and CLI agree.
|
|
85
|
+
- **Effect**: for a state that has a `stateSchema`, a bound path that the schema definitely lacks is `wcs/path-nonexistent` (**error**, exit `1`); `for:` on a non-array is `wcs/path-type-mismatch` (**error**). Paths the schema leaves open (a bare `{}`) stay silent, and methods / getters / `$listKeys` from the inline script still count as existing. States without a schema are unchanged.
|
|
86
|
+
- **Where the schema comes from**: write it by hand (only the JSON-Schema subset `type / properties / required / items / enum / const / anyOf / $defs / $ref` is accepted), or generate it from a TypeScript state file with `wcs-schema` (`@wcstack/typescript`). The manifest is a derived artifact — keep it in sync with `wcs-schema check` in CI.
|
|
87
|
+
|
|
56
88
|
## Use in generate–validate–fix loops
|
|
57
89
|
|
|
58
90
|
Stable diagnostic codes, `source:line:col` ranges, and the exit-code contract make this CLI a drop-in gate for CI and for AI code-generation flows: generate HTML → `npx @wcstack/lint --errors-only` → read the diagnostics, fix, and re-run until exit code `0`.
|