@wcstack/lint 4.25.0 → 4.27.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 CHANGED
@@ -95,6 +95,7 @@ nothing to check: index.html — no data-wcs binding, <wcs-*> tag or wcstack scr
95
95
  ```
96
96
 
97
97
  - **発見**: HTML ファイルから上へ辿って最も近い `wcstack.manifest.json` が自動で使われます — コマンドラインに渡す必要はありません。`application` artifact を含む `*.manifest.json` を引数に渡した場合は、その実行全体で発見を置き換えます。VS Code 拡張も同じファイルを発見するので IDE と CLI の結果は一致します。
98
+ - **schema を当てるページ**(4.26 から): schema を作った state のファイルを記した manifest — `wcstack.application.stateSource`、manifest からの相対で、`wcs-schema emit` が書きます — は、そのファイルを root の `<wcs-state src>` で読むページだけの契約です(同じパスの `.js` と `.ts`、`.mjs` と `.mts` は同じファイル)。state がインラインのページや別のファイルのページは、発見した manifest でも引数に渡した manifest でも、manifest が無いものとして検査します。4.25 までは、アプリの schema をその下のすべてのページに当てていたので、アプリの隣で自前のインラインの state を持つページの正しいパスが `wcs/path-nonexistent` の error になっていました。`stateSource` の無い manifest(手書き・それより前の `wcs-schema` が作ったもの)は、これまでどおりすべてのページに当てます。
98
99
  - **効果**: `stateSchema` を宣言すると、schema 上に確定的に存在しないバインドパスは `wcs/path-nonexistent`(**error**・exit `1`)、`for:` に非配列は `wcs/path-type-mismatch`(**error**)になります。schema が開いたままの箇所(素の `{}`)は沈黙し、インラインスクリプトのメソッド / getter / `$listKeys` は引き続き存在扱いです。`stateSchema` が無ければ従来どおりです。
99
100
  - **契約が要るとき**: validator が全体を読めない state は、契約が無いとパスをまったく検査できません。よくあるのはトップレベルの spread です — `export default { ...defaults(), get total() { … } }` は静的には見えないキーを持ち込むので、その state のパスは検査しません。4.4 から、spread の上で 1 回だけそう言います(`wcs/path-dynamic-unknown`、info)。`stateSchema` があれば束縛を —— 4.4 から getter の中で読むパス(`wcs/read-path-missing`)も —— それで検査します。読めない `<wcs-state src>` — / から始まるパス・URL・無いファイル — の state も検査できません。4.7 から、それを属性の上で 1 回だけ言います(`wcs/state-src-unread`、info)。4.6 までは何も言いませんでした。`src` はページからの相対パスで読むので、ファイルはサーバーと同じ並びに置き、/ から始まるパスには 4.10 から `--root=<dir>` を渡してください。
100
101
  - **schema の出どころ**: 手で書く(受け付けるのは JSON-Schema サブセット `type / properties / required / items / enum / const / anyOf / $defs / $ref` のみ)か、TypeScript の state ファイル(または JSDoc で型を付けた JavaScript のファイル)から `wcs-schema`(`@wcstack/typescript`)で生成します。manifest は派生物なので、CI では `wcs-schema check` で同期を保ってください。
@@ -158,6 +159,22 @@ nothing to check: index.html — no data-wcs binding, <wcs-*> tag or wcstack scr
158
159
 
159
160
  広がった `wcs/path-readonly` と `wcs/token-undeclared` の error は `--errors-only` にも出ます。新しい 4 つの warning は `--strict` で失敗します。
160
161
 
162
+ ## TypeScript で書くチームに言うこと
163
+
164
+ 4.26 から、継ぎ目アプリ lending-desk — TypeScript で書くチームの備品の貸出窓口: `.ts` の state、生成した `stateSchema`、`.ts` のモジュールで定義する要素、1 つの共有ファイルに置いた API の型。そのページは、比較の綴り違いのステータス、ステッパーに無いメンバーへの束縛、読むものの半分しか追跡しない getter、manifest には残っている 3 つの改名したキーなどを抱えたまま、この lint を 0 error・0 warning で通っていました。そこへ行き着くために、ハンドラの戻りの型も外していました。いま言うこと:
165
+
166
+ - **`.ts` の state の戻りの型を読みます。** `get total(): number {`・`submit(e: Event): void {`・`$watch` の `count(cur: number): void {` — オブジェクト型・合併・`Promise<…>`・型引数・型述語も — でメンバーが隠れなくなりました。4.25 までは、そのメンバーを読まず: ページに束ねた getter やメソッドは `wcs/binding-path-missing`(`stateSchema` があれば `wcs/path-nonexistent` — メソッドは schema に無い)、ハンドラの引数の `cur:` は `$watch` のキー(`wcs/watch-path-missing "cur"`)になり、スクリプトの規則(`wcs/getter-untracked-read`・`wcs/nested-assign`・`wcs/array-mutation` …)は型付きの getter を飛ばしていました。TypeScript の構文のある本体(`x as T`・`y!`・型付きの局所変数)・state が import する `.ts` のモジュール・ページの `.ts` のモジュールは、Node の `module.stripTypeScriptTypes` で型を消して読みます(Node 22.13 以降。それより古い Node では従来どおり検査しません)。パッケージは足していません: `@wcstack/lint` は依存ゼロのままです。
167
+ - **`wcs/tag-member-unknown` は TypeScript で定義した要素も読みます。** `<script type="module" src="./main.ts">` とそれが import する `.ts`(`./x.js` の import は `.js` が無ければ `./x.ts`、拡張子の無い import は `./x.ts` → `./x.js`): `static wcBindable = { … } as const satisfies Decl` もリテラルです。4.25 までは `.js` / `.mjs` のモジュールだけを読んでいたので、`max` を宣言するステッパーへの `maximum:` が通り、ステッパーは上限を持ちませんでした。
168
+ - **`wcs/filter-arg-enum`**(warning) — 比べる値が決して取らないリテラルを引数にした比較のフィルタ(`eq` / `ne`): 型が `"pending" | "approved" | "denied"` のときの `class.st-approved: .status|eq('aproved')`(`stateSchema` の `enum` / `const` / `anyOf` の const、JSDoc のリテラルの合併 — `@typedef` や import した型を通しても)。`eq` は決して真にならず(`ne` はいつも真)、バッジの色は黙って出ません。取りうる値と綴りの近い値を挙げます。パスに最初にかけたフィルタだけを見ます。
169
+ - **`wcs/filter-input-type` は、持っている型を使います。** 行のパス(`for: rows` の中の `.label|toFixed(0)`)は、展開した行のフィールドの型 — リテラルの行・JSDoc の型・`stateSchema`(getter も: schema が string と言う `.depositLabel|toFixed(0)`)— で読みます。日付のフィルタ(`date`・`time`・`datetime`・`ymd`・`hms`)はランタイムと同じく `Date` だけを受けます(null 以外はランタイムが throw する): ISO の文字列への `.at|date` を報告します。4.25 までは、リテラルの種を持つ書き切ったパスだけを検査していました。
170
+ - **別モジュールの JSDoc の型を読みます。** `/** @type {import("./api.ts").Reservation[]} */`・getter の `@returns {import("./api.ts").Reservation[]}`・`@typedef {import("./api").Reservation} Reservation`: 型をそのファイル — `.ts` / `.d.ts` の `interface` と `type`、`.js` の `@typedef` — から読み、その下に束ねた行を検査します。読めない型(ファイルが無い・名前が無い)のキーの下は検査せず、1 回だけそう言います(`wcs/path-dynamic-unknown`、info)— 分からないのであって、無いのではありません。4.25 までは、そのリストの下に束ねたフィールドが 1 件ずつ偽の `wcs/binding-path-missing` でした。
171
+ - **`[]` に落ちる getter の行を「無い」と言いません。** `get pickups() { return this.counter ? this.counter.pickups : []; }`(`X ?? []`・`X || []`・早い `return []` も)で `X` の形が分からないとき、行は分からないものとし、getter の上で 1 回言います(`wcs/path-dynamic-unknown`)。4.25 までは `[]` が行のフィールドをすべて `wcs/binding-path-missing` にしていました。行の分かるリスト(`this.items ?? []`)はこれまでどおり検査します。
172
+ - **`wcs/watch-path-missing` は `stateSchema` を見ます。** 束縛と同じく、schema が持つキーは報告せず、確かに持たないキーだけを報告します。
173
+ - **`wcs/drift-state-key`**(warning) — このページに当てた `stateSchema` と root の state のスクリプトの、トップレベルのキーの食い違い: `.ts` で `get displayName()` に名前を変え、manifest にはまだ `headerName` がある。古い schema はスクリプトに勝ち — 古い名前に残った束縛が通り(0 error・0 warning)、その後に足したキーは `wcs/path-nonexistent` でした。`<wcs-state>` の開始タグの上で 1 回、両側のキーを挙げ、作り直しの `wcs-schema emit` を案内します — CI ではこの lint の前に `wcs-schema check` を走らせてください。両側が分かるときだけ: 読み切れる root の state のスクリプト(トップレベルの spread・計算したキー・`$stream` / `$scan` が無い)と schema のトップレベルの properties。ボリュームのマウントの根は数えません。
174
+ - **schema はその state のページに当てます** — 上の「schema を当てるページ」。
175
+
176
+ `--errors-only` には TypeScript で新たに見つかる error(`.ts` のモジュールで定義した要素の `wcs/tag-member-unknown`・型付きの getter の `wcs/getter-untracked-read` …)が出ます。`--strict` は新しい 2 つの warning と、広がった `wcs/filter-input-type` でも失敗します。
177
+
161
178
  ## 生成 → 検証 → 修正ループでの利用
162
179
 
163
180
  安定した 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
@@ -95,6 +95,7 @@ Without a contract, a path the validator cannot resolve is only a **warning** (`
95
95
  ```
96
96
 
97
97
  - **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.
98
+ - **Which pages a schema is for** (since 4.26): a manifest that names the state file its schema was generated from — `wcstack.application.stateSource`, relative to the manifest, which `wcs-schema emit` writes — is the contract only of a page whose root `<wcs-state src>` loads that file (`.js` and `.ts`, `.mjs` and `.mts` of one path being one file). A page whose state is inline, or another file, is checked as if there were no manifest, whether the manifest was discovered or passed on the command line. Up to 4.25 the app's schema was applied to every page under it, so a page with its own inline state beside the app got `wcs/path-nonexistent` errors for its correct paths. A manifest without `stateSource` (hand-written, or generated by an earlier `wcs-schema`) applies to every page as before.
98
99
  - **Effect**: when a `stateSchema` is declared, 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. Without a `stateSchema`, behavior is unchanged.
99
100
  - **When a contract is needed**: a state the validator cannot read in full needs one for its paths to be checked at all. A top-level spread is the common case — `export default { ...defaults(), get total() { … } }` brings in keys no static reader sees, so the validator checks no path of that state, and since 4.4 it says so once, at the spread (`wcs/path-dynamic-unknown`, info). With a `stateSchema` the bindings — and, since 4.4, the paths the getters read (`wcs/read-path-missing`) — are checked against it. A `<wcs-state src>` it cannot read — a path from `/`, a URL, a file that is not there — leaves that state unchecked as well; since 4.7 it says so once, at the attribute (`wcs/state-src-unread`, info), where up to 4.6 it said nothing. It reads a `src` relative to the page: keep the files laid out as on the server, and since 4.10 pass `--root=<dir>` for a path from `/`.
100
101
  - **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 — or a JavaScript one with JSDoc types — with `wcs-schema` (`@wcstack/typescript`). The manifest is a derived artifact — keep it in sync with `wcs-schema check` in CI.
@@ -158,6 +159,22 @@ Since 4.25, from the stamp-rally seam app — a stamp rally on the screen and se
158
159
 
159
160
  `--errors-only` prints the wider `wcs/path-readonly` and `wcs/token-undeclared` errors; `--strict` also fails on the four new warnings.
160
161
 
162
+ ## What a TypeScript team is told
163
+
164
+ Since 4.26, from the lending-desk seam app — an equipment-lending desk written by a team that writes TypeScript: a `.ts` state, a generated `stateSchema`, page-defined elements in `.ts` modules, API types in one shared file. Its pages passed this lint with 0 errors and 0 warnings while it had made, among others, a misspelt status in a comparison, a binding to a member a stepper does not have, a getter that tracks only half of what it reads, and three renamed keys the manifest still had; and to get there it had taken the return types off its handlers. What it says now:
165
+
166
+ - **A `.ts` state's return types are read.** `get total(): number {`, `submit(e: Event): void {`, `count(cur: number): void {` in `$watch` — and object types, unions, `Promise<…>`, type parameters, type predicates — no longer hide the member. Up to 4.25 such a member was not read: a getter or a method bound in the page was `wcs/binding-path-missing` (with a `stateSchema`, `wcs/path-nonexistent` — methods are not in the schema), a handler's parameter `cur:` was read as a `$watch` key (`wcs/watch-path-missing "cur"`), and the script rules (`wcs/getter-untracked-read`, `wcs/nested-assign`, `wcs/array-mutation`, …) skipped the typed getters. A body with TypeScript syntax (`x as T`, `y!`, a typed local), a `.ts` module the state imports, and a page's `.ts` modules are read with their types erased, through Node's `module.stripTypeScriptTypes` (Node 22.13 or later; on an older Node they stay unchecked, as before). No package is added: `@wcstack/lint` keeps zero dependencies.
167
+ - **`wcs/tag-member-unknown` reads elements defined in TypeScript.** `<script type="module" src="./main.ts">` and the `.ts` modules it imports (an import of `./x.js` reads `./x.ts` when there is no `.js`; one without an extension, `./x.ts` then `./x.js`): `static wcBindable = { … } as const satisfies Decl` is the literal. Up to 4.25 only `.js` / `.mjs` modules were read, and `maximum:` on a stepper that declares `max` passed — the stepper was never limited.
168
+ - **`wcs/filter-arg-enum`** (warning) — a comparison filter (`eq` / `ne`) whose literal argument the compared value never takes: `class.st-approved: .status|eq('aproved')` where the type is `"pending" | "approved" | "denied"` (a `stateSchema` `enum` / `const` / `anyOf` of consts, a JSDoc literal union — through a `@typedef` or an imported type too). `eq` is never true (`ne` always), and the badge's colour silently never shows. The message names the values and a near one. Only for a filter applied first to the path.
169
+ - **`wcs/filter-input-type` uses the types it has.** A row's path (`.label|toFixed(0)` under `for: rows`) is typed as the row field it expands to — a literal row's, a JSDoc type's, a `stateSchema`'s (a getter's too: `.depositLabel|toFixed(0)` where the schema says string). The date filters (`date`, `time`, `datetime`, `ymd`, `hms`) take a `Date` only, as the runtime does (it throws for anything else but null): `.at|date` on an ISO string is reported. Up to 4.25 only a path written in full with a literal seed was checked.
170
+ - **A JSDoc type from another module is read.** `/** @type {import("./api.ts").Reservation[]} */`, a getter's `@returns {import("./api.ts").Reservation[]}`, a `@typedef {import("./api").Reservation} Reservation`: the type is read from that file — an `interface` or a `type` of a `.ts` / `.d.ts`, a `@typedef` of a `.js` — and the rows bound under it are checked. A type it cannot read (no such file, no such name) leaves the paths under the key unchecked and says so once (`wcs/path-dynamic-unknown`, info) — unknown, not missing. Up to 4.25 each field bound under such a list was a false `wcs/binding-path-missing`.
171
+ - **A getter that falls back to `[]` does not make its rows "missing".** `get pickups() { return this.counter ? this.counter.pickups : []; }` (also `X ?? []`, `X || []`, an early `return []`) where `X`'s shape is not known: the rows are unknown, said once at the getter (`wcs/path-dynamic-unknown`). Up to 4.25 the `[]` made every row field a `wcs/binding-path-missing`. A list whose rows are known (`this.items ?? []`) is checked as before.
172
+ - **`wcs/watch-path-missing` consults the `stateSchema`**, as the bindings do: a key the schema has is not reported, only one it definitely lacks.
173
+ - **`wcs/drift-state-key`** (warning) — the `stateSchema` applied to the page and the page's root state script disagree on the top-level keys: `get displayName()` renamed in the `.ts` while the manifest still says `headerName`. A stale schema wins over the script — the binding left on the old name passed (0 errors, 0 warnings), and a key added since was `wcs/path-nonexistent`. Said once, at the `<wcs-state>` start tag, naming the keys on each side, with `wcs-schema emit` to regenerate it — run `wcs-schema check` before this lint in CI. Only where both sides are known: a root state script read in full (no top-level spread, no computed key, no `$stream` / `$scan`) and the schema's top-level properties; a volume's mount root is not counted.
174
+ - **A schema applies to the pages of its state** — see *Which pages a schema is for* above.
175
+
176
+ `--errors-only` prints the errors now found in TypeScript (`wcs/tag-member-unknown` on an element defined in a `.ts` module, `wcs/getter-untracked-read` on a typed getter, …); `--strict` also fails on the two new warnings and on the wider `wcs/filter-input-type`.
177
+
161
178
  ## Use in generate–validate–fix loops
162
179
 
163
180
  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.