@wcstack/lint 4.6.2 → 4.7.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
@@ -89,7 +89,7 @@ nothing to check: index.html — no data-wcs binding, <wcs-*> tag or wcstack scr
89
89
 
90
90
  - **発見**: HTML ファイルから上へ辿って最も近い `wcstack.manifest.json` が自動で使われます — コマンドラインに渡す必要はありません。`application` artifact を含む `*.manifest.json` を引数に渡した場合は、その実行全体で発見を置き換えます。VS Code 拡張も同じファイルを発見するので IDE と CLI の結果は一致します。
91
91
  - **効果**: `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`)も —— それで検査します。
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
93
  - **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
94
 
95
95
  ## 生成 → 検証 → 修正ループでの利用
package/README.md CHANGED
@@ -89,7 +89,7 @@ Without a contract, a path the validator cannot resolve is only a **warning** (`
89
89
 
90
90
  - **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
91
  - **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.
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
93
  - **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
94
 
95
95
  ## Use in generate–validate–fix loops
package/dist/cli.cjs CHANGED
@@ -89,6 +89,9 @@ var WcsDiagnosticCode = {
89
89
  // lint の限界の告知(作者の誤りではない): `export default { … }` のトップレベルの spread が持ち込むキーは読めないので、
90
90
  // stateSchema の無い state のパスは検査しない — それを spread の上で 1 回だけ言う。info。
91
91
  PathDynamicUnknown: "wcs/path-dynamic-unknown",
92
+ // lint の限界の告知(作者の誤りではない): 読めない `<wcs-state src>`(/ から始まるパス・URL・無いファイル)の state は
93
+ // パスもスクリプトの規則も検査しない — それを src の上で 1 回だけ言う。info(docs/seam-apps.md、prod-booking)。
94
+ StateSrcUnread: "wcs/state-src-unread",
92
95
  // --- existing binding-expression validators (retrofitted) ---
93
96
  FilterUnknown: "wcs/filter-unknown",
94
97
  FilterArity: "wcs/filter-arity",
@@ -2179,11 +2182,11 @@ var registered = {
2179
2182
  percent: { factory: percent, arity: [0, 1] },
2180
2183
  unit: { factory: nullishPassthrough(unit), arity: [1, 1] },
2181
2184
  // The locale-dependent three take a locale like `locale` does (`date(ja-JP)`), and a style (`date(ja-JP,long)`)
2182
- date: { factory: date, arity: [0, 2] },
2183
- time: { factory: time, arity: [0, 2] },
2184
- datetime: { factory: datetime, arity: [0, 2] },
2185
- ymd: { factory: ymd, arity: [0, 1] },
2186
- hms: { factory: hms, arity: [0, 1] },
2185
+ date: { factory: nullishPassthrough(date), arity: [0, 2] },
2186
+ time: { factory: nullishPassthrough(time), arity: [0, 2] },
2187
+ datetime: { factory: nullishPassthrough(datetime), arity: [0, 2] },
2188
+ ymd: { factory: nullishPassthrough(ymd), arity: [0, 1] },
2189
+ hms: { factory: nullishPassthrough(hms), arity: [0, 1] },
2187
2190
  // the core set of 4.0.0-rc.3 (the core's own: eq ne not lt le gt ge falsy truthy boolean)
2188
2191
  eq: eq2,
2189
2192
  ne: ne2,
@@ -3408,11 +3411,21 @@ function expressionShape(text3, paths, aliases) {
3408
3411
  if (scan.startsWith("[")) {
3409
3412
  const inner = extractDelimitedContent(expr, scan, 0, "[", "]");
3410
3413
  rest = inner.length + 2;
3411
- const spread = /^\s*\.\.\.([\s\S]+)$/.exec(inner);
3412
- if (spread === null || splitTopLevelElements(inner).length !== 1) return null;
3413
- const source = expressionShape(spread[1], paths, aliases);
3414
- if (source === null || !source.isList) return null;
3415
- shape = source;
3414
+ if (inner.trim() === "") {
3415
+ shape = EMPTY_LIST;
3416
+ } else {
3417
+ const spread = /^\s*\.\.\.([\s\S]+)$/.exec(inner);
3418
+ if (spread === null || splitTopLevelElements(inner).length !== 1) return null;
3419
+ const source = expressionShape(spread[1], paths, aliases);
3420
+ if (source === null || !source.isList) return null;
3421
+ shape = source;
3422
+ }
3423
+ } else if (scan.startsWith("(")) {
3424
+ const inner = extractDelimitedContent(expr, scan, 0, "(", ")");
3425
+ const base = expressionShape(inner, paths, aliases);
3426
+ if (base === null) return null;
3427
+ shape = base;
3428
+ rest = inner.length + 2;
3416
3429
  } else {
3417
3430
  const base = readBase(expr, scan, aliases, paths);
3418
3431
  if (base === null) return null;
@@ -3486,8 +3499,7 @@ function applyChain(expr, scan, start, initial) {
3486
3499
  if (!shape.isList) return null;
3487
3500
  shape = pickRow(shape);
3488
3501
  } else if (method === "map") {
3489
- if (!shape.isList) return null;
3490
- const mapped = mapRows(args, shape);
3502
+ const mapped = mapRows(args, shape.isList ? shape : OPAQUE);
3491
3503
  if (mapped === null) return null;
3492
3504
  shape = mapped;
3493
3505
  } else {
@@ -3497,6 +3509,7 @@ function applyChain(expr, scan, start, initial) {
3497
3509
  return shape.opaque ? null : shape;
3498
3510
  }
3499
3511
  var OPAQUE = { isList: true, mirrors: [], fields: [], opaque: true };
3512
+ var EMPTY_LIST = { isList: true, mirrors: [], fields: [] };
3500
3513
  function pickRow(shape) {
3501
3514
  return {
3502
3515
  isList: false,
@@ -10944,6 +10957,7 @@ var ja = {
10944
10957
  commandTokenUnbound: (t) => `\u30B3\u30DE\u30F3\u30C9\u30C8\u30FC\u30AF\u30F3 "${t}" \u3092 emit \u3057\u3066\u3044\u307E\u3059\u304C\u3001\u3053\u306E\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306B\u305D\u308C\u3092\u53D7\u3051\u308B command.<\u30E1\u30BD\u30C3\u30C9>: ${t} \u306E\u675F\u7E1B\u304C\u3042\u308A\u307E\u305B\u3093\u3002emit \u306F\u8AB0\u306B\u3082\u5C4A\u304D\u307E\u305B\u3093\u3002\u30E1\u30BD\u30C3\u30C9\u3092\u547C\u3076\u8981\u7D20\u306B\u675F\u306D\u3066\u304F\u3060\u3055\u3044\uFF08command.focus: ${t}\uFF09`,
10945
10958
  writePathMissing: (k) => `"${k}" \u306F state \u304C\u5BA3\u8A00\u3057\u3066\u3044\u306A\u3044\u30AD\u30FC\u3067\u3059\u3002\u66F8\u304D\u8FBC\u307F\u306F\u65B0\u3057\u3044\u30AD\u30FC\u3092\u4F5C\u308B\u3060\u3051\u3067\u3001\u5BA3\u8A00\u3057\u305F\u30AD\u30FC\u306E\u675F\u7E1B\u306B\u306F\u5C4A\u304D\u307E\u305B\u3093`,
10946
10959
  readPathMissing: (p, top) => top ? `"${p}" \u306F state \u304C\u5BA3\u8A00\u3057\u3066\u3044\u306A\u3044\u30AD\u30FC\u3067\u3059\u3002\u8AAD\u3093\u3060\u6642\u70B9\u3067\u4F8B\u5916\u306B\u306A\u308A\u307E\u3059\uFF08#301\uFF09` : `\u30D1\u30B9 "${p}" \u306F\u72B6\u614B\u5B9A\u7FA9\u306B\u5B58\u5728\u3057\u307E\u305B\u3093\u3002\u8AAD\u307F\u306F undefined \u306B\u306A\u308A\u3001\u305D\u3053\u304B\u3089\u8A08\u7B97\u3057\u305F\u5024\u306F\u9ED9\u3063\u3066\u9055\u3044\u307E\u3059`,
10960
+ stateSrcUnread: (src) => `"${src}" \u3092\u8AAD\u3081\u306A\u3044\u306E\u3067\u3001\u3053\u306E state \u306E\u30D1\u30B9\u3082\u30B9\u30AF\u30EA\u30D7\u30C8\u306E\u898F\u5247\u3082\u691C\u67FB\u3057\u3066\u3044\u307E\u305B\u3093\u3002src \u306F\u3053\u306E\u30D5\u30A1\u30A4\u30EB\u304B\u3089\u306E\u76F8\u5BFE\u30D1\u30B9\u3067\u8AAD\u307F\u307E\u3059\uFF08/ \u304B\u3089\u59CB\u307E\u308B\u30D1\u30B9\u3068 URL \u306F\u8AAD\u307F\u307E\u305B\u3093\uFF09\u3002\u30B5\u30FC\u30D0\u30FC\u3068\u540C\u3058\u4E26\u3073\u306B\u7F6E\u3044\u305F\u30D5\u30A1\u30A4\u30EB\u3092\u3001\u3053\u306E\u30D5\u30A1\u30A4\u30EB\u304B\u3089\u306E\u76F8\u5BFE\u30D1\u30B9\u3067\u6307\u3057\u3066\u304F\u3060\u3055\u3044`,
10947
10961
  pathDynamicUnknownSpread: (sp) => `${sp} \u304C\u6301\u3061\u8FBC\u3080\u30AD\u30FC\u306F\u9759\u7684\u306B\u8AAD\u3081\u306A\u3044\u306E\u3067\u3001\u3053\u306E state \u306E\u30D1\u30B9\u306F\u691C\u67FB\u3057\u3066\u3044\u307E\u305B\u3093\uFF08\u675F\u7E1B\u30FBgetter \u306E\u4E2D\u306E\u8AAD\u307F\u30FB$watch \u306E\u30AD\u30FC\uFF09\u3002\u30AD\u30FC\u3092 wcstack.manifest.json \u306E stateSchema \u306B\u5BA3\u8A00\u3059\u308B\u3068\u691C\u67FB\u3055\u308C\u307E\u3059\u3002npx wcs-schema\uFF08@wcstack/typescript\uFF09\u304C state \u306E\u578B\uFF08JSDoc\u30FBTypeScript\uFF09\u304B\u3089\u4F5C\u308C\u307E\u3059`,
10948
10962
  pathReadonlyTwoWay: (p, prop) => `"${p}" \u306F setter \u306E\u7121\u3044 getter \u3067\u3059\u304C\u3001${prop}: \u306F\u8AAD\u8005\u306E\u5165\u529B\u3092\u66F8\u304D\u623B\u3059\u306E\u3067\u3001\u5165\u529B\u306E\u305F\u3073\u306B\u66F8\u304D\u8FBC\u307F\u304C\u5931\u6557\u3057\u307E\u3059\uFF08"${p}" is a getter without a setter\uFF09\u3002setter \u3092\u8DB3\u3059\uFF08set "${p}"(v) { \u2026 }\uFF09\u304B\u3001#ro \u3067\u4E00\u65B9\u5411\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08${prop}#ro: ${p}\uFF09`,
10949
10963
  submitWithoutPrevent: (h) => `onsubmit \u306B #prevent \u304C\u7121\u304F\u3001"${h}" \u3082 preventDefault \u3092\u547C\u3073\u307E\u305B\u3093\u3002\u30D6\u30E9\u30A6\u30B6\u306F\u30D5\u30A9\u30FC\u30E0\u3082\u9001\u308B\u306E\u3067\u3001\u30DA\u30FC\u30B8\u304C\u8AAD\u307F\u76F4\u3055\u308C\u308B\u304B\u3001router \u304C\u3042\u308C\u3070 GET \u304C\u6B04\u306E\u5024\uFF08\u30D1\u30B9\u30EF\u30FC\u30C9\u3082\uFF09\u3092 URL \u3068\u5C65\u6B74\u306B\u8F09\u305B\u307E\u3059\u3002onsubmit#prevent: ${h} \u3068\u66F8\u304F\u304B\u3001\u30CF\u30F3\u30C9\u30E9\u3067 event.preventDefault() \u3092\u547C\u3093\u3067\u304F\u3060\u3055\u3044`,
@@ -11153,6 +11167,7 @@ var en = {
11153
11167
  commandTokenUnbound: (t) => `The command token "${t}" is emitted, but no command.<method>: ${t} binding in this document receives it, so the emit reaches nothing. Bind it on the element whose method it should call (command.focus: ${t})`,
11154
11168
  writePathMissing: (k) => `"${k}" is not a key the state declares. The write creates a new key and reaches no binding of a declared one`,
11155
11169
  readPathMissing: (p, top) => top ? `"${p}" is not a key the state declares. Reading it throws (#301)` : `Path "${p}" does not exist in the state definition. The read gives undefined, and what is computed from it is wrong without a word`,
11170
+ stateSrcUnread: (src) => `"${src}" cannot be read, so this state's paths and script rules are not checked. A src is read relative to this file (a path from / or a URL is not read): point it at the file laid out as on the server, relative to this file`,
11156
11171
  pathDynamicUnknownSpread: (sp) => `The keys ${sp} brings in cannot be read statically, so this state's paths are not checked (bindings, reads in getters, $watch keys). Declare the keys in the stateSchema of wcstack.manifest.json to have them checked; npx wcs-schema (@wcstack/typescript) derives it from the state's types (JSDoc or TypeScript)`,
11157
11172
  pathReadonlyTwoWay: (p, prop) => `"${p}" is a getter without a setter, and ${prop}: writes back what the reader enters, so every edit fails ("${p}" is a getter without a setter). Add a setter (set "${p}"(v) { \u2026 }), or bind it one way with #ro (${prop}#ro: ${p})`,
11158
11173
  submitWithoutPrevent: (h) => `onsubmit has no #prevent and "${h}" does not call preventDefault, so the browser submits the form too: the page reloads, or with the router a GET puts the fields (a password too) in the URL and the history. Write onsubmit#prevent: ${h}, or call event.preventDefault() in the handler`,
@@ -16981,6 +16996,27 @@ function nearName(path, tree) {
16981
16996
  return null;
16982
16997
  }
16983
16998
 
16999
+ // src/service/stateSourceValidator.ts
17000
+ function validateStateSources(html, stateTagName = "wcs-state", locale2, fileReader) {
17001
+ if (fileReader === void 0) return [];
17002
+ const out = [];
17003
+ for (const element2 of parseWcsStateElements(html, stateTagName)) {
17004
+ const src = element2.srcAttr;
17005
+ const span = element2.srcSpan;
17006
+ if (src === void 0 || span === void 0 || element2.stateAttr !== void 0 || element2.bindComponent) continue;
17007
+ const readable = src.endsWith(".json") ? Boolean(fileReader(src)) : readStateScriptFile(src, fileReader) !== void 0;
17008
+ if (readable) continue;
17009
+ out.push({
17010
+ code: WcsDiagnosticCode.StateSrcUnread,
17011
+ start: span.start,
17012
+ end: span.end,
17013
+ message: getMessages(locale2).stateSrcUnread(src),
17014
+ severity: "info"
17015
+ });
17016
+ }
17017
+ return out;
17018
+ }
17019
+
16984
17020
  // src/core/sidecar/jsonSource.ts
16985
17021
  var JsonReader = class {
16986
17022
  constructor(text3) {
@@ -17426,9 +17462,9 @@ function validateDocument(text3, options = {}) {
17426
17462
  const stateTagName = options.stateTagName ?? "wcs-state";
17427
17463
  const fileReader = options.fileReader;
17428
17464
  const applicationSchema = options.applicationSchema ?? (fileReader !== void 0 ? discoverApplicationManifest(fileReader)?.schema : void 0);
17429
- const found = validateText(text3, options, applicationSchema);
17465
+ const found = [...validateText(text3, options, applicationSchema), ...validateStateSources(text3, stateTagName, options.locale, fileReader)];
17430
17466
  const page = fileReader === void 0 ? null : inlineExternalStates(text3, stateTagName, fileReader);
17431
- if (page === null) return found;
17467
+ if (page === null) return sortDiagnostics(found);
17432
17468
  const key = (d) => [d.code, d.start, d.end, d.message, d.origin?.path, d.origin?.start].join("\0");
17433
17469
  const seen2 = new Set(found.map(key));
17434
17470
  const out = [...found];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wcstack/lint",
3
- "version": "4.6.2",
3
+ "version": "4.7.0",
4
4
  "description": "Static-contract validator CLI (wcs-validate) for wcstack data-wcs bindings and wcstack.manifest.json sidecars. Thin npm wrapper around the wcstack-intellisense validator core.",
5
5
  "type": "module",
6
6
  "bin": {