@wcstack/lint 4.21.0 → 4.22.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/dist/cli.cjs +164 -15
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -270,6 +270,14 @@ var WcsDiagnosticCode = {
|
|
|
270
270
|
// 元の値を返し、双方向の入力はそこへ戻る — 何も知らせない(4.17 から diagnostics の後付けが警告する)。setter・getter
|
|
271
271
|
// の読み書きを追えない(`this[key]`・`fn(this)`・知らないメソッド)なら黙る。warning。
|
|
272
272
|
SetterUnobserved: "wcs/setter-unobserved",
|
|
273
|
+
// 1 つのアクセサを複数のパスに宣言するキー(`get "users.*.full,employees.*.full"()`、4.22)の書き方の誤り:
|
|
274
|
+
// カンマの前後の空白・空の項目・再帰のキー(`**`)。ランタイムはカンマで分けた間をそのままパスにするので、
|
|
275
|
+
// 空白入りのパスは誰も読まないパスになる(diagnostics の後付けは同じコードで初期化を失敗させる)。error。
|
|
276
|
+
AccessorListSyntax: "wcs/accessor-list-syntax",
|
|
277
|
+
// 複数のリストに宣言したアクセサの本体が、そのうち 1 つのリストの行を絶対パス(`this["users.*.first"]`)で
|
|
278
|
+
// 読み書きしている。ほかのリストの行ではそのパスに行が無く、読みは undefined、書きは例外になる。本体は
|
|
279
|
+
// 行からの相対パス(`this[".first"]`)で書く(diagnostics の後付けは同じコードで警告する)。error。
|
|
280
|
+
AccessorListPath: "wcs/accessor-list-path",
|
|
273
281
|
// `$renderedCallback`(3.x の旧名 `$updatedCallback`)が、どのバインディングにも現れないパスを判定に使っている。
|
|
274
282
|
// 同コールバックは **binding 駆動**(live binding が適用された path しか報告しない)
|
|
275
283
|
// なので、その分岐は一度も実行されない。表示要素が購読の実体になる事故
|
|
@@ -1236,7 +1244,7 @@ var SENTENCES = {
|
|
|
1236
1244
|
[
|
|
1237
1245
|
1402
|
|
1238
1246
|
/* WildcardRelative */
|
|
1239
|
-
]: (p) => `"${p}" is relative: it needs an enclosing "for" template`,
|
|
1247
|
+
]: (p) => `"${p}" is relative: it needs an enclosing "for" template (in script, a row: a row accessor, or a method called from a row)`,
|
|
1240
1248
|
[
|
|
1241
1249
|
1403
|
|
1242
1250
|
/* WildcardOtherList */
|
|
@@ -2556,7 +2564,7 @@ function getWcsManifest() {
|
|
|
2556
2564
|
}
|
|
2557
2565
|
|
|
2558
2566
|
// ../state/package.json
|
|
2559
|
-
var version = "4.
|
|
2567
|
+
var version = "4.22.0";
|
|
2560
2568
|
|
|
2561
2569
|
// src/service/wcsManifest.ts
|
|
2562
2570
|
var ENGINE_VERSION = version;
|
|
@@ -9298,6 +9306,13 @@ function analyzeDeclarationSpans(scriptContent) {
|
|
|
9298
9306
|
}
|
|
9299
9307
|
return out;
|
|
9300
9308
|
}
|
|
9309
|
+
function accessorRow(callable) {
|
|
9310
|
+
if (callable.kind !== "getter") return null;
|
|
9311
|
+
const segments = callable.name.split(".");
|
|
9312
|
+
let last = -1;
|
|
9313
|
+
for (let i = 0; i < segments.length; i++) if (segments[i] === "*" || segments[i] === "**") last = i;
|
|
9314
|
+
return last < 0 ? null : segments.slice(0, last + 1).join(".");
|
|
9315
|
+
}
|
|
9301
9316
|
function analyzeCallableBodies(scriptContent) {
|
|
9302
9317
|
const root = locateDefaultExportObject(scriptContent);
|
|
9303
9318
|
if (!root) return [];
|
|
@@ -9312,7 +9327,8 @@ function analyzeCallableBodies(scriptContent) {
|
|
|
9312
9327
|
end: root.start + prop.nameEnd,
|
|
9313
9328
|
body: prop.value ?? "",
|
|
9314
9329
|
bodyStart: root.start + (prop.valueStart ?? 0),
|
|
9315
|
-
accessor: prop.accessor
|
|
9330
|
+
accessor: prop.accessor,
|
|
9331
|
+
...prop.listed !== void 0 ? { listed: { ...prop.listed, start: root.start + prop.listed.start, end: root.start + prop.listed.end } } : {}
|
|
9316
9332
|
});
|
|
9317
9333
|
}
|
|
9318
9334
|
return out;
|
|
@@ -10236,6 +10252,19 @@ function inferJsonTypeHint(value) {
|
|
|
10236
10252
|
if (typeof value === "object") return "object";
|
|
10237
10253
|
return void 0;
|
|
10238
10254
|
}
|
|
10255
|
+
function listedPaths(key, keyStart) {
|
|
10256
|
+
const out = [];
|
|
10257
|
+
let at2 = 0;
|
|
10258
|
+
for (const part of key.split(",")) {
|
|
10259
|
+
const name = part.trim();
|
|
10260
|
+
if (name !== "") {
|
|
10261
|
+
const start = keyStart + at2 + (part.length - part.trimStart().length);
|
|
10262
|
+
out.push({ name, start, end: start + name.length });
|
|
10263
|
+
}
|
|
10264
|
+
at2 += part.length + 1;
|
|
10265
|
+
}
|
|
10266
|
+
return out;
|
|
10267
|
+
}
|
|
10239
10268
|
function locateDefaultExportObject(script) {
|
|
10240
10269
|
const scan = maskCommentsAndStrings(script);
|
|
10241
10270
|
const match = scan.match(/export\s+default\s+(?:defineState\s*\(\s*)?(\{)/);
|
|
@@ -10312,16 +10341,20 @@ function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
|
|
|
10312
10341
|
const accessor = match[0].startsWith("set") ? "set" : "get";
|
|
10313
10342
|
const returnsText = accessor === "get" ? readJsDocReturnsBefore(objectContent, match.index) : void 0;
|
|
10314
10343
|
const declaredType = returnsText === void 0 ? null : parseJsDocType(returnsText);
|
|
10315
|
-
|
|
10316
|
-
name: accessorName,
|
|
10344
|
+
const entry = {
|
|
10317
10345
|
kind: "getter",
|
|
10318
10346
|
accessor,
|
|
10319
10347
|
value: body,
|
|
10320
10348
|
valueStart: bodyStart,
|
|
10321
|
-
nameStart: nameSpan[0],
|
|
10322
|
-
nameEnd: nameSpan[1],
|
|
10323
10349
|
...declaredType !== null ? { declaredType } : {}
|
|
10324
|
-
}
|
|
10350
|
+
};
|
|
10351
|
+
const paths = accessorName.includes(",") ? listedPaths(accessorName, nameSpan[0]) : [];
|
|
10352
|
+
if (paths.length > 0) {
|
|
10353
|
+
const listed = { paths: paths.map((p) => p.name), key: accessorName, start: nameSpan[0], end: nameSpan[1] };
|
|
10354
|
+
for (const p of paths) props.push({ name: p.name, ...entry, nameStart: p.start, nameEnd: p.end, listed });
|
|
10355
|
+
continue;
|
|
10356
|
+
}
|
|
10357
|
+
props.push({ name: accessorName, ...entry, nameStart: nameSpan[0], nameEnd: nameSpan[1] });
|
|
10325
10358
|
continue;
|
|
10326
10359
|
}
|
|
10327
10360
|
const methodName = nameAt(4) ?? nameAt(5) ?? nameAt(6);
|
|
@@ -11147,7 +11180,20 @@ function collectGetterReads(body, options = {}) {
|
|
|
11147
11180
|
} finally {
|
|
11148
11181
|
collecting = {};
|
|
11149
11182
|
}
|
|
11150
|
-
|
|
11183
|
+
const row = options.row;
|
|
11184
|
+
return row == null ? out : out.map((read) => atRow(read, row));
|
|
11185
|
+
}
|
|
11186
|
+
var underRow = (path, row) => path === "." ? row : row + path;
|
|
11187
|
+
var ROW_APIS = /* @__PURE__ */ new Set(["$getAll", "$dependOn"]);
|
|
11188
|
+
function atRow(read, row) {
|
|
11189
|
+
if (!read.path.startsWith(".") || read.api !== void 0 && !ROW_APIS.has(read.api)) return read;
|
|
11190
|
+
return {
|
|
11191
|
+
...read,
|
|
11192
|
+
path: underRow(read.path, row),
|
|
11193
|
+
chain: read.chain === null ? null : [underRow(read.chain[0], row), ...read.chain.slice(1)],
|
|
11194
|
+
...read.indexed !== void 0 ? { indexed: read.indexed.map((list) => underRow(list, row)) } : {},
|
|
11195
|
+
relative: read.path
|
|
11196
|
+
};
|
|
11151
11197
|
}
|
|
11152
11198
|
function unwrapWrapper(program) {
|
|
11153
11199
|
if (program.type !== "Program" || program.body.length !== 1) return null;
|
|
@@ -11411,6 +11457,7 @@ function visitCall(node, scope, out) {
|
|
|
11411
11457
|
form: TRACK_APIS.has(api) ? "track" : "api",
|
|
11412
11458
|
callee: false,
|
|
11413
11459
|
written: false,
|
|
11460
|
+
api,
|
|
11414
11461
|
...scope.nested ? { nested: true } : {},
|
|
11415
11462
|
start: node.start - PREFIX.length,
|
|
11416
11463
|
end: node.end - PREFIX.length
|
|
@@ -11429,6 +11476,7 @@ function visitCall(node, scope, out) {
|
|
|
11429
11476
|
form: "api-write",
|
|
11430
11477
|
callee: false,
|
|
11431
11478
|
written: false,
|
|
11479
|
+
api,
|
|
11432
11480
|
...scope.nested ? { nested: true } : {},
|
|
11433
11481
|
start: first.start - PREFIX.length,
|
|
11434
11482
|
end: first.end - PREFIX.length
|
|
@@ -11890,6 +11938,11 @@ var ja = {
|
|
|
11890
11938
|
setterCycleSelf: (p) => `"${p}" \u306E setter \u304C\u81EA\u5206\u306E\u30D1\u30B9 "${p}" \u306B\u66F8\u3044\u3066\u3044\u307E\u3059\u3002setter \u306E\u30D1\u30B9\u306F\u30A2\u30AF\u30BB\u30B5\u305D\u306E\u3082\u306E\u306A\u306E\u3067\u3001\u66F8\u3051\u3070 setter \u304C\u307E\u305F\u547C\u3070\u308C\u3001\u30B9\u30BF\u30C3\u30AF\u304C\u6EA2\u308C\u308B\u307E\u3067\u7D9A\u304D\u307E\u3059\u3002\u5024\u306F getter \u304C\u8AAD\u3080\u30C7\u30FC\u30BF\u306E\u30D1\u30B9\uFF08_${p.split(".").pop()} \u306A\u3069\uFF09\u306B\u7F6E\u3044\u3066\u304F\u3060\u3055\u3044`,
|
|
11891
11939
|
setterCycle: (cycle) => `setter \u304C\u4E92\u3044\u306B\u66F8\u304D\u5408\u3063\u3066\u3044\u307E\u3059: ${cycle}\u3002\u6761\u4EF6\u3067\u6B62\u307E\u3089\u306A\u3051\u308C\u3070\u3001\u4E92\u3044\u3092\u547C\u3073\u7D9A\u3051\u3066\u30B9\u30BF\u30C3\u30AF\u304C\u6EA2\u308C\u307E\u3059\u3002\u5024\u306F getter \u304C\u8AAD\u3080\u30C7\u30FC\u30BF\u306E\u30D1\u30B9\u306B\u7F6E\u3044\u3066\u304F\u3060\u3055\u3044`,
|
|
11892
11940
|
setterUnobserved: (p, w) => `"${p}" \u306E setter \u306F ${w} \u3092\u66F8\u304D\u307E\u3059\u304C\u3001getter "${p}" \u306F\u305D\u306E\u3069\u308C\u3082\u8AAD\u307F\u307E\u305B\u3093\u3002\u66F8\u3044\u305F\u5F8C\u3082 getter \u306F\u5143\u306E\u5024\u3092\u8FD4\u3057\u3001"${p}" \u306B\u675F\u306D\u305F\u53CC\u65B9\u5411\u306E\u5165\u529B\u306F\u305D\u3053\u3078\u623B\u308A\u307E\u3059\u3002getter \u304C\u8AAD\u3080\u5024\u3092\u66F8\u304F\u304B\u3001setter \u304C\u66F8\u304F\u5024\u3092 getter \u3067\u8AAD\u3093\u3067\u304F\u3060\u3055\u3044`,
|
|
11941
|
+
relativePathOf: (r, a) => `\uFF08\u30A2\u30AF\u30BB\u30B5 "${a}" \u306E\u4E2D\u306E "${r}"\uFF09`,
|
|
11942
|
+
relativeNoRow: (r, a) => `"${r}" \u306F\u884C\u304B\u3089\u306E\u76F8\u5BFE\u30D1\u30B9\u3067\u3059\u304C\u3001\u30A2\u30AF\u30BB\u30B5 "${a}" \u306F\u30EA\u30B9\u30C8\u306E\u884C\u306E\u3082\u306E\u3067\u306F\u3042\u308A\u307E\u305B\u3093\uFF08\u30AD\u30FC\u306B "*" \u304C\u3042\u308A\u307E\u305B\u3093\uFF09\u3002\u884C\u304C\u7121\u3044\u306E\u3067\u3001\u8A55\u4FA1\u306E\u305F\u3073\u306B\u4F8B\u5916\u306B\u306A\u308A\u307E\u3059\uFF08#1402\uFF09\u3002\u30D5\u30EB\u30D1\u30B9\u3067\u66F8\u304F\u304B\u3001\u884C\u306E\u30A2\u30AF\u30BB\u30B5\uFF08get "<\u30EA\u30B9\u30C8>.*.<\u540D\u524D>"()\uFF09\u306B\u3057\u3066\u304F\u3060\u3055\u3044`,
|
|
11943
|
+
relativeApiPath: (r, api) => `"${r}" \u306F\u884C\u304B\u3089\u306E\u76F8\u5BFE\u30D1\u30B9\u3067\u3059\u304C\u3001${api} \u306F\u884C\u3092\u6DFB\u5B57\u306E\u5F15\u6570\u3067\u53D7\u3051\u53D6\u308A\u3001\u547C\u3070\u308C\u305F\u884C\u304B\u3089\u306F\u53D6\u308A\u307E\u305B\u3093\u3002\u76F8\u5BFE\u30D1\u30B9\u306F\u3053\u3053\u3067\u306F\u5C55\u958B\u3055\u308C\u305A\u3001\u547C\u3073\u51FA\u3057\u306F\u4F8B\u5916\u306B\u306A\u308A\u307E\u3059\u3002\u30D5\u30EB\u30D1\u30B9\u3067\u66F8\u3044\u3066\u304F\u3060\u3055\u3044\uFF08"<\u30EA\u30B9\u30C8>.*${r === "." ? "" : r}"\uFF09`,
|
|
11944
|
+
accessorListSyntax: (k, why) => `\u30A2\u30AF\u30BB\u30B5\u306E\u30AD\u30FC "${k}" \u306F\u8907\u6570\u306E\u30D1\u30B9\u306E\u4E26\u3073\u3067\u3059\u304C\u3001${why === "space" ? "\u30AB\u30F3\u30DE\u306E\u524D\u5F8C\u306B\u7A7A\u767D\u304C\u3042\u308A\u307E\u3059" : why === "empty" ? "\u7A7A\u306E\u9805\u76EE\u304C\u3042\u308A\u307E\u3059" : '\u518D\u5E30\u306E\u30D1\u30B9\uFF08"**"\uFF09\u306F\u4E26\u3079\u3089\u308C\u307E\u305B\u3093'}\u3002\u30D1\u30B9\u306F\u30AB\u30F3\u30DE\u3060\u3051\u3067\u533A\u5207\u308A\u307E\u3059\uFF08get "users.*.fullname,employees.*.fullname"()\uFF09${why === "recursive" ? "" : "\u3002\u30E9\u30F3\u30BF\u30A4\u30E0\u306F\u30AB\u30F3\u30DE\u306E\u9593\u3092\u305D\u306E\u307E\u307E\u30D1\u30B9\u306B\u3059\u308B\u306E\u3067\u3001\u3053\u306E\u307E\u307E\u3067\u306F\u8AB0\u3082\u8AAD\u307E\u306A\u3044\u30D1\u30B9\u304C\u5BA3\u8A00\u3055\u308C\u307E\u3059"}`,
|
|
11945
|
+
accessorListPath: (p, list, other, rel) => `"${p}" \u306F "${list}" \u306E\u884C\u306E\u30D1\u30B9\u3067\u3059\u304C\u3001\u3053\u306E\u30A2\u30AF\u30BB\u30B5\u306F "${other}" \u306B\u3082\u5BA3\u8A00\u3055\u308C\u3066\u3044\u307E\u3059\u3002\u305D\u3061\u3089\u306E\u884C\u3067\u306F\u3053\u306E\u30D1\u30B9\u306B\u884C\u304C\u7121\u304F\u3001\u8AAD\u307F\u306F undefined\u3001\u66F8\u304D\u306F\u4F8B\u5916\u306B\u306A\u308A\u307E\u3059\u3002\u884C\u304B\u3089\u306E\u76F8\u5BFE\u30D1\u30B9\u3067\u66F8\u3044\u3066\u304F\u3060\u3055\u3044: this["${rel}"]`,
|
|
11893
11946
|
nestedWritePathMissing: (p) => `\u30D1\u30B9 "${p}" \u306F\u72B6\u614B\u5B9A\u7FA9\u306B\u5B58\u5728\u3057\u307E\u305B\u3093\u3002\u66F8\u304D\u8FBC\u307F\u306F\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u306B\u65B0\u3057\u3044\u30AD\u30FC\u3092\u4F5C\u308B\u3060\u3051\u3067\u3001\u5BA3\u8A00\u3057\u305F\u30D1\u30B9\u306E\u675F\u7E1B\u306B\u306F\u5C4A\u304D\u307E\u305B\u3093`,
|
|
11894
11947
|
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`,
|
|
11895
11948
|
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\uFF08URL \u306F\u8AAD\u307E\u305A\u3001/ \u304B\u3089\u59CB\u307E\u308B\u30D1\u30B9\u306F wcs-validate --root=<\u30B5\u30A4\u30C8\u306E\u30EB\u30FC\u30C8> \u306E\u3068\u304D\u3060\u3051\u305D\u306E\u4E0B\u3067\u8AAD\u307F\u307E\u3059\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\u3059\u304B\u3001--root \u3092\u6E21\u3057\u3066\u304F\u3060\u3055\u3044`,
|
|
@@ -12122,6 +12175,11 @@ var en = {
|
|
|
12122
12175
|
setterCycleSelf: (p) => `The setter of "${p}" writes its own path "${p}". A setter's path is the accessor itself: writing it calls the setter again, until the stack overflows. Store the value under a data path the getter reads (such as _${p.split(".").pop()})`,
|
|
12123
12176
|
setterCycle: (cycle) => `Setters write each other: ${cycle}. Unless a condition stops them, they call each other until the stack overflows. Store the values under data paths the getters read`,
|
|
12124
12177
|
setterUnobserved: (p, w) => `The setter of "${p}" writes ${w}, none of which the getter "${p}" reads. After a write the getter returns its old value, and a two-way input bound to "${p}" goes back to it. Write what the getter reads, or read what the setter writes in the getter`,
|
|
12178
|
+
relativePathOf: (r, a) => ` ("${r}" in the accessor "${a}")`,
|
|
12179
|
+
relativeNoRow: (r, a) => `"${r}" is relative to a row, but the accessor "${a}" is not one of a list's rows (its key has no "*"). With no row it throws each time it is evaluated (#1402). Write the full path, or make it a row accessor (get "<list>.*.<name>"())`,
|
|
12180
|
+
relativeApiPath: (r, api) => `"${r}" is relative to a row, but ${api} takes its rows from its indexes argument, not from the row it is called at. A relative path is not expanded there, and the call throws. Write the full path ("<list>.*${r === "." ? "" : r}")`,
|
|
12181
|
+
accessorListSyntax: (k, why) => `The accessor key "${k}" lists several paths, but ${why === "space" ? "has a space beside a comma" : why === "empty" ? "has an empty entry" : 'a recursive path ("**") cannot be listed'}. Separate the paths with "," alone (get "users.*.fullname,employees.*.fullname"())${why === "recursive" ? "" : ": the runtime takes what is between the commas as it is, so this declares a path nothing reads"}`,
|
|
12182
|
+
accessorListPath: (p, list, other, rel) => `"${p}" is a path of the rows of "${list}", and this accessor is also declared for "${other}": at its rows that path has no row, so a read gives undefined and a write throws. Write it relative to the row: this["${rel}"]`,
|
|
12125
12183
|
nestedWritePathMissing: (p) => `Path "${p}" does not exist in the state definition. The write creates a new key in the object and reaches no binding of a declared path`,
|
|
12126
12184
|
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`,
|
|
12127
12185
|
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 URL is not read, and a path from / only under wcs-validate --root=<the site's root>): point it at the file laid out as on the server, relative to this file, or pass --root`,
|
|
@@ -15911,7 +15969,7 @@ function collectGetterReadsByName(html, stateTagName) {
|
|
|
15911
15969
|
const prefix = block.mountPath === null || block.mountPath === "" ? "" : `${block.mountPath}.`;
|
|
15912
15970
|
for (const callable of analyzeCallableBodies(block.content)) {
|
|
15913
15971
|
if (callable.kind !== "getter" || callable.accessor === "set") continue;
|
|
15914
|
-
const reads = collectGetterReads(callable.body) ?? [];
|
|
15972
|
+
const reads = collectGetterReads(callable.body, { row: accessorRow(callable) }) ?? [];
|
|
15915
15973
|
out.set(prefix + callable.name, reads.map((r) => prefix + r.path));
|
|
15916
15974
|
}
|
|
15917
15975
|
}
|
|
@@ -17956,6 +18014,7 @@ function validateIndexArity(script, scriptStart, locale2) {
|
|
|
17956
18014
|
if (parsed.args.length < 2) continue;
|
|
17957
18015
|
const path = literalString2(parsed.args[0]);
|
|
17958
18016
|
if (path === null) continue;
|
|
18017
|
+
if (path.startsWith(".")) continue;
|
|
17959
18018
|
if (hasRecursionWildcard(path)) continue;
|
|
17960
18019
|
const actual = literalArrayLength(parsed.args[1]);
|
|
17961
18020
|
if (actual === null) continue;
|
|
@@ -17984,7 +18043,7 @@ function validateGetterCycles(script, scriptStart, locale2) {
|
|
|
17984
18043
|
for (const getter of getters) {
|
|
17985
18044
|
if (getter.accessor === "set") continue;
|
|
17986
18045
|
const targets = /* @__PURE__ */ new Set();
|
|
17987
|
-
for (const read of collectGetterReads(getter.body) ?? []) {
|
|
18046
|
+
for (const read of collectGetterReads(getter.body, { row: accessorRow(getter) }) ?? []) {
|
|
17988
18047
|
if (declared.has(read.path)) targets.add(read.path);
|
|
17989
18048
|
}
|
|
17990
18049
|
edges.set(getter.name, [...targets]);
|
|
@@ -18702,8 +18761,9 @@ function validateScriptReads(html, stateTagName = "wcs-state", locale2, fileRead
|
|
|
18702
18761
|
});
|
|
18703
18762
|
}
|
|
18704
18763
|
}
|
|
18764
|
+
const saidInListed = /* @__PURE__ */ new Set();
|
|
18705
18765
|
for (const callable of analyzeCallableBodies(block.content)) {
|
|
18706
|
-
for (const read of collectGetterReads(callable.body, { templates: true, writes: true }) ?? []) {
|
|
18766
|
+
for (const read of collectGetterReads(callable.body, { templates: true, writes: true, row: accessorRow(callable) }) ?? []) {
|
|
18707
18767
|
const write = read.written || read.form === "write" || read.form === "api-write";
|
|
18708
18768
|
if (write && read.form !== "api-write" && !read.path.includes(".")) continue;
|
|
18709
18769
|
if (read.path.split(".").some((s) => s === "" || s.startsWith("$")) || hasRecursionWildcard(read.path)) continue;
|
|
@@ -18716,12 +18776,17 @@ function validateScriptReads(html, stateTagName = "wcs-state", locale2, fileRead
|
|
|
18716
18776
|
const said = suggestion(near.segment, near.names, msgs);
|
|
18717
18777
|
if (said === "") continue;
|
|
18718
18778
|
const at2 = block.contentStart + callable.bodyStart;
|
|
18779
|
+
if (callable.listed !== void 0) {
|
|
18780
|
+
const place = `${write}:${at2 + read.start}`;
|
|
18781
|
+
if (saidInListed.has(place)) continue;
|
|
18782
|
+
saidInListed.add(place);
|
|
18783
|
+
}
|
|
18719
18784
|
const member = read.form === "member" || read.form === "write";
|
|
18720
18785
|
out.push({
|
|
18721
18786
|
code: write ? WcsDiagnosticCode.WritePathMissing : WcsDiagnosticCode.ReadPathMissing,
|
|
18722
18787
|
start: at2 + read.start,
|
|
18723
18788
|
end: member ? at2 + read.start + statePart(callable.body.slice(read.start, read.end)) : at2 + read.end,
|
|
18724
|
-
message: (write ? msgs.nestedWritePathMissing(read.path) : msgs.readPathMissing(read.path, !read.path.includes("."))) + said,
|
|
18789
|
+
message: (write ? msgs.nestedWritePathMissing(read.path) : msgs.readPathMissing(read.path, !read.path.includes("."))) + (read.relative === void 0 ? "" : msgs.relativePathOf(read.relative, callable.name)) + said,
|
|
18725
18790
|
// a stateSchema says the path is not there, as for a binding's `wcs/path-nonexistent` (a write stays a
|
|
18726
18791
|
// warning, as the top-level one: a key the state adds on purpose is not a mistake)
|
|
18727
18792
|
severity: !write && applicationSchema !== void 0 ? "error" : "warning"
|
|
@@ -18745,7 +18810,7 @@ function isWrite(read) {
|
|
|
18745
18810
|
return read.form === "write" || read.form === "api-write" || read.written && read.form !== "opaque";
|
|
18746
18811
|
}
|
|
18747
18812
|
function bodyOf(callable) {
|
|
18748
|
-
const found = collectGetterReads(callable.body, OPTIONS);
|
|
18813
|
+
const found = collectGetterReads(callable.body, { ...OPTIONS, row: accessorRow(callable) });
|
|
18749
18814
|
if (found === null) return { callable, writes: [], reads: [], calls: [], opaque: true };
|
|
18750
18815
|
const writes = [];
|
|
18751
18816
|
const reads = [];
|
|
@@ -18753,7 +18818,7 @@ function bodyOf(callable) {
|
|
|
18753
18818
|
let opaque2 = false;
|
|
18754
18819
|
for (const read of found) {
|
|
18755
18820
|
const at2 = { start: callable.bodyStart + read.start, end: callable.bodyStart + read.end, nested: read.nested === true };
|
|
18756
|
-
if (read.form === "opaque") {
|
|
18821
|
+
if (read.form === "opaque" || read.path.startsWith(".")) {
|
|
18757
18822
|
opaque2 = true;
|
|
18758
18823
|
continue;
|
|
18759
18824
|
}
|
|
@@ -18857,6 +18922,8 @@ function validateScriptWrites(html, stateTagName = "wcs-state", locale2) {
|
|
|
18857
18922
|
function getterWrites(state, msgs, at2) {
|
|
18858
18923
|
const out = [];
|
|
18859
18924
|
for (const [name, getter] of state.getters) {
|
|
18925
|
+
const listed = getter.callable.listed;
|
|
18926
|
+
if (listed !== void 0 && listed.paths[0] !== name) continue;
|
|
18860
18927
|
for (const w of getter.writes) {
|
|
18861
18928
|
if (w.state !== true || w.nested) continue;
|
|
18862
18929
|
out.push({ code: WcsDiagnosticCode.GetterWrite, ...at2(w.start, w.end), message: msgs.getterWrite(w.path, name), severity: "error" });
|
|
@@ -18876,9 +18943,12 @@ function readonlyWrites(state, msgs, at2) {
|
|
|
18876
18943
|
if (readonly.size === 0) return [];
|
|
18877
18944
|
const out = [];
|
|
18878
18945
|
for (const body of [...state.methods.values(), ...state.setters.values()]) {
|
|
18946
|
+
const listed = body.callable.listed;
|
|
18947
|
+
const again = listed !== void 0 && listed.paths[0] !== body.callable.name;
|
|
18879
18948
|
for (const w of body.writes) {
|
|
18880
18949
|
const path = toWildcardForm(w.path);
|
|
18881
18950
|
if (w.state !== true || hasRecursionWildcard(path) || !readonly.has(path)) continue;
|
|
18951
|
+
if (again && out.some((d) => d.start === at2(w.start, w.end).start)) continue;
|
|
18882
18952
|
out.push({ code: WcsDiagnosticCode.PathReadonly, ...at2(w.start, w.end), message: msgs.pathReadonlyWrite(path), severity: "error" });
|
|
18883
18953
|
}
|
|
18884
18954
|
}
|
|
@@ -18937,6 +19007,84 @@ function unobservedSetters(state, msgs, at2) {
|
|
|
18937
19007
|
return out;
|
|
18938
19008
|
}
|
|
18939
19009
|
|
|
19010
|
+
// src/service/accessorListValidator.ts
|
|
19011
|
+
var OPTIONS2 = { templates: true, writes: true, resolveWrites: true, untracked: true };
|
|
19012
|
+
var INDEXED_APIS = /* @__PURE__ */ new Set(["$resolve", "$setAll", "$update"]);
|
|
19013
|
+
function rowOfPath(path) {
|
|
19014
|
+
const at2 = path.lastIndexOf("*");
|
|
19015
|
+
return at2 < 0 ? null : path.slice(0, at2 + 1);
|
|
19016
|
+
}
|
|
19017
|
+
function hasRow(row, needed) {
|
|
19018
|
+
return row !== null && (row === needed || row.startsWith(`${needed}.`));
|
|
19019
|
+
}
|
|
19020
|
+
function validateAccessorLists(html, stateTagName = "wcs-state", locale2) {
|
|
19021
|
+
const blocks = parseLoadedScriptBlocks(html, stateTagName).filter((block) => hasDefaultExportObject(block.content));
|
|
19022
|
+
if (blocks.length === 0) return [];
|
|
19023
|
+
const msgs = getMessages(locale2);
|
|
19024
|
+
const out = [];
|
|
19025
|
+
for (const block of blocks) {
|
|
19026
|
+
const at2 = (start, end) => ({ start: block.contentStart + start, end: block.contentStart + end });
|
|
19027
|
+
const keys = /* @__PURE__ */ new Set();
|
|
19028
|
+
for (const callable of analyzeCallableBodies(block.content)) {
|
|
19029
|
+
const listed = callable.listed;
|
|
19030
|
+
if (listed !== void 0 && !keys.has(listed.start)) {
|
|
19031
|
+
keys.add(listed.start);
|
|
19032
|
+
const why = listSyntax(listed.key, listed.paths);
|
|
19033
|
+
if (why !== null) {
|
|
19034
|
+
out.push({
|
|
19035
|
+
code: WcsDiagnosticCode.AccessorListSyntax,
|
|
19036
|
+
...at2(listed.start, listed.end),
|
|
19037
|
+
message: msgs.accessorListSyntax(listed.key, why),
|
|
19038
|
+
severity: "error"
|
|
19039
|
+
});
|
|
19040
|
+
}
|
|
19041
|
+
}
|
|
19042
|
+
if (listed !== void 0 && listed.paths[0] !== callable.name) continue;
|
|
19043
|
+
const reads = collectGetterReads(callable.body, OPTIONS2);
|
|
19044
|
+
if (reads === null) continue;
|
|
19045
|
+
const rows = (listed?.paths ?? [callable.name]).map((name) => accessorRow({ name, kind: callable.kind }));
|
|
19046
|
+
for (const read of reads) {
|
|
19047
|
+
if (read.form === "opaque") continue;
|
|
19048
|
+
const place = at2(callable.bodyStart + read.start, callable.bodyStart + read.end);
|
|
19049
|
+
if (read.path.startsWith(".") && read.api !== void 0 && INDEXED_APIS.has(read.api)) {
|
|
19050
|
+
out.push({ code: WcsDiagnosticCode.WildcardRank, ...place, message: msgs.relativeApiPath(read.path, read.api), severity: "error" });
|
|
19051
|
+
continue;
|
|
19052
|
+
}
|
|
19053
|
+
if (callable.kind !== "getter" || read.nested === true) continue;
|
|
19054
|
+
if (read.path.startsWith(".")) {
|
|
19055
|
+
if (rows.every((row) => row === null)) {
|
|
19056
|
+
out.push({ code: WcsDiagnosticCode.WildcardRank, ...place, message: msgs.relativeNoRow(read.path, describe(callable)), severity: "error" });
|
|
19057
|
+
}
|
|
19058
|
+
continue;
|
|
19059
|
+
}
|
|
19060
|
+
if (listed === void 0 || read.form === "api" || read.form === "api-write" || read.form === "track") continue;
|
|
19061
|
+
if (hasRecursionWildcard(read.path)) continue;
|
|
19062
|
+
const needed = rowOfPath(read.path);
|
|
19063
|
+
if (needed === null) continue;
|
|
19064
|
+
const home = rows.findIndex((row) => hasRow(row, needed));
|
|
19065
|
+
const away = rows.findIndex((row) => !hasRow(row, needed));
|
|
19066
|
+
if (home < 0 || away < 0) continue;
|
|
19067
|
+
const rest = read.path.slice(rows[home].length);
|
|
19068
|
+
out.push({
|
|
19069
|
+
code: WcsDiagnosticCode.AccessorListPath,
|
|
19070
|
+
...place,
|
|
19071
|
+
message: msgs.accessorListPath(read.path, needed.slice(0, -2), listed.paths[away], rest === "" ? "." : rest),
|
|
19072
|
+
severity: "error"
|
|
19073
|
+
});
|
|
19074
|
+
}
|
|
19075
|
+
}
|
|
19076
|
+
}
|
|
19077
|
+
return out;
|
|
19078
|
+
}
|
|
19079
|
+
function listSyntax(key, paths) {
|
|
19080
|
+
if (/\s/.test(key)) return "space";
|
|
19081
|
+
if (key.split(",").some((part) => part === "")) return "empty";
|
|
19082
|
+
return paths.some(hasRecursionWildcard) ? "recursive" : null;
|
|
19083
|
+
}
|
|
19084
|
+
function describe(callable) {
|
|
19085
|
+
return callable.listed?.key ?? callable.name;
|
|
19086
|
+
}
|
|
19087
|
+
|
|
18940
19088
|
// src/service/moduleTopReadValidator.ts
|
|
18941
19089
|
var GUARD_TAG = "wcs-guard-handler";
|
|
18942
19090
|
var STORAGES = /* @__PURE__ */ new Set(["localStorage", "sessionStorage"]);
|
|
@@ -19635,6 +19783,7 @@ function validateText(text3, options, applicationSchema) {
|
|
|
19635
19783
|
out.push(...validateScriptStateUses(text3, stateTagName, locale2, bindAttribute));
|
|
19636
19784
|
out.push(...validateScriptReads(text3, stateTagName, locale2, fileReader, applicationSchema, bindAttribute));
|
|
19637
19785
|
out.push(...validateScriptWrites(text3, stateTagName, locale2));
|
|
19786
|
+
out.push(...validateAccessorLists(text3, stateTagName, locale2));
|
|
19638
19787
|
out.push(...validateArrayMutations(text3, stateTagName, locale2));
|
|
19639
19788
|
out.push(...validateModuleTopReads(text3, stateTagName, locale2));
|
|
19640
19789
|
out.push(...validateWatchDeclarations(text3, stateTagName, locale2, fileReader));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/lint",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.22.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": {
|