@wcstack/lint 4.9.0 → 4.10.1
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 +4 -3
- package/README.md +4 -3
- package/dist/cli.cjs +7824 -7166
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -23,10 +23,10 @@ npx wcs-validate --errors-only src/**/*.html
|
|
|
23
23
|
|
|
24
24
|
`.manifest.json` で終わるファイルは sidecar manifest として、それ以外は `data-wcs` バインディングを含む HTML として検査されます。ただし framework のコンポーネントと script のファイル(`.js`・`.ts`・`.jsx`・`.tsx`・`.vue`・`.svelte`)は読みません(4.6 から。以前は HTML として読み、問題なしと報告していました)。
|
|
25
25
|
|
|
26
|
-
`<wcs-state src="...">` で参照される外部 state(`.json` / `.js` / `.ts`)は HTML ファイルからの相対パスで解決され、パス検証の対象になります。URL
|
|
26
|
+
`<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.9 までは短縮プロパティのキーをまったく読まなかったので、`i18n.t.*` の束縛はすべて `wcs/binding-path-missing` の誤報でした。値を計算する名前(実行時にロケールの辞書を合わせた辞書)や辿れない名前(素の指定子・URL・無いファイル)のキーは、その下のパスを検査せず、ページがその下を束ねていればキーの上で 1 回だけそう言います(`wcs/path-dynamic-unknown`、info)。キーか宣言に JSDoc の `@type {typeof import("./en.js").default}` を付けると、そのファイルのリテラルで検査します。
|
|
27
27
|
|
|
28
28
|
```
|
|
29
|
-
wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--errors-only] [--strict] <file> [<file> ...]
|
|
29
|
+
wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--root=<dir>] [--errors-only] [--strict] <file> [<file> ...]
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
| オプション | 説明 |
|
|
@@ -34,6 +34,7 @@ wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--errors-
|
|
|
34
34
|
| `--attr=<name>` | バインド属性名(既定 `data-wcs`) |
|
|
35
35
|
| `--state-tag=<name>` | state カスタム要素のタグ名(既定 `wcs-state`) |
|
|
36
36
|
| `--lang=ja\|en` | 診断メッセージの言語。未指定時は環境ロケール(`LC_ALL` / `LC_MESSAGES` / `LANG` → OS ロケール)に従う。code / range は言語に依らず不変 |
|
|
37
|
+
| `--root=<dir>`(`--root <dir>` も) | 4.10 から: サイトのルートのディレクトリ。/ から始まるパスをその下で読む — `<base href="/ja/">` の下の `<wcs-state src="/app.js">`(`docs/csp.md` と `examples/router-i18n` の形)や、state のファイルの `/…` からの import は `<dir>/app.js` として読む。ディレクトリの外へ出るもの(`/../x.js`)は読まない。無ければ / から始まるパスは読まない(`wcs/state-src-unread`、info)。そうしたファイルの指摘はディレクトリの下のパスで出す(`public/app.js:12:5 …`) |
|
|
37
38
|
| `--errors-only`(別名 `--quiet`) | error severity の行だけ表示。warning / info の件数と exit code は不変 |
|
|
38
39
|
| `--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 を反映する |
|
|
39
40
|
|
|
@@ -89,7 +90,7 @@ nothing to check: index.html — no data-wcs binding, <wcs-*> tag or wcstack scr
|
|
|
89
90
|
|
|
90
91
|
- **発見**: HTML ファイルから上へ辿って最も近い `wcstack.manifest.json` が自動で使われます — コマンドラインに渡す必要はありません。`application` artifact を含む `*.manifest.json` を引数に渡した場合は、その実行全体で発見を置き換えます。VS Code 拡張も同じファイルを発見するので IDE と CLI の結果は一致します。
|
|
91
92
|
- **効果**: `stateSchema` を宣言すると、schema 上に確定的に存在しないバインドパスは `wcs/path-nonexistent`(**error**・exit `1`)、`for:` に非配列は `wcs/path-type-mismatch`(**error**)になります。schema が開いたままの箇所(素の `{}`)は沈黙し、インラインスクリプトのメソッド / getter / `$listKeys` は引き続き存在扱いです。`stateSchema` が無ければ従来どおりです。
|
|
92
|
-
- **契約が要るとき**: 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`
|
|
93
|
+
- **契約が要るとき**: 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>` を渡してください。
|
|
93
94
|
- **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` で同期を保ってください。
|
|
94
95
|
|
|
95
96
|
## 生成 → 検証 → 修正ループでの利用
|
package/README.md
CHANGED
|
@@ -23,10 +23,10 @@ npx wcs-validate --errors-only src/**/*.html
|
|
|
23
23
|
|
|
24
24
|
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
25
|
|
|
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
|
|
26
|
+
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). 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
27
|
|
|
28
28
|
```
|
|
29
|
-
wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--errors-only] [--strict] <file> [<file> ...]
|
|
29
|
+
wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--root=<dir>] [--errors-only] [--strict] <file> [<file> ...]
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
| Option | Description |
|
|
@@ -34,6 +34,7 @@ wcs-validate [--attr=data-wcs] [--state-tag=wcs-state] [--lang=ja|en] [--errors-
|
|
|
34
34
|
| `--attr=<name>` | Bind attribute name (default `data-wcs`) |
|
|
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
|
+
| `--root=<dir>` (also `--root <dir>`) | Since 4.10: the site's root directory, where a path from `/` is read — a `<wcs-state src="/app.js">` under `<base href="/ja/">` (the form of `docs/csp.md` and `examples/router-i18n`) and an import from `/…` in a state file are read as `<dir>/app.js`; a path that leaves the directory (`/../x.js`) is not. Without it a path from `/` is not read (`wcs/state-src-unread`, info). A finding in such a file is reported under the directory (`public/app.js:12:5 …`) |
|
|
37
38
|
| `--errors-only` (alias `--quiet`) | Print only error-severity lines; warning/info counts and the exit code are unchanged |
|
|
38
39
|
| `--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 |
|
|
39
40
|
|
|
@@ -89,7 +90,7 @@ Without a contract, a path the validator cannot resolve is only a **warning** (`
|
|
|
89
90
|
|
|
90
91
|
- **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.
|
|
91
92
|
- **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.
|
|
92
|
-
- **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.
|
|
93
|
+
- **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 `/`.
|
|
93
94
|
- **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.
|
|
94
95
|
|
|
95
96
|
## Use in generate–validate–fix loops
|