@wcstack/lint 3.3.0 → 3.4.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 (2) hide show
  1. package/dist/cli.cjs +72 -16
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -3230,7 +3230,8 @@ var ja = {
3230
3230
  patternPathOutsideFor: (p) => `\u30D1\u30BF\u30FC\u30F3\u30D1\u30B9 "${p}" \u306F <template for> \u306E\u5916\u5074\u3067\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093`,
3231
3231
  omittedPathOutsideFor: (p) => `\u7701\u7565\u30D1\u30B9 "${p}" \u306F <template for> \u306E\u5916\u5074\u3067\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093`,
3232
3232
  loopIndexOutsideFor: (p) => `\u30EB\u30FC\u30D7\u30A4\u30F3\u30C7\u30C3\u30AF\u30B9 "${p}" \u306F <template for> \u306E\u5916\u5074\u3067\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093`,
3233
- resolvedPathInUi: (p) => `\u89E3\u6C7A\u6E08\u307F\u30D1\u30B9 "${p}" \u306F UI \u30D0\u30A4\u30F3\u30C7\u30A3\u30F3\u30B0\u3067\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093\u3002\u30D1\u30BF\u30FC\u30F3\u30D1\u30B9\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044`,
3233
+ resolvedPathInUi: (p) => `\u30D1\u30B9 "${p}" \u306F\u884C\u3067\u306F\u306A\u304F\u7D20\u306E\u30D1\u30B9\u3068\u3057\u3066\u8AAD\u307E\u308C\u308B\u305F\u3081\u3001\u6DFB\u5B57\u3092\u901A\u3057\u305F\u66F8\u304D\u8FBC\u307F\u304C\u3053\u306E\u30D0\u30A4\u30F3\u30C7\u30A3\u30F3\u30B0\u306B\u5C4A\u304D\u307E\u305B\u3093\uFF08\u6700\u521D\u306E\u5024\u306E\u307E\u307E\u6B62\u307E\u308B\u3053\u3068\u304C\u3042\u308A\u307E\u3059\uFF09\u3002\u6307\u3059\u884C\u306B\u8FFD\u5F93\u3059\u308B\u306E\u306F\u3001\u6570\u5024\u306E\u6DFB\u5B57\u304C\u3061\u3087\u3046\u3069 1 \u3064\u3067 "*" \u3092\u542B\u307E\u306A\u3044\u30D1\u30B9\uFF08items.0.name\uFF09\u3060\u3051\u3067\u3059\u3002<template for> \u306E\u4E2D\u3067\u30D1\u30BF\u30FC\u30F3\u30D1\u30B9\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044`,
3234
+ indexPathInFor: (p) => `for: "${p}" \u306F\u6570\u5024\u306E\u6DFB\u5B57\u3092\u542B\u3080\u30EA\u30B9\u30C8\u3067\u3059\u3002\u884C\u306F "${p}.*.\u2026" \u3068\u3057\u3066\u89E3\u6C7A\u3055\u308C\u3001\u884C\u3078\u306E\u53CC\u65B9\u5411\u675F\u7E1B\uFF08value: .v\uFF09\u3084\u6DFB\u5B57\u306E\u30D1\u30B9\u306E\u8AAD\u307F\u66F8\u304D\u306F\u5B9F\u884C\u6642\u306B\u4F8B\u5916\u306B\u306A\u308A\u307E\u3059\uFF08@wcstack/state #363\uFF09\u3002\u30EA\u30B9\u30C8\u306E\u6BB5\u3054\u3068\u306B for: \u3092\u5165\u308C\u5B50\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u4F8B: for: groups \u306E\u4E2D\u306B for: .items\uFF09`,
3234
3235
  indexArity: (api, p, req, wc, actual) => `${api}("${p}") \u306E\u6DFB\u5B57\u306F${req === "exact" ? `\u3061\u3087\u3046\u3069 ${wc} \u500B` : `${wc} \u500B\u4EE5\u4E0B`}\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059\uFF08\u30D1\u30B9\u4E2D\u306E "*" \u306F ${wc} \u500B\uFF09\u3002${actual} \u500B\u6307\u5B9A\u3055\u308C\u3066\u3044\u307E\u3059`,
3235
3236
  wildcardRank: (subject, needed, available) => `${subject} \u306F ${needed} \u6BB5\u306E\u30EB\u30FC\u30D7\u304C\u5FC5\u8981\u3067\u3059\u304C\u3001\u73FE\u5728\u306E\u30B9\u30B3\u30FC\u30D7\u306F ${available} \u6BB5\u3067\u3059`,
3236
3237
  getterCycle: (cycle) => `\u30D1\u30B9 getter \u304C\u5FAA\u74B0\u53C2\u7167\u3057\u3066\u3044\u307E\u3059: ${cycle}`,
@@ -3252,6 +3253,7 @@ var ja = {
3252
3253
  watchKeyEmptySegment: (k) => `$watch \u306E\u30AD\u30FC "${k}" \u306B\u7A7A\u306E\u30D1\u30B9\u30BB\u30B0\u30E1\u30F3\u30C8\u304C\u3042\u308A\u307E\u3059`,
3253
3254
  watchHandlerNotFunction: (k) => `$watch \u306E\u30A8\u30F3\u30C8\u30EA "${k}" \u306E\u5024\u306F\u95A2\u6570\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`,
3254
3255
  watchPathMissing: (k) => `$watch \u306E\u30AD\u30FC "${k}" \u306F\u72B6\u614B\u5B9A\u7FA9\u306B\u5B58\u5728\u3057\u307E\u305B\u3093\uFF08\u4E00\u5EA6\u3082\u767A\u706B\u3057\u307E\u305B\u3093\uFF09`,
3256
+ watchIndexKey: (k) => `$watch \u306E\u30AD\u30FC "${k}" \u306F\u6570\u5024\u306E\u6DFB\u5B57\u3092\u542B\u307F\u307E\u3059\u3002\u30EA\u30B9\u30C8\u304C\u4E38\u3054\u3068\u7F6E\u304D\u63DB\u308F\u308B\u3068\u767A\u706B\u3057\u307E\u3059\u304C\u3001\u6DFB\u5B57\u3092\u901A\u3057\u305F\u66F8\u304D\u8FBC\u307F\uFF08this["${k}"] = \u2026\uFF09\u3067\u306F\u767A\u706B\u3057\u307E\u305B\u3093\uFF08\u540C\u3058\u30D1\u30B9\u3092\u30DE\u30FC\u30AF\u30A2\u30C3\u30D7\u3067\u675F\u7E1B\u3057\u3066\u3044\u308C\u3070\u767A\u706B\u3057\u307E\u3059\uFF09`,
3255
3257
  scanNotObject: () => `$scan \u306F\u300C\u51FA\u529B\u540D \u2192 { from | on, initial, fold, resetOn? }\u300D\u306E\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059\uFF08\u3053\u306E\u5F62\u306F\u30E9\u30F3\u30BF\u30A4\u30E0\u304C\u8AAD\u307F\u8FBC\u307F\u6642\u306B throw \u3057\u307E\u3059\uFF09`,
3256
3258
  scanOutputInvalid: (n) => `$scan \u306E\u51FA\u529B\u540D "${n}" \u306F\u5E73\u5766\u306A\u30D7\u30ED\u30D1\u30C6\u30A3\u540D\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059\uFF08"."\u30FB"*"\u30FB\u5148\u982D\u306E "$" \u306F\u4F7F\u3048\u307E\u305B\u3093\uFF09`,
3257
3259
  scanOutputReserved: (n) => `$scan \u306E\u51FA\u529B\u540D "${n}" \u306F Object.prototype \u304B\u3089\u7D99\u627F\u3055\u308C\u308B\u540D\u524D\u3067\u3059\uFF08"constructor" \u306A\u3069\uFF09`,
@@ -3426,7 +3428,8 @@ var en = {
3426
3428
  patternPathOutsideFor: (p) => `Pattern path "${p}" cannot be used outside a <template for>`,
3427
3429
  omittedPathOutsideFor: (p) => `Shorthand path "${p}" cannot be used outside a <template for>`,
3428
3430
  loopIndexOutsideFor: (p) => `Loop index "${p}" cannot be used outside a <template for>`,
3429
- resolvedPathInUi: (p) => `Resolved path "${p}" cannot be used in a UI binding. Use a pattern path instead`,
3431
+ resolvedPathInUi: (p) => `Path "${p}" is read as a plain path, not as a row, so a write through its index does not reach this binding (it can keep its first value). Only a path with exactly one numeric index and no "*" (items.0.name) follows the row it points at. Use a pattern path inside a <template for> instead`,
3432
+ indexPathInFor: (p) => `for: "${p}" is a list reached through a numeric index. Its rows resolve as "${p}.*.\u2026", and a two-way binding in a row (value: .v) or a read or write through an index path throws at runtime (@wcstack/state #363). Nest one for: per list level instead (e.g. for: groups, with for: .items inside)`,
3430
3433
  indexArity: (api, p, req, wc, actual) => `${api}("${p}") requires ${req === "exact" ? "exactly" : "at most"} ${wc} index(es) ("*" appears ${wc} time(s) in the path) but got ${actual}`,
3431
3434
  wildcardRank: (subject, needed, available) => `${subject} needs ${needed} enclosing loop level(s) but the current scope provides ${available}`,
3432
3435
  getterCycle: (cycle) => `Path getters form a dependency cycle: ${cycle}`,
@@ -3448,6 +3451,7 @@ var en = {
3448
3451
  watchKeyEmptySegment: (k) => `$watch key "${k}" has an empty path segment`,
3449
3452
  watchHandlerNotFunction: (k) => `The value of $watch entry "${k}" must be a function`,
3450
3453
  watchPathMissing: (k) => `$watch key "${k}" does not exist in the state definition (it will never fire)`,
3454
+ watchIndexKey: (k) => `$watch key "${k}" has a numeric index: it fires when the list is replaced, but not on a write through the index (this["${k}"] = \u2026) unless the same path is also bound in the markup`,
3451
3455
  scanNotObject: () => `$scan must be an object mapping output names to { from | on, initial, fold, resetOn? } (the runtime throws on this shape at load time)`,
3452
3456
  scanOutputInvalid: (n) => `$scan output name "${n}" must be a flat property name ("." and "*" and a leading "$" are not allowed)`,
3453
3457
  scanOutputReserved: (n) => `$scan output name "${n}" is a property name inherited from Object.prototype (e.g. "constructor")`,
@@ -3798,6 +3802,49 @@ function escape(key) {
3798
3802
  return key.replace(/~/g, "~0").replace(/\//g, "~1");
3799
3803
  }
3800
3804
 
3805
+ // src/service/indexPath.ts
3806
+ var ARRAY_INDEX_KEY = /^(?:0|[1-9]\d*)$/;
3807
+ function isNumericSegment(segment) {
3808
+ return segment !== "" && !Number.isNaN(Number(segment));
3809
+ }
3810
+ function rowIndexPosition(segments) {
3811
+ if (segments[0] === "" || segments.includes("*")) return -1;
3812
+ let position = -1;
3813
+ for (let i = 0; i < segments.length; i++) {
3814
+ if (!isNumericSegment(segments[i])) continue;
3815
+ if (i === 0 || position !== -1) return -1;
3816
+ position = i;
3817
+ }
3818
+ return position;
3819
+ }
3820
+ function isPlainIndexPath(path) {
3821
+ return hasIndexSegment(path) && rowIndexPosition(path.split(".")) === -1;
3822
+ }
3823
+ function hasIndexSegment(path) {
3824
+ return path.split(".").some((segment, i) => i > 0 && isNumericSegment(segment));
3825
+ }
3826
+ function toRowPatternPath(path, pathSet) {
3827
+ const segments = path.split(".");
3828
+ const position = rowIndexPosition(segments);
3829
+ if (position === -1 || Number(segments[position]) < 0) return path;
3830
+ if (!pathSet.has(`${segments.slice(0, position).join(".")}.*`)) return path;
3831
+ segments[position] = "*";
3832
+ return segments.join(".");
3833
+ }
3834
+ function toPlainPatternPath(path, pathSet) {
3835
+ const segments = path.split(".");
3836
+ for (let i = 1; i < segments.length; i++) {
3837
+ if (ARRAY_INDEX_KEY.test(segments[i]) && pathSet.has(`${segments.slice(0, i).join(".")}.*`)) {
3838
+ segments[i] = "*";
3839
+ }
3840
+ }
3841
+ return segments.join(".");
3842
+ }
3843
+ function isPlainElementPath(path, candidates, pathSet) {
3844
+ const pattern = toPlainPatternPath(path, pathSet);
3845
+ return candidates.some((c) => c.path === pattern && (c.kind === "data" || c.kind === "list"));
3846
+ }
3847
+
3801
3848
  // src/service/bindingValidator.ts
3802
3849
  var filterMap = new Map(BUILTIN_FILTERS.map((f) => [f.name, f]));
3803
3850
  function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, fileReader, applicationSchema) {
@@ -3995,14 +4042,15 @@ function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, f
3995
4042
  }
3996
4043
  }
3997
4044
  }
3998
- if (/\.\d+\.|\.\d+$/.test(pathTrimmed)) {
4045
+ const isFor = propNoMod === "for";
4046
+ if (isFor ? hasIndexSegment(pathTrimmed) : isPlainIndexPath(pathTrimmed)) {
3999
4047
  const pathOffset = binding.indexOf(parsed.path);
4000
4048
  const pathStart = bindingStart + pathOffset;
4001
4049
  diagnostics.push({
4002
4050
  code: WcsDiagnosticCode.TemplateSyntax,
4003
4051
  start: pathStart,
4004
4052
  end: pathStart + pathTrimmed.length,
4005
- message: msgs.resolvedPathInUi(pathTrimmed),
4053
+ message: isFor ? msgs.indexPathInFor(pathTrimmed) : msgs.resolvedPathInUi(pathTrimmed),
4006
4054
  severity: "warning"
4007
4055
  });
4008
4056
  }
@@ -4027,7 +4075,7 @@ function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, f
4027
4075
  const pathTrimmed = parsed.path.trim();
4028
4076
  if (pathTrimmed && !pathTrimmed.startsWith(".") && !isLiteral(pathTrimmed)) {
4029
4077
  const chainDiags = validateFilterChainTypes(
4030
- pathTrimmed,
4078
+ toRowPatternPath(pathTrimmed, scopedPathSet),
4031
4079
  parsed.filters,
4032
4080
  scopedPaths,
4033
4081
  bindingStart,
@@ -4043,7 +4091,8 @@ function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, f
4043
4091
  if (parsed.path && scopedPaths.length > 0) {
4044
4092
  const pathTrimmed = parsed.path.trim();
4045
4093
  if (pathTrimmed && !pathTrimmed.startsWith(".") && !isLiteral(pathTrimmed)) {
4046
- const resultType = resolveResultType(pathTrimmed, parsed.filters, scopedPaths);
4094
+ const typePath = toRowPatternPath(pathTrimmed, scopedPathSet);
4095
+ const resultType = resolveResultType(typePath, parsed.filters, scopedPaths);
4047
4096
  if (resultType !== null) {
4048
4097
  const typeReq = getExpectedType(
4049
4098
  parsed.property,
@@ -4052,7 +4101,7 @@ function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, f
4052
4101
  if (typeReq && resultType !== typeReq.expected) {
4053
4102
  const pathOffset = binding.indexOf(parsed.path);
4054
4103
  const pathStart = bindingStart + pathOffset;
4055
- const schemaDefinite = typeReq.expected === "array" && parsed.filters.length === 0 && applicationSchema !== void 0 && scopedPaths.some((p) => p.path === pathTrimmed && p.fromSchema === true);
4104
+ const schemaDefinite = typeReq.expected === "array" && parsed.filters.length === 0 && applicationSchema !== void 0 && scopedPaths.some((p) => p.path === typePath && p.fromSchema === true);
4056
4105
  diagnostics.push({
4057
4106
  code: schemaDefinite ? WcsDiagnosticCode.PathTypeMismatch : WcsDiagnosticCode.BindingTypeExpectation,
4058
4107
  start: pathStart,
@@ -4216,7 +4265,9 @@ function validatePathExistence(checkPath, displayPath, scopedPaths, scopedPathSe
4216
4265
  }
4217
4266
  return null;
4218
4267
  }
4219
- if (!scopedPathSet.has(checkPath) && !matchesRecursionCandidates(scopedPaths, checkPath, scopedPathSet)) {
4268
+ if (scopedPathSet.has(checkPath)) return null;
4269
+ const rowPath = toRowPatternPath(checkPath, scopedPathSet);
4270
+ if (!scopedPathSet.has(rowPath) && !matchesRecursionCandidates(scopedPaths, rowPath, scopedPathSet) && !isPlainElementPath(checkPath, scopedPaths, scopedPathSet)) {
4220
4271
  return msgs.pathMissing(displayPath);
4221
4272
  }
4222
4273
  return null;
@@ -4234,8 +4285,11 @@ function validateSchemaPathExistence(checkPath, displayPath, scopedPaths, scoped
4234
4285
  return toMissingVerdict(validatePathExistence(checkPath, displayPath, scopedPaths, scopedPathSet, commandNames, msgs));
4235
4286
  }
4236
4287
  if (scopedPathSet.has(checkPath)) return null;
4237
- if (matchesRecursionCandidates(scopedPaths, checkPath, scopedPathSet)) return null;
4238
- const resolution = resolveSchemaPath(schema, schema.$defs ?? {}, checkPath.split("."));
4288
+ const rowPath = toRowPatternPath(checkPath, scopedPathSet);
4289
+ if (scopedPathSet.has(rowPath)) return null;
4290
+ if (matchesRecursionCandidates(scopedPaths, rowPath, scopedPathSet)) return null;
4291
+ if (isPlainElementPath(checkPath, scopedPaths, scopedPathSet)) return null;
4292
+ const resolution = resolveSchemaPath(schema, schema.$defs ?? {}, toPlainPatternPath(rowPath, scopedPathSet).split("."));
4239
4293
  if (resolution.kind === "nonexistent") {
4240
4294
  return { code: WcsDiagnosticCode.PathNonexistent, message: msgs.pathNonexistent(displayPath), severity: "error" };
4241
4295
  }
@@ -4668,9 +4722,10 @@ function validateTemplateSyntax(html, stateTagName, bindAttrName = "data-wcs", l
4668
4722
  message: msgs.recursionUnsupported(path, "binding")
4669
4723
  };
4670
4724
  }
4671
- if (isValidTemplatePath(path, pathSet2, scoped)) return null;
4725
+ const rowPath = toRowPatternPath(path, pathSet2);
4726
+ if (isValidTemplatePath(path, rowPath, pathSet2, scoped)) return null;
4672
4727
  if (defaultSchema !== void 0 && !path.startsWith("$")) {
4673
- const resolution = resolveSchemaPath(defaultSchema, defaultSchema.$defs ?? {}, path.split("."));
4728
+ const resolution = resolveSchemaPath(defaultSchema, defaultSchema.$defs ?? {}, toPlainPatternPath(rowPath, pathSet2).split("."));
4674
4729
  return resolution.kind === "nonexistent" ? { code: WcsDiagnosticCode.PathNonexistent, severity: "error", message: msgs.pathNonexistent(displayPath) } : null;
4675
4730
  }
4676
4731
  return { code: WcsDiagnosticCode.BindingPathMissing, severity: "warning", message: msgs.pathMissing(displayPath) };
@@ -4740,7 +4795,7 @@ function validateTemplateSyntax(html, stateTagName, bindAttrName = "data-wcs", l
4740
4795
  }
4741
4796
  }
4742
4797
  }
4743
- if (/\.\d+\.|\.\d+$/.test(pathPart)) {
4798
+ if (isPlainIndexPath(pathPart)) {
4744
4799
  diagnostics.push({
4745
4800
  code: WcsDiagnosticCode.TemplateSyntax,
4746
4801
  start: item.exprStart,
@@ -4805,14 +4860,14 @@ function validateTemplateSyntax(html, stateTagName, bindAttrName = "data-wcs", l
4805
4860
  }
4806
4861
  return diagnostics;
4807
4862
  }
4808
- function isValidTemplatePath(path, pathSet, scopedPaths) {
4863
+ function isValidTemplatePath(path, rowPath, pathSet, scopedPaths) {
4809
4864
  if (/^\$\d+$/.test(path)) return true;
4810
4865
  if (path.startsWith("$streamStatus.") || path.startsWith("$streamError.")) {
4811
4866
  const prefix = path.startsWith("$streamStatus.") ? "$streamStatus." : "$streamError.";
4812
4867
  const hasNamespace = scopedPaths.some((p) => p.path.startsWith(prefix));
4813
4868
  return !hasNamespace || pathSet.has(path);
4814
4869
  }
4815
- return pathSet.has(path) || matchesRecursionCandidates(scopedPaths, path, pathSet);
4870
+ return pathSet.has(path) || pathSet.has(rowPath) || matchesRecursionCandidates(scopedPaths, rowPath, pathSet) || isPlainElementPath(path, scopedPaths, pathSet);
4816
4871
  }
4817
4872
 
4818
4873
  // src/core/parser/positionalParser.ts
@@ -6717,9 +6772,10 @@ function validateEntry(entry, pathSet, paths, msgs) {
6717
6772
  return invalid(msgs.watchHandlerNotFunction(key));
6718
6773
  }
6719
6774
  if (pathSet.size > 0 && !pathSet.has(key) && !matchesRecursion(collectRecursionSpecs(paths), key, (p) => pathSet.has(p))) {
6775
+ const rowKey = toRowPatternPath(key, pathSet);
6720
6776
  return {
6721
6777
  code: WcsDiagnosticCode.WatchPathMissing,
6722
- message: msgs.watchPathMissing(key),
6778
+ message: rowKey !== key && pathSet.has(rowKey) ? msgs.watchIndexKey(key) : msgs.watchPathMissing(key),
6723
6779
  severity: "warning"
6724
6780
  };
6725
6781
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wcstack/lint",
3
- "version": "3.3.0",
3
+ "version": "3.4.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": {