@wcstack/lint 4.19.0 → 4.21.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 +21 -3
- package/README.md +21 -3
- package/dist/cli.cjs +724 -122
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -21,10 +21,14 @@ npm i -D @wcstack/lint
|
|
|
21
21
|
npx wcs-validate --errors-only src/**/*.html
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
4.20 から、シェルが展開しなかったパターンは CLI が自分で展開します: 在るファイルを名指さず、`*`・`**`・`?`・`[…]`・`{a,b}` を持つ引数をファイルに当てます。当て方はシェルと同じで、`*` は 1 つのディレクトリの中だけ・`.` で始まる名前には当たらず、`**` はディレクトリをまたぎますが `node_modules` と `.` で始まるディレクトリには入りません。cmd.exe と PowerShell はパターンをそのまま渡し、npm は Windows ではパッケージの scripts を cmd.exe で走らせるので、4.19 までは npm script の `wcs-validate templates/*.html` がそこで `cannot read templates/*.html` で失敗していました。何にも当たらないパターンは error です(`no file matches <パターン>`、exit code `2`)。どのシェルでも CLI に展開させるには、パターンを引用符で囲んでください(`"src/**/*.html"`): `globstar` の無い POSIX シェルは `**` を `*` と読みます。
|
|
25
|
+
|
|
24
26
|
`.manifest.json` で終わるファイルは sidecar manifest として、それ以外は `data-wcs` バインディングを含む HTML として検査されます。ただし framework のコンポーネントと script のファイル(`.js`・`.ts`・`.jsx`・`.tsx`・`.vue`・`.svelte`)は読みません(4.6 から。以前は HTML として読み、問題なしと報告していました)。
|
|
25
27
|
|
|
26
28
|
`<wcs-state src="...">` で参照される外部 state(`.json` / `.js` / `.ts`)は HTML ファイルからの相対パスで解決され、パス検証の対象になります。URL は読み込まず、/ から始まるパスは `--root`(下記)のときだけ読み、読めないファイルはスキップされ、解決できないパスは warning のままです。なお外部 state が**解決できた**ページには通常の検証面が全て適用されるため、error severity の検出(例: 配列でない値への `for:`)が「これまでパス未解決で沈黙していたビルド」を新たに落とすことがあります。4.4 から、`.js` / `.ts` の state にはスクリプトの規則(`wcs/nested-assign`・`wcs/array-mutation`・`wcs/on-handler-this`・`wcs/updated-callback-unbound` など)もかかります: ファイルの中の指摘はそのファイルで報告し(`state.js:12:5 error wcs/nested-assign …`)、何ページから読まれても 1 回だけ数え、IDE はページの `src` の値の上に出します。4.3 までは、外部 state ではパスだけを検査していました。4.10 から、名前で書いたキー — 短縮プロパティ(`export default { lang, t }`。`examples/router-i18n` の辞書のボリューム `<wcs-state mount="i18n" src="./i18n/state.js">`)や `items: ITEMS` — は、その名前が束縛する値の形を持ちます: モジュールの `const` か、相対パスからの import(import するファイルからの相対で読み、再 export の先も辿ります)。4.17 からは名前空間の import のメンバーも同じです(`import * as M from "./lib/music.js"` の `sound: M.DEFAULT_SOUND`)。4.9 までは短縮プロパティのキーをまったく読まなかったので、`i18n.t.*` の束縛はすべて `wcs/binding-path-missing` の誤報でした。値を計算する名前(実行時にロケールの辞書を合わせた辞書)や辿れない名前(素の指定子・URL・無いファイル)のキーは、その下のパスを検査せず、ページがその下を束ねていればキーの上で 1 回だけそう言います(`wcs/path-dynamic-unknown`、info)。キーか宣言に JSDoc の `@type {typeof import("./en.js").default}` を付けると、そのファイルのリテラルで検査します。
|
|
27
29
|
|
|
30
|
+
4.20 から、`{{ }}` はランタイムが束ねる場所でだけ束縛として読みます: テキストの中 — 属性の値(`aria-current="{{ x }}"`)や HTML コメントの中ではなく — で、文書の `<head>` の外(`<wcs-state>` は `<head>` を束ねません。そこの `{{ }}` やコメント束縛は `wcs/template-syntax` の warning です)。ページの state が `$behavior: { enableMustache: false }` を宣言していれば、`{{ }}` はどれも束縛として読みません — アイランドの横の CMS やサーバーのテンプレートの中括弧 — が、コメント束縛は検査します。設定は state のある場所で読みます: インライン・`json=`・`state=`・lint が読める `src=` のファイル(/ から始まるパスは `--root` のとき)。読めない state なら、`{{ }}` は従来どおり検査します。4.19 までは、そうした中括弧ごとに `wcs/binding-path-missing` の誤報と FOUC の info が出て、コメント束縛は 1 つずつ `wcs-text バインディング: …` の info を出していました(4.20 はもう出しません)。
|
|
31
|
+
|
|
28
32
|
```
|
|
29
33
|
wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--root=<dir>] [--errors-only] [--strict] <file> [<file> ...]
|
|
30
34
|
```
|
|
@@ -53,7 +57,7 @@ app.manifest.json:1:3 error wcs/manifest-broken Broken manifest JSON: ...
|
|
|
53
57
|
|---|---|
|
|
54
58
|
| `0` | error severity の診断なし(warning / info はあってもよい)。`--strict` 時は error も warning もなし |
|
|
55
59
|
| `1` | error severity の診断が 1 件以上。`--strict` 時は error または warning が 1 件以上 |
|
|
56
|
-
| `2` | usage
|
|
60
|
+
| `2` | usage エラー、またはファイル読み取り失敗。4.20 からは、何にも当たらないパターンも |
|
|
57
61
|
|
|
58
62
|
件数の後に、件数が何も語らないファイルを 2 つの注が挙げます(4.6 から。`--errors-only` でも出し、exit code は変えません):
|
|
59
63
|
|
|
@@ -65,9 +69,11 @@ nothing to check: index.html — no data-wcs binding, <wcs-*> tag or wcstack scr
|
|
|
65
69
|
|
|
66
70
|
`<wcs-*>` の要素を使う framework のアプリ(React・Vue)にはどちらも無く、ページはルートの要素を持つだけで、コンポーネントは読まれません。exit code `0` は、そのようなアプリを検査したという意味ではありません。代わりに見るべきことは [framework 統合の手引き](../../docs/framework-adapter-integration.ja.md) にあります。
|
|
67
71
|
|
|
72
|
+
4.20 から、束縛 — `data-wcs` 属性かコメント束縛 — があるのに `<wcs-state>` の無いファイルには、最初の束縛の上に `wcs/state-absent` の info を 1 つ出します: CMS の部分テンプレート・ファイルに分けたルートの中身・state をスクリプトで作るページには、パスを照らす state が無いので、パスは検査していません。4.19 までは、そうしたファイルは何も出さず `nothing to check:` にも載らなかったので、検査済みに見え、打ち間違い(`booking.totl`)が通っていました。state のあるページを検査するか、パスを `stateSchema`(下記)に宣言してください(宣言すれば出ません)。テキストの束縛が `{{ }}` だけのファイルは報告しません(中括弧だけでは、ほかのテンプレートエンジンのものかもしれません)。
|
|
73
|
+
|
|
68
74
|
## state の契約を宣言する(`stateSchema`)
|
|
69
75
|
|
|
70
|
-
契約が無いと、validator が解決できないパスは **warning**(`wcs/binding-path-missing`)に留まります: インラインスクリプトが静的に読めなくても `count` は実行時には存在するかもしれないからです。`[]` で始まるリストの行のフィールドは、行を足す・置き換える代入式の行リテラルから読みます。4.9 から、`map` で行を作り直す代入 — `this.rows = [...this.items].map((c) => ({ id: c.id, label: c.name }))`・`.filter(…).map((c) => { return { … }; })` — も、そうする getter と同じく読み、`{}` を種にしたキーへ代入したオブジェクトリテラルのキーも読みます(`this.fieldErrors = { date: "…" }` で `fieldErrors.date`。リテラルの中の spread は追いません)。4.17 から、`Array.from({ length: n }, (_, i) => ({ … }))`・`Array.from(source, (x) => ({ … }))` の mapper と、`[...Array(n).keys()]` に続く `map` も、getter でも代入でも同じに行の形を言います。4.16 まではその行の下の束縛がどれも `wcs/binding-path-missing` の誤報でした。4.11 から、モジュールの定数を spread する種 — `const EMPTY_DRAFT = { title: "", body: "" }` と `draft: { ...EMPTY_DRAFT }`、読めるファイルから import した定数も — は、そのリテラルのキーを持ちます(入れ子のものも。同じ名前は後に書いた方が勝ちます — オブジェクトを作るときと同じ)。リストの種の最初の行(`[{ ...ROW, id: 0 }]`)も同じです。4.17 からは、読めるファイルの名前空間の import のメンバー(`import * as M from "./lib/music.js"` の `sound: { ...M.DEFAULT_SOUND }`)も同じです。4.16 まではそのキーの下を検査しませんでした。4.10 まではそのキーの下の束縛がすべて `wcs/binding-path-missing` の誤報で、打ち間違い(`draft.titel`)も同じ警告でした。読めない spread — 呼び出し・`let`・読めない import — があれば、そのキーの下は検査せず、ページがその下を束ねていればキーの上で 1 回だけそう言います(`wcs/path-dynamic-unknown`、info)。外から届くリスト(`<wcs-fetch>` や `<wcs-storage>` が埋めるまで `null`)にはそのリテラルが無いので、プロパティの直前の JSDoc `@type` で形を宣言してください(`/** @type {{ id: number, name: string }[] | null} */ catalog: null`)。同じスクリプトの `@typedef` で行の型に名前を付け、`@type {Product[] | null}` と書いてもかまいません。本体から結果を読めない getter(`get keyRows() { return buildRows(this.sound); }`)も、getter の直前に同じように宣言します: getter は `@returns` か `@type` を結果の型として受けます(`/** @returns {{ label: string }[]} */ get keyRows() { … }`)— TypeScript と同じです。getter の `@type` は 4.17 から効きます。4.16 までは `@returns` だけが効き、getter の `@type` は何も言わずに無視されていました。HTML と同じ(または上の)ディレクトリに `application` sidecar を置くと、同じ typo が **error** になります:
|
|
76
|
+
契約が無いと、validator が解決できないパスは **warning**(`wcs/binding-path-missing`)に留まります: インラインスクリプトが静的に読めなくても `count` は実行時には存在するかもしれないからです。`[]` で始まるリストの行のフィールドは、行を足す・置き換える代入式の行リテラルから読みます。4.9 から、`map` で行を作り直す代入 — `this.rows = [...this.items].map((c) => ({ id: c.id, label: c.name }))`・`.filter(…).map((c) => { return { … }; })` — も、そうする getter と同じく読み、`{}` を種にしたキーへ代入したオブジェクトリテラルのキーも読みます(`this.fieldErrors = { date: "…" }` で `fieldErrors.date`。リテラルの中の spread は追いません)。4.17 から、`Array.from({ length: n }, (_, i) => ({ … }))`・`Array.from(source, (x) => ({ … }))` の mapper と、`[...Array(n).keys()]` に続く `map` も、getter でも代入でも同じに行の形を言います。4.16 まではその行の下の束縛がどれも `wcs/binding-path-missing` の誤報でした。4.11 から、モジュールの定数を spread する種 — `const EMPTY_DRAFT = { title: "", body: "" }` と `draft: { ...EMPTY_DRAFT }`、読めるファイルから import した定数も — は、そのリテラルのキーを持ちます(入れ子のものも。同じ名前は後に書いた方が勝ちます — オブジェクトを作るときと同じ)。リストの種の最初の行(`[{ ...ROW, id: 0 }]`)も同じです。4.17 からは、読めるファイルの名前空間の import のメンバー(`import * as M from "./lib/music.js"` の `sound: { ...M.DEFAULT_SOUND }`)も同じです。4.16 まではそのキーの下を検査しませんでした。4.10 まではそのキーの下の束縛がすべて `wcs/binding-path-missing` の誤報で、打ち間違い(`draft.titel`)も同じ警告でした。読めない spread — 呼び出し・`let`・読めない import — があれば、そのキーの下は検査せず、ページがその下を束ねていればキーの上で 1 回だけそう言います(`wcs/path-dynamic-unknown`、info)。外から届くリスト(`<wcs-fetch>` や `<wcs-storage>` が埋めるまで `null`)にはそのリテラルが無いので、プロパティの直前の JSDoc `@type` で形を宣言してください(`/** @type {{ id: number, name: string }[] | null} */ catalog: null`)。同じスクリプトの `@typedef` で行の型に名前を付け、`@type {Product[] | null}` と書いてもかまいません。本体から結果を読めない getter(`get keyRows() { return buildRows(this.sound); }`)も、getter の直前に同じように宣言します: getter は `@returns` か `@type` を結果の型として受けます(`/** @returns {{ label: string }[]} */ get keyRows() { … }`)— TypeScript と同じです。getter の `@type` は 4.17 から効きます。4.16 までは `@returns` だけが効き、getter の `@type` は何も言わずに無視されていました。4.20 から、そうした型の索引シグネチャ — `Record<string, T>`・`{ [key: string]: T }`・Closure の `Object<string, T>` — は、getter の `@returns` / `@type` でもキーの `@type` でも、その下のパスを開いたままにします(`stateSchema` の開いたオブジェクトと同じ): `/** @returns {Record<string, boolean>} */ get soldOut()` と `class.full: soldOut.e12` は報告しません。4.19 まではそうした束縛のそれぞれが `wcs/binding-path-missing` の誤報でした。`Record<"open" | "closed", T>` はフィールド `open` と `closed` を持ちます。HTML と同じ(または上の)ディレクトリに `application` sidecar を置くと、同じ typo が **error** になります:
|
|
71
77
|
|
|
72
78
|
```json
|
|
73
79
|
{
|
|
@@ -95,11 +101,23 @@ nothing to check: index.html — no data-wcs binding, <wcs-*> tag or wcstack scr
|
|
|
95
101
|
|
|
96
102
|
## ページの wcstack のスクリプトと lint の版
|
|
97
103
|
|
|
98
|
-
4.11 から、2
|
|
104
|
+
4.11 から、2 つの検査がページの読み込む wcstack のスクリプトを見ます。4.20 から 3 つ目が加わります。4.21 から `wcs/tag-package-missing` は error なので、`--errors-only` でも落ちます(4.20 までは warning で、`--errors-only` に隠れていました)。残りの 2 つは warning なので、`--strict` では落ち、`--errors-only` では落ちません。
|
|
99
105
|
|
|
100
106
|
- **`wcs/tag-package-missing`** — wcstack を自分で読み込むページが、あるパッケージの `wcs-*` のタグ(`<wcs-upload>` やそのヘルパー `<wcs-upload-header>`、`<wcs-state>`・`<wcs-router>` など)を書くのに、そのパッケージのスクリプトを読み込んでいない。要素は定義されず、束縛は待ち続けて何も起きず、コンソールにも何も出ません。パッケージごとに 1 回、最初のタグに、読み込む `/auto` を挙げて報告します。読み込んだと数えるのは、`<script src>`・import map の項目・インラインのスクリプトの import か文字列が `@wcstack/<pkg>`(版・CDN・ローカルのパスを問わない)か一括バンドル `wcstack`(state・router・fetch・storage・autoloader)を名指すものです。ローカルのスクリプト(`./app.js`)は、それが import する相対のモジュールとともに読み、名指すものを数えます。wcstack を自分で読み込まないページ(断片・バンドラのページ)、autoloader がいて `@components/` の import map が覆うタグ、読めないローカルのスクリプトがあるページでは報告しません。
|
|
107
|
+
- **`wcs/link-router-missing`**(4.20 から) — router(か一括バンドル `wcstack`)を読み込むのに `<wcs-router>` の無いページの `<wcs-link to="/…">`。リンクは接続した時点で `[@wcstack/router] wcs-link is not connected to a router.` を投げ、隠れたまま(`display: none`)になります。router の無いページ — サーバーが描き、アイランドを置いたページ — では `<a href>` と書くか、`<wcs-router>` を置いてください。ページに 1 回、最初のそうしたリンクに報告します。見るのは `wcs/tag-package-missing` と同じページ(wcstack を自分で読み込むページ)だけです: 断片 — ルートの中身・router のページが取り込むレイアウトのファイル — は wcstack のスクリプトを読み込まないので報告せず、HTML コメントの外のどこかで `wcs-router` を名指すページ(`<template>` の中の `<wcs-router>`・それを作るスクリプトも)、router が無くても描かれる URL やクエリ(`?page=2`)の `to` も報告しません。
|
|
101
108
|
- **`wcs/lint-version-behind`** — ページの URL が、この lint より新しい minor を固定している: `@wcstack/state@4.11.0` を `@wcstack/lint@4.10.1` で検査する。lint が持つのは自分の版の規則なので(`@wcstack/state` と lockstep で出ます)、新しい minor で加わったものは検査されず、新しい minor の正しい書き方を error にもします(4.2.0 の lint は 4.10 の `datetime(ja-JP,short,Asia/Tokyo)` を `wcs/filter-arity` にします)。ページに 1 回、いちばん新しい固定に、`@wcstack/lint` をその版に上げるよう言います — `package.json` の lint はページが固定する版に揃えてください。版の無い URL・major だけの固定(`@4`)・lint の方が新しいときは報告しません。
|
|
102
109
|
|
|
110
|
+
## ページを直す保守担当に言うこと
|
|
111
|
+
|
|
112
|
+
4.21 から、継ぎ目アプリ ledger-repair — 目録の誤りを 10 件入れた家計簿を、外の保守担当がコンソール・この lint・DevTools のオーバーレイ・文書で直した — から:
|
|
113
|
+
|
|
114
|
+
- **`wcs/submit-without-prevent` と `wcs/tag-package-missing` は error です。** 報告するところでは必ず不具合です — フォームも自分を送る(router があれば GET がパスワードを URL に載せる)、要素がけっして定義されない — が、warning だったので `--errors-only` に隠れていました。`wcs/binding-path-missing` は warning のままです: `stateSchema` が無いと、値が外から届くこともあるためです。
|
|
115
|
+
- **`wcs/session-read-at-module-top`** — `<wcs-guard-handler>` のモジュール(error)や `<wcs-state>` のモジュール(インライン・`src=`。warning)のトップレベルでの `localStorage` / `sessionStorage` / `document.cookie` の読み。router はガードのモジュールを 1 回だけ評価し、export した関数を遷移のたびに走らせるので、関数の外でセッションを読むガードは、ページを読み込んだ時点のセッションを持ち続けます: ログインの後も、守られたページはすべて /login へ戻り、何も知らせませんでした。関数の中で読んでください。関数の中(そこから呼ぶ補助関数・getter・メソッド)の読みは報告しません。
|
|
116
|
+
- **`wcs/event-token-unbound`**(warning) — `wcs/command-token-unbound` の逆: `$eventTokens` に宣言したのに、ページのどの `eventToken.<メンバー>: <名前>` 束縛も出さない名前。`$on` のハンドラは走りません(ページは束縛を外して `deleteFetch.status` を watch していましたが、2 回目の 204 ではそれは変わりません)。lint の見ない束縛が出しうるページ — `<wcs-layout src>` のあるページ、`eventToken.` の束縛を書くスクリプトのあるページ — では報告しません。
|
|
117
|
+
- 行に無いフィールドの近くに行のフィールドがあれば名指します — `パス ".amountLabl" は状態定義に存在しません(展開: rows.*.amountLabl)。もしかして: "amountLabel"`。行の形はどこから読んだものでもかまいません: データのリスト・getter の map のリテラル・JSDoc の型。
|
|
118
|
+
- 配列と分からない値(`budgetErrors: {}` と `this.budgetErrors[id] = …`)への `wcs/array-index-assign` は、「配列の添字」ではなくオブジェクトのキーへの代入として言います。
|
|
119
|
+
- スクリプトがその場で変えるリスト(`this.budgetRows.splice(0, n, ...rows)` — `wcs/array-mutation` が報告する)の行は、リテラルや JSDoc の型からフィールドが読めなければ検査しません。4.20 までは、そうした行のフィールドがどれも `wcs/binding-path-missing` の誤報で、本物の打ち間違いと同じ code でした。
|
|
120
|
+
|
|
103
121
|
## 生成 → 検証 → 修正ループでの利用
|
|
104
122
|
|
|
105
123
|
安定した diagnostic code・`source:line:col` range・exit code 契約により、CI のゲートにも AI コード生成フローにもそのまま組み込めます: HTML を生成 → `npx @wcstack/lint --errors-only` → 診断を読んで修正 → exit code `0` になるまで再実行。このゲートが覆うのは `data-wcs` のページです: 出力が `not read:` や `nothing to check:` で終わるときは、そのファイルは検査されていません。
|
package/README.md
CHANGED
|
@@ -21,10 +21,14 @@ npm i -D @wcstack/lint
|
|
|
21
21
|
npx wcs-validate --errors-only src/**/*.html
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
Since 4.20, the CLI expands a pattern itself when the shell has not: an argument that names no existing file and holds `*`, `**`, `?`, `[…]` or `{a,b}` is matched against the files, as a shell does — `*` stays in one directory and skips names that start with `.`; `**` crosses directories, but not `node_modules` or one whose name starts with `.`. cmd.exe and PowerShell pass a pattern through as it is, and npm runs a package's scripts with cmd.exe on Windows, so up to 4.19 `wcs-validate templates/*.html` in an npm script failed there with `cannot read templates/*.html`. A pattern that matches no file is an error (`no file matches <pattern>`, exit code `2`). Quote the pattern (`"src/**/*.html"`) to have the CLI expand it on every shell: a POSIX shell without `globstar` reads `**` as `*`.
|
|
25
|
+
|
|
24
26
|
Files ending in `.manifest.json` are validated as sidecar manifests; everything else is validated as HTML with `data-wcs` bindings, except a framework's components and script files (`.js`, `.ts`, `.jsx`, `.tsx`, `.vue`, `.svelte`), which are not read (since 4.6; before, they were read as HTML and reported clean).
|
|
25
27
|
|
|
26
28
|
External state referenced via `<wcs-state src="...">` (`.json` / `.js` / `.ts`) is resolved relative to the HTML file and included in path validation. URLs are never read, and a path from `/` only under `--root` (below), 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. Since 4.4 that includes the script rules (`wcs/nested-assign`, `wcs/array-mutation`, `wcs/on-handler-this`, `wcs/updated-callback-unbound` and the rest) on a `.js` / `.ts` state: a finding in the file is reported in the file (`state.js:12:5 error wcs/nested-assign …`), once however many pages load it, and the IDE shows it on the page's `src` value. Up to 4.3 only the paths of an external state were checked. Since 4.10, a key written as a name — a shorthand (`export default { lang, t }`, the dictionary volume `<wcs-state mount="i18n" src="./i18n/state.js">` of `examples/router-i18n`) or `items: ITEMS` — has the shape of what the name is bound to: a `const` of the module, or an import from a relative path, which is read relative to the file that imports it (and the module it re-exports from) — since 4.17 a member of a namespace import too (`sound: M.DEFAULT_SOUND` with `import * as M from "./lib/music.js"`). Up to 4.9 a shorthand key was not read at all, so every `i18n.t.*` binding was a false `wcs/binding-path-missing`. A name whose value is computed (the dictionary merged from the locale catalogs at run time), or that it cannot follow (a bare specifier, a URL, a file that is not there), leaves the paths under that key unchecked, and says so once at the key when the page binds under it (`wcs/path-dynamic-unknown`, info); a JSDoc `@type {typeof import("./en.js").default}` on the key or on the declaration has them checked against that file's literal.
|
|
27
29
|
|
|
30
|
+
Since 4.20, `{{ }}` is read as a binding only where the runtime binds it: in text — not in an attribute value (`aria-current="{{ x }}"`) or an HTML comment — and outside the document's `<head>`, which a `<wcs-state>` does not bind (a `{{ }}` or a comment binding there is a `wcs/template-syntax` warning). When the page's state declares `$behavior: { enableMustache: false }`, no `{{ }}` is read as a binding at all — a CMS's or a server template's braces beside an island — while comment bindings are still checked. The setting is read where the state is: inline, `json=`, `state=`, or an `src=` file the lint can read (with `--root` for a path from `/`); a state it cannot read leaves `{{ }}` checked as before. Up to 4.19 each such brace pair was a false `wcs/binding-path-missing` and a FOUC info, and every comment binding printed a `wcs-text binding: …` info, which 4.20 no longer does.
|
|
31
|
+
|
|
28
32
|
```
|
|
29
33
|
wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--root=<dir>] [--errors-only] [--strict] <file> [<file> ...]
|
|
30
34
|
```
|
|
@@ -53,7 +57,7 @@ app.manifest.json:1:3 error wcs/manifest-broken Broken manifest JSON: ...
|
|
|
53
57
|
|---|---|
|
|
54
58
|
| `0` | No error-severity diagnostics (warnings/info may exist); with `--strict`, no error or warning |
|
|
55
59
|
| `1` | At least one error-severity diagnostic; with `--strict`, at least one error or warning |
|
|
56
|
-
| `2` | Usage error or unreadable file |
|
|
60
|
+
| `2` | Usage error or unreadable file; since 4.20, also a pattern that matches no file |
|
|
57
61
|
|
|
58
62
|
After the counts, two notes name the files the counts say nothing about (since 4.6; printed with `--errors-only` too, and they do not change the exit code):
|
|
59
63
|
|
|
@@ -65,9 +69,11 @@ nothing to check: index.html — no data-wcs binding, <wcs-*> tag or wcstack scr
|
|
|
65
69
|
|
|
66
70
|
A framework app (React, Vue) that uses the `<wcs-*>` elements has neither: its page holds the root element and its components are not read. Exit code `0` does not mean such an app was checked; [the framework integration guide](../../docs/framework-adapter-integration.md) lists what to look for instead.
|
|
67
71
|
|
|
72
|
+
Since 4.20, a file with bindings — a `data-wcs` attribute or a comment binding — and no `<wcs-state>` gets one `wcs/state-absent` info, at its first binding: a CMS's partial template, a route's content in a file of its own, or a page whose state a script makes has no state to check the paths against, so they are not checked. Up to 4.19 such a file printed nothing and was not listed under `nothing to check:` either, so it looked checked while a typo (`booking.totl`) passed. Check the page that holds the state, or declare the paths in a `stateSchema` (below), which silences it. A file whose only text bindings are `{{ }}` is not reported (braces alone may be another template engine's).
|
|
73
|
+
|
|
68
74
|
## Declaring a state contract (`stateSchema`)
|
|
69
75
|
|
|
70
|
-
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. Note that a list starting as `[]` does not need a contract just to name its row fields — the analyzer reads them from the row literals in the assignments that add or replace rows (`this.items = this.items.concat({ id, kind: "general" })`, `.toSpliced(i, n, { … })`, `.with(i, { … })`, `[...this.items, { … }]`); only a row passed as a variable (`concat(row)`) is invisible to it. Since 4.9 it also reads an assignment that rebuilds the rows with `map` — `this.rows = [...this.items].map((c) => ({ id: c.id, label: c.name }))`, `.filter(…).map((c) => { return { … }; })` — the way it reads a getter that does, and the keys of an object literal assigned to a key seeded `{}` (`this.fieldErrors = { date: "…" }` gives `fieldErrors.date`; a spread inside the literal is not followed). Since 4.17 the mapper of `Array.from({ length: n }, (_, i) => ({ … }))` and `Array.from(source, (x) => ({ … }))`, and a `map` after `[...Array(n).keys()]`, give the rows the same way, in a getter and in an assignment; up to 4.16 each binding under such rows was a false `wcs/binding-path-missing`. Since 4.11 a seed that spreads a constant of the module — `draft: { ...EMPTY_DRAFT }` with `const EMPTY_DRAFT = { title: "", body: "" }`, or one imported from a file it reads — has that literal's keys (nested ones too; a later key of the same name wins, as when the object is built), and so does a list seed's first row (`[{ ...ROW, id: 0 }]`); since 4.17 so does a member of a namespace import of a file it reads (`sound: { ...M.DEFAULT_SOUND }` with `import * as M from "./lib/music.js"`), which up to 4.16 left the keys unchecked. Up to 4.10 every binding under such a key was a false `wcs/binding-path-missing`, and a typo (`draft.titel`) the same warning. A spread it cannot read — a call, a `let`, an import it cannot read — leaves the keys under that key unchecked, said once at the key when the page binds under it (`wcs/path-dynamic-unknown`, info). A list that arrives from outside — `null` until `<wcs-fetch>` or `<wcs-storage>` fills it — has no such literal: declare its shape with a JSDoc `@type` before the property (`/** @type {{ id: number, name: string }[] | null} */ catalog: null`), or name the row type with a `@typedef` in the same script and write `@type {Product[] | null}`. A getter whose result it cannot read from the body (`get keyRows() { return buildRows(this.sound); }`) is declared the same way, before the getter: a getter takes `@returns` or `@type` — `/** @returns {{ label: string }[]} */ get keyRows() { … }` — as its result type, as TypeScript does. `@type` counts on a getter since 4.17; up to 4.16 only `@returns` did, and a getter's `@type` was ignored without a word. Put an `application` sidecar next to (or above) the HTML and the same typo becomes an **error**:
|
|
76
|
+
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. Note that a list starting as `[]` does not need a contract just to name its row fields — the analyzer reads them from the row literals in the assignments that add or replace rows (`this.items = this.items.concat({ id, kind: "general" })`, `.toSpliced(i, n, { … })`, `.with(i, { … })`, `[...this.items, { … }]`); only a row passed as a variable (`concat(row)`) is invisible to it. Since 4.9 it also reads an assignment that rebuilds the rows with `map` — `this.rows = [...this.items].map((c) => ({ id: c.id, label: c.name }))`, `.filter(…).map((c) => { return { … }; })` — the way it reads a getter that does, and the keys of an object literal assigned to a key seeded `{}` (`this.fieldErrors = { date: "…" }` gives `fieldErrors.date`; a spread inside the literal is not followed). Since 4.17 the mapper of `Array.from({ length: n }, (_, i) => ({ … }))` and `Array.from(source, (x) => ({ … }))`, and a `map` after `[...Array(n).keys()]`, give the rows the same way, in a getter and in an assignment; up to 4.16 each binding under such rows was a false `wcs/binding-path-missing`. Since 4.11 a seed that spreads a constant of the module — `draft: { ...EMPTY_DRAFT }` with `const EMPTY_DRAFT = { title: "", body: "" }`, or one imported from a file it reads — has that literal's keys (nested ones too; a later key of the same name wins, as when the object is built), and so does a list seed's first row (`[{ ...ROW, id: 0 }]`); since 4.17 so does a member of a namespace import of a file it reads (`sound: { ...M.DEFAULT_SOUND }` with `import * as M from "./lib/music.js"`), which up to 4.16 left the keys unchecked. Up to 4.10 every binding under such a key was a false `wcs/binding-path-missing`, and a typo (`draft.titel`) the same warning. A spread it cannot read — a call, a `let`, an import it cannot read — leaves the keys under that key unchecked, said once at the key when the page binds under it (`wcs/path-dynamic-unknown`, info). A list that arrives from outside — `null` until `<wcs-fetch>` or `<wcs-storage>` fills it — has no such literal: declare its shape with a JSDoc `@type` before the property (`/** @type {{ id: number, name: string }[] | null} */ catalog: null`), or name the row type with a `@typedef` in the same script and write `@type {Product[] | null}`. A getter whose result it cannot read from the body (`get keyRows() { return buildRows(this.sound); }`) is declared the same way, before the getter: a getter takes `@returns` or `@type` — `/** @returns {{ label: string }[]} */ get keyRows() { … }` — as its result type, as TypeScript does. `@type` counts on a getter since 4.17; up to 4.16 only `@returns` did, and a getter's `@type` was ignored without a word. Since 4.20, an index signature in such a type — `Record<string, T>`, `{ [key: string]: T }`, Closure's `Object<string, T>` — on a getter's `@returns` / `@type` or a key's `@type` leaves the paths under it open, as a `stateSchema`'s open object does: `/** @returns {Record<string, boolean>} */ get soldOut()` with `class.full: soldOut.e12` is not reported, where up to 4.19 each such binding was a false `wcs/binding-path-missing`. `Record<"open" | "closed", T>` has the fields `open` and `closed`. Put an `application` sidecar next to (or above) the HTML and the same typo becomes an **error**:
|
|
71
77
|
|
|
72
78
|
```json
|
|
73
79
|
{
|
|
@@ -95,11 +101,23 @@ Without a contract, a path the validator cannot resolve is only a **warning** (`
|
|
|
95
101
|
|
|
96
102
|
## The page's wcstack scripts and the lint's version
|
|
97
103
|
|
|
98
|
-
Since 4.11, two
|
|
104
|
+
Since 4.11, two findings look at the wcstack scripts a page loads, and since 4.20 a third. Since 4.21, `wcs/tag-package-missing` is an error, so `--errors-only` fails on it too (up to 4.20 it was a warning, which `--errors-only` hid); the other two are warnings: `--strict` fails on them, `--errors-only` does not.
|
|
99
105
|
|
|
100
106
|
- **`wcs/tag-package-missing`** — a `wcs-*` tag of a wcstack package (`<wcs-upload>`, or its helper `<wcs-upload-header>`; `<wcs-state>`, `<wcs-router>` …) on a page that loads wcstack itself but no script of that package. The element is never defined, its bindings wait and nothing happens, and the console says nothing. Reported once per package, at its first tag, with the `/auto` to load. A script counts when a `<script src>`, an import map entry, or an import or a string in an inline script names `@wcstack/<pkg>` (any version, any CDN, a local path) or the `wcstack` bundle (state, router, fetch, storage, autoloader); a local script (`./app.js`) is read, with the relative modules it imports, for what it names. Not reported on a page that names no wcstack script itself (a fragment, a bundler's page), for a tag an `@components/` import map entry covers while the autoloader is there, or when a local script cannot be read.
|
|
107
|
+
- **`wcs/link-router-missing`** (since 4.20) — a `<wcs-link to="/…">` on a page that loads the router (or the `wcstack` bundle) but has no `<wcs-router>`: the link throws `[@wcstack/router] wcs-link is not connected to a router.` when it connects, and stays hidden (`display: none`). On a page without the router — a page a server renders, with islands in it — write `<a href>`, or add the `<wcs-router>`. Reported once per page, at the first such link, where `wcs/tag-package-missing` would look (a page that loads wcstack itself): a fragment — a route's content, a layout file the router page includes — loads no wcstack script and is not reported, nor is a page that names `wcs-router` anywhere outside an HTML comment (a `<wcs-router>`, in a `<template>` too, or a script that makes one), nor a `to` that is a URL or a query (`?page=2`), which renders without the router.
|
|
101
108
|
- **`wcs/lint-version-behind`** — a URL on the page pins a newer minor than this lint: `@wcstack/state@4.11.0` checked with `@wcstack/lint@4.10.1`. The lint carries the rules of its own version (it is released with `@wcstack/state`, in lockstep), so it does not check what the newer minor added, and it can report the newer minor's correct syntax as an error (4.2.0's lint gives `wcs/filter-arity` for 4.10's `datetime(ja-JP,short,Asia/Tokyo)`). Said once per page, at the newest pin: upgrade `@wcstack/lint` to that version — keep the lint in `package.json` at the version the page pins. A URL without a version, a major-only pin (`@4`) and a lint newer than the page are not reported.
|
|
102
109
|
|
|
110
|
+
## What a maintainer fixing a page is told
|
|
111
|
+
|
|
112
|
+
Since 4.21, from the ledger-repair seam app — a maintainer fixing a household-budget app with ten catalogued mistakes put in, with the console, this lint, the DevTools overlay and the documents:
|
|
113
|
+
|
|
114
|
+
- **`wcs/submit-without-prevent` and `wcs/tag-package-missing` are errors.** Where they are reported they are always bugs — a form that also submits itself (with the router, a GET that puts the password in the URL), an element that is never defined — and as warnings `--errors-only` hid them. `wcs/binding-path-missing` stays a warning: without a `stateSchema` the value may arrive from outside.
|
|
115
|
+
- **`wcs/session-read-at-module-top`** — a `localStorage` / `sessionStorage` / `document.cookie` read at the top level of a `<wcs-guard-handler>`'s module (an error) or of a `<wcs-state>`'s module, inline or `src=` (a warning). The router evaluates a guard's module once and runs its exported function on every navigation, so a guard that reads the session outside the function keeps the session there was when the page loaded: after the login, every guarded page went back to /login, and nothing said so. Read it inside the function; a read inside any function (a helper it calls, a getter, a method) is not reported.
|
|
116
|
+
- **`wcs/event-token-unbound`** (warning) — the mirror of `wcs/command-token-unbound`: a name `$eventTokens` declares that no `eventToken.<member>: <name>` binding on the page emits, so its `$on` handler never runs (the page had removed the binding and watched `deleteFetch.status`, which a second 204 does not change). Not reported where a binding the lint does not see can emit it: a page with a `<wcs-layout src>`, or a script that writes `eventToken.` bindings.
|
|
117
|
+
- A row field the rows lack, beside a near one they have, is named — `Path ".amountLabl" does not exist in the state definition (expanded: rows.*.amountLabl). Did you mean "amountLabel"?` — wherever the rows were read from: a data list, a getter's mapped literal, a JSDoc type.
|
|
118
|
+
- `wcs/array-index-assign` on a value not known to be an array (`budgetErrors: {}` with `this.budgetErrors[id] = …`) says it assigns an object's key, not "an array index".
|
|
119
|
+
- The rows of a list the script changes in place (`this.budgetRows.splice(0, n, ...rows)`, reported as `wcs/array-mutation`) are not checked when no literal or JSDoc type gives their fields. Up to 4.20 each such row field was a false `wcs/binding-path-missing`, the same code as a real typo.
|
|
120
|
+
|
|
103
121
|
## Use in generate–validate–fix loops
|
|
104
122
|
|
|
105
123
|
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`. The gate covers `data-wcs` pages: when the output ends with `not read:` or `nothing to check:`, those files were not checked.
|