@wcstack/lint 4.27.0 → 4.29.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.
Files changed (4) hide show
  1. package/README.ja.md +22 -0
  2. package/README.md +22 -0
  3. package/dist/cli.cjs +3409 -2581
  4. package/package.json +1 -1
package/README.ja.md CHANGED
@@ -125,6 +125,7 @@ nothing to check: index.html — no data-wcs binding, <wcs-*> tag or wcstack scr
125
125
 
126
126
  - **値を読めないキーの下は「分からない」で、「存在しない」ではありません。** `const init = emptyEntry()` の `team: init.team`、`errs: emptyErrs()`、条件式、`[1, 2].map(…)`、`[newRunner()]` の行: そうしたキーの下のパスは検査せず、キーの上の `wcs/path-dynamic-unknown`(info)が 1 回だけそう言います — その下に束ねたパスの数(キーの `for:` の行の `.name` も数えます)と、検査させる方法(キーの JSDoc の `@type` か `stateSchema`)付きで。4.22 までは、そのパスが 1 件ずつ `wcs/binding-path-missing` の誤報で、本物の打ち間違いと同じ code でした。オブジェクトリテラルを束縛する `const` のメンバー(`team: DEFAULTS.team`。モジュールの中のものも import したものも)は読み、その下のパスを検査します。
127
127
  - **`wcs/radio-name-shared`**(warning) — `for:` の行の中の、`name` をリテラルで書いた、行の値を束ねたラジオ(`<input type="radio" name="sex" data-wcs="radio: .sex">`)。どの行のラジオも同じ name になるので、ブラウザは全部の行を 1 つのグループにします: ページ全体で 1 つしか選ばれた状態にならず、表示は最初の描画から行ごとの値と食い違います。行ごとに違う name を束ねる(`attr.name: .<行のフィールド>`)か、name を外してください — `radio:` は name が無くても、同じパスに束ねたラジオを選択に合わせます。name を束ねてあるとき、行のものでないパス(`value: .id; radio: selectedId` — 行をまたぐ 1 つの選択)、行ごとに `<form>` があるときは報告しません。
128
+ - **`wcs/radio-before-value`**(warning) — `radio:` / `checkbox:` を、その要素に値を与える束縛より前に書いた(`<input type="radio" data-wcs="radio: theme; attr.value: .value">`)。束縛は書いた順に当たり、`radio:` は当たるときに要素の `value` を比べるので、まだブラウザの既定の `"on"` と比べる: 最初の描画ではどのラジオも選ばれず、実行時は何も言わない(後から state に書くと正しいものが選ばれるので、値がページを描いた後に届く所では隠れる)。値を先に書く: `attr.value: .value; radio: theme`。値の束縛が前にあるとき・値がマークアップのリテラルだけのとき(`value="red"`)は黙る。4.29 から。
128
129
  - **`wcs/number-written-as-string`**(warning) — 書き戻すときに変換しない双方向の `value:` が、state が数値で持つパスを指す: `count: 0` と `<input type="number" data-wcs="value: count">`(JSDoc の `@type {number}`・`stateSchema`・行のフィールド `value: .qty` も)。要素の `value` は文字列なので、5 と入力した後の state は `"5"` で、`count + 1` は `"51"` になります。`valueAsNumber: count` か、左辺の入力フィルタ `value|number: count`(`|int`・`|float`)と書いてください。
129
130
  - **`wcs/two-way-output-filter`**(warning) — 双方向の `value:` / `valueAsNumber:` の出力フィルタ(`value: code|upper`・`value: price|locale`)。打つ欄では、フィルタが 1 打鍵ごとに state の値を整形して欄へ書き直します: 入力中の欄が書き換わり(キャレットは末尾へ飛び、IME の変換は途切れます)、state が受け取るのも欄の整形済みの文字です — 出力フィルタは書き戻しで元に戻りません。整形した文字は別の要素に表示する、欄の確定で書き戻して setter で整形する(`value#onchange:`)、または一方向にしてください(`value#ro:`)。確定した値を書き戻す束縛(`#onchange`・`<select>`・スライダー)は、出力を元に戻す入力フィルタが無いときだけ報告します: `value#onchange|number: price|toFixed(2)` は報告しません。要素の書いた文字をそのまま返すフィルタ(`string`・`nullIfEmpty`・`coalesce(…)`・`defaults('')`)も報告しません。
130
131
  - **`attr.*` に束ねた boolean**(`wcs/binding-type-expectation`)には、起きることを言います: ランタイムは `String(value)` — `"true"` / `"false"` — を書き、属性を外すのは `null` / `undefined` だけです。その語が属性の値であるもの — ARIA の状態(`attr.aria-invalid: flag|truthy`)・`contenteditable`・`draggable`・`spellcheck` — は、もう報告しません(`"attr.aria-invalid" には文字列型が必要です` は誤報でした)。ネイティブ要素の論理属性(`attr.disabled: flag`)には、`disabled="false"` でも無効のままであることと、代わりに束ねるプロパティ(`disabled: flag`)を言います。ほかの属性(`attr.data-open: flag`)には、文字として書かれて外れないことと、false の間は外す `|defaults(null)`・文字が意図のときの `|string` を言います。
@@ -175,6 +176,27 @@ nothing to check: index.html — no data-wcs binding, <wcs-*> tag or wcstack scr
175
176
 
176
177
  `--errors-only` には TypeScript で新たに見つかる error(`.ts` のモジュールで定義した要素の `wcs/tag-member-unknown`・型付きの getter の `wcs/getter-untracked-read` …)が出ます。`--strict` は新しい 2 つの warning と、広がった `wcs/filter-input-type` でも失敗します。
177
178
 
179
+ ## 部品で組み立てたページに言うこと
180
+
181
+ 4.29 から。継ぎ目アプリ garden-plots — 市の共通部品で組み立てた画面: デザイナーの部品は HTML だけ(宣言的カスタムコンポーネント)、開発者の部品はページのデータにマウントするクラス。4.28 までの lint は部品を何も知らず、作者がわざとした 45 通りの間違いのうち捕まえたのは 2 つでした。
182
+
183
+ **宣言的カスタムコンポーネント(DCC)**(`<my-pager data-wc-definition><template shadowrootmode="open"> … <wcs-state> … </wcs-state></template></my-pager>`):
184
+
185
+ - **定義は、それ自身の範囲です。** テンプレートの中のマークアップは定義の `<wcs-state>` に対して、ページのマークアップはページの state に対して検査します。4.28 までは両方のキーが 1 つの集合で、部品だけが持つキーへのページの束縛も、ページだけが持つキーへの部品の束縛も通っていました。部品のファイル(`parts/my-pager.html`)も、コマンドラインで名指せば同じに検査します。
186
+ - **`wcs/dcc-declaration`**(error) — 実行時がタグを定義するときに拒む定義。条件は実行時と同じです: リストでない `$bindables` / `$commands`、空・`$` で始まる・2 回書いた・state のメンバーでない項目、`$bindables` のメソッド、`$commands` の値、定義の中の `<wcs-state bind-component>`、定義自身の 2 つ目の `<wcs-state>`。拒まれた定義は何も定義しないので、どのページのどのインスタンスも未知の要素のままです。確かなときだけ言います: リテラルでないリスト、`export default { … }` のリテラルでない state、lint が読めない state のファイルには触れません。
187
+ - **`wcs/tag-member-unknown`**(error)が DCC も見ます: `<my-pager data-wcs="totl: n">` や `command.nxt:` を、部品の `$bindables` と `$commands` に突き合わせ、近い名前を添えます。定義は、ページが言う場所から読みます — ページの中、または import map が autoloader の `dcc` ローダーに名指すファイル: `.html` で終わるか `|dcc` と書いた eager のキー、`|dcc/` と書いた名前空間。lint が読めないファイルからは契約が出ず、そのタグの束縛は検査しません: `/` から始まるパスは `--root=<dir>` を渡したときだけ読みます。
188
+ - **`wcs/dcc-attribute`**(warning) — 部品の `$bindables` のメンバーを属性で書いたインスタンス(`<my-pager total="120">`)。DCC の入力はプロパティで、属性は読まれません: 部品は既定のままです。実行時も 4.28 から同じ code で警告します。タグと名前ごとに 1 回。
189
+
190
+
191
+ **クラスの部品**(テンプレートに `<wcs-state bind-component="state">`、インスタンスに `state = { … }` を持つ `class XCard extends HTMLElement`。`<x-card data-wcs="state: user">` でマウントする):
192
+
193
+ - **クラスは、ページが言う場所から読みます** — import map が autoloader に名指すファイル(`"@components/x-card": "./parts/x-card.js"`、または名前空間: `"@components/x/": "./parts/"` と `<x-card>` → `./parts/card.js`)、またはページが読み込むモジュールのうち `customElements.define("x-card", XCard)` を呼ぶもの。部品のテンプレートの中でマウントしている部品も、そこから辿って読みます。`.ts` のファイルは型を消して読みます。
194
+ - **部品が公開する getter は、ページのパスです。** 部品の state の getter は、部品をマウントした所のパスで読めます — `user.display`、行にマウントしたなら行の中の `.display`。部品の中の部品も同じです。4.28 までは、それを読むページに「パスが存在しない」(`wcs/binding-path-missing`)と言い、回避策 — ページのデータの JSDoc の型に getter を手で宣言する — は、後の改名を隠していました。部品から無くなった getter は、ほかの無いパスと同じに報告します。
195
+ - **部品のメソッドは、ページと同じに検査します**: `this.tenant.name = v`(`wcs/nested-assign`)と `this.plots.push(p)`(`wcs/array-mutation`)は、部品でもエラーです。所見は部品のファイルの、その行に出ます。
196
+ - **部品のテンプレートのパスで、先頭のキーをどこも与えないもの**は `wcs/binding-path-missing`(warning)で、部品のファイルに出ます: そのキーが部品自身の state のものでなく、ページが渡してもおらず(`state.view:`)、マウント先のオブジェクトにも無いとき — テンプレートの `nmae`、ページが `state.veiw:` と書いた所の `view.x`、部品の中で読んだページのパス(`pageTitle`: 渡してください)。部品の中では、そういう読みはマウント先へ落ちて何も失敗しません。実行時は 4.28 から報告していて、これは同じ基準です。マウント先のオブジェクトは、形が分かるとき(種・JSDoc の型・スキーマ)だけ判定します: 空で始まるリストの行には何も言いません。先頭のキーより深い所は言いません。
197
+ - 確かなときだけ読みます: オブジェクトリテラルの `state = { … }`(フィールドか、コンストラクタの `this.state = { … }`)で、スプレッドも計算されたキーも無いもの。テンプレートは、モジュールの中の 1 つの文字列。lint が読めないファイル(`--root` なしの `/` から始まるパス)、呼び出しで作る state、見つからないクラスには、これまでどおり何も言いません。
198
+
199
+
178
200
  ## 生成 → 検証 → 修正ループでの利用
179
201
 
180
202
  安定した 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
@@ -125,6 +125,7 @@ Since 4.23, from the ekiden-entry seam app — an entry wizard for a relay race,
125
125
 
126
126
  - **A key whose value the lint cannot read is unknown, not missing.** `team: init.team` beside `const init = emptyEntry()`, `errs: emptyErrs()`, a conditional, `[1, 2].map(…)`, the rows of `[newRunner()]`: the paths under such a key are not checked, and one `wcs/path-dynamic-unknown` info at the key says so — with the number of paths bound under it (a row's `.name` under the key's `for:` is one) and what has them checked: a JSDoc `@type` on the key, or a `stateSchema`. Up to 4.22 each of those paths was a false `wcs/binding-path-missing`, the same code as a real typo. A member of a `const` bound to an object literal (`team: DEFAULTS.team`, in the module or imported) is read, and the paths under it are checked.
127
127
  - **`wcs/radio-name-shared`** (warning) — radios in a `for:` row with a literal `name` and a binding of the row's (`<input type="radio" name="sex" data-wcs="radio: .sex">`). Every row's radios get the same name, so the browser makes one group of all the rows: only one radio on the whole page stays checked, and the page disagrees with the rows' values from the first render. Bind a name that differs per row (`attr.name: .<a row field>`), or drop the name — `radio:` keeps the radios bound to one path in step without it. Not reported when the name is bound, when the bound path is not the row's (`value: .id; radio: selectedId` — one choice over the rows), or when each row holds its own `<form>`.
128
+ - **`wcs/radio-before-value`** (warning) — `radio:` / `checkbox:` written before the binding that gives the control its value (`<input type="radio" data-wcs="radio: theme; attr.value: .value">`). Bindings are applied in the order written, and `radio:` compares the element's `value` when it is applied — still the browser's `"on"`: no radio is checked at the first render, and nothing at run time says so (a later write of the state checks the right one, which hides it where the value arrives after the page is drawn). Write the value first: `attr.value: .value; radio: theme`. Silent when the value binding comes first and when the value is only in the markup (`value="red"`). Since 4.29.
128
129
  - **`wcs/number-written-as-string`** (warning) — a two-way `value:` with no conversion on the way in, bound to a path the state holds as a number: `<input type="number" data-wcs="value: count">` with `count: 0` (a JSDoc `@type {number}`, a `stateSchema` and a row field `value: .qty` count too). An element's `value` is a string, so after the user enters 5 the state has `"5"` and `count + 1` is `"51"`. Write `valueAsNumber: count`, or an input filter on the left side: `value|number: count` (`|int`, `|float`).
129
130
  - **`wcs/two-way-output-filter`** (warning) — an output filter on a two-way `value:` / `valueAsNumber:` (`value: code|upper`, `value: price|locale`). In a field the user types in, the filter formats what the state holds on every keystroke: the field is rewritten while the user types — the caret jumps to the end, an IME composition is cut — and the state receives the field's formatted text, since an output filter is not undone on the way back. Show the formatted text in another element, write back when the field is committed and format in a setter (`value#onchange:`), or make the binding one-way (`value#ro:`). A binding that writes back a committed value (`#onchange`, a `<select>`, a slider) is reported only when no input filter undoes the output: `value#onchange|number: price|toFixed(2)` is not. Nor are the filters that give back what the element wrote: `string`, `nullIfEmpty`, `coalesce(…)`, `defaults('')`.
130
131
  - **A boolean given to `attr.*`** (`wcs/binding-type-expectation`) is told what happens to it: the runtime writes `String(value)` — `"true"` / `"false"` — and only `null` / `undefined` remove an attribute. Where those words are the attribute's values — the ARIA states (`attr.aria-invalid: flag|truthy`), `contenteditable`, `draggable`, `spellcheck` — nothing is reported any more (it was a false warning: `"attr.aria-invalid" requires a string`). A boolean attribute of a native element (`attr.disabled: flag`) is told that `disabled="false"` still disables, with the property to bind instead (`disabled: flag`). Any other attribute (`attr.data-open: flag`) is told that it is written as the text and never removed, with `|defaults(null)` to remove it while false and `|string` where the text is meant.
@@ -175,6 +176,27 @@ Since 4.26, from the lending-desk seam app — an equipment-lending desk written
175
176
 
176
177
  `--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
178
 
179
+ ## What a page assembled from parts is told
180
+
181
+ Since 4.29, from the garden-plots seam app — a console assembled from a city's shared parts: designers' parts in HTML alone (Declarative Custom Components), developers' parts as classes mounted on the page's data. Up to 4.28 the lint knew nothing of a part: of the 45 mistakes its author made on purpose it caught 2.
182
+
183
+ **A Declarative Custom Component** (`<my-pager data-wc-definition><template shadowrootmode="open"> … <wcs-state> … </wcs-state></template></my-pager>`):
184
+
185
+ - **A definition is a scope of its own.** The markup in its template is checked against the definition's own `<wcs-state>`, and the page's markup against the page's. Up to 4.28 the two were one set of keys: a page's binding passed on a key only a part had, and a part's on a key only the page had. A part's file (`parts/my-pager.html`) is checked the same way when it is named on the command line.
186
+ - **`wcs/dcc-declaration`** (error) — a definition the runtime refuses when it defines the tag, by the same conditions: `$bindables` / `$commands` that is not a list; an entry that is empty, starts with `$`, is written twice or is not a member of the state; a method in `$bindables`; a value in `$commands`; a `<wcs-state bind-component>` in a definition; a second `<wcs-state>` of the definition's own. The refused definition defines nothing, so every instance on every page stays an unknown element. Only what is certain is said: a list that is not a literal, a state that is not an `export default { … }` literal and a state file the lint cannot read are left alone.
187
+ - **`wcs/tag-member-unknown`** (error) now covers a DCC: `<my-pager data-wcs="totl: n">` and `command.nxt:` are checked against the part's `$bindables` and `$commands`, with the near name. The definition is read where the page says it is — in the page, or in the file the import map names for the autoloader's `dcc` loader: an eager key whose file ends in `.html` or that says `|dcc`, a namespace that says `|dcc/`. A file the lint cannot read gives no contract, and the tag's bindings are not checked: a path from `/` is read only with `--root=<dir>`.
188
+ - **`wcs/dcc-attribute`** (warning) — an instance that carries one of the part's `$bindables` as an attribute (`<my-pager total="120">`). A DCC's inputs are properties: the attribute is not read, and the part shows its default. The runtime warns with the same code since 4.28. Once per tag and name.
189
+
190
+
191
+ **A class part** (`class XCard extends HTMLElement` with `<wcs-state bind-component="state">` in its template and `state = { … }` on the instance, mounted with `<x-card data-wcs="state: user">`):
192
+
193
+ - **The class is read where the page says it is** — the file the import map names for the autoloader (`"@components/x-card": "./parts/x-card.js"`, or a namespace: `"@components/x/": "./parts/"` and `<x-card>` → `./parts/card.js`), or a module the page loads that calls `customElements.define("x-card", XCard)`. A part's own template is read for the parts it mounts in turn. `.ts` files are read with their types erased.
194
+ - **The getters a part exports are paths of the page.** A getter of the part's state is readable at the path the part is mounted on — `user.display`, and `.display` in the rows a part is mounted on, a part inside a part included. Up to 4.28 a page that read one was told the path does not exist (`wcs/binding-path-missing`), and the way round it — declaring the getter by hand in the JSDoc type of the page's data — hid a later rename. A getter the part no longer has is reported as any missing path.
195
+ - **A part's methods are checked like a page's**: `this.tenant.name = v` (`wcs/nested-assign`) and `this.plots.push(p)` (`wcs/array-mutation`) are errors in a part too. The finding is in the part's file, at its line.
196
+ - **A path of a part's template whose first key nothing gives** is `wcs/binding-path-missing` (warning), in the part's file: the key is not one of the part's own state, the page does not hand it over (`state.view:`), and the object the part is mounted on does not have it — `nmae` in the template, `view.x` where the page wrote `state.veiw:`, a path of the page read inside the part (`pageTitle`: hand it over). Inside a part such a read falls through and fails nothing; the runtime reports it since 4.28, and this is the same test. The mounted object is judged only where its shape is known (a seed, a JSDoc type, a schema): rows of a list that starts empty say nothing. Deeper than the first key nothing is said.
197
+ - Only what is certain is read: `state = { … }` as an object literal (a field, or `this.state = { … }` in the constructor) with no spread and no computed key, and a template that is one string of the module. A file the lint cannot read (a path from `/` without `--root`), a state built by a call, a class it cannot find: nothing is said about the tag, as before.
198
+
199
+
178
200
  ## Use in generate–validate–fix loops
179
201
 
180
202
  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.