@scientific-method/standard-checker 0.5.1 → 0.6.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.
@@ -4,6 +4,20 @@ import { dirname, join } from "node:path";
4
4
  import { readText } from "../markdown.js";
5
5
  import { locationRule, unlistedFormat } from "../standard.js";
6
6
  import { parseYaml } from "../yaml.js";
7
+ /**
8
+ * Returns a manifest or other-files path as text, or reports it and returns undefined when it is
9
+ * missing or is a map or list. The YAML reader turns a bare name such as 1990 or 0 into a number,
10
+ * so a number or boolean is a path written without quotes and is read as its text.
11
+ */
12
+ function pathText(value, file, missing, problem) {
13
+ if (value === null || value === undefined || value === "")
14
+ problem(file, missing);
15
+ else if (typeof value === "object")
16
+ problem(file, "a path is text, not a map or list");
17
+ else
18
+ return String(value);
19
+ return undefined;
20
+ }
7
21
  /**
8
22
  * Reads and checks the manifest of every build entry, and reports a manifest or list of other files
9
23
  * that belongs to no build. Returns build ID -> the items of its files list that are maps.
@@ -40,9 +54,16 @@ export function loadBuildFiles({ config, problem }, entries) {
40
54
  problem(path, "every item of files is a map of path, format, size and xxh3");
41
55
  const files = manifest.files.filter((f) => f && typeof f === "object");
42
56
  buildFiles.set(id, files);
57
+ // A manifest gives one format, size and hash per file, so a path it lists twice is reported
58
+ // even when the two items agree. Paths compare as text, as in the list of other files.
59
+ const seen = new Set();
43
60
  for (const f of files) {
44
- if (!f.path)
45
- problem(path, "every file has a path");
61
+ const p = pathText(f.path, path, "every file has a path", problem);
62
+ if (p !== undefined) {
63
+ if (seen.has(p))
64
+ problem(path, `${p} is listed twice`);
65
+ seen.add(p);
66
+ }
46
67
  if (f.format === undefined || f.format === null || f.format === "")
47
68
  problem(path, `${f.path}: every file has a format`);
48
69
  else if (!locationRule(f.format))
@@ -105,11 +126,9 @@ export function checkOtherFiles({ problem }, entries, buildFiles) {
105
126
  problem(path, "every item of other_files is a map of path and reason");
106
127
  continue;
107
128
  }
108
- if (item.path === null || item.path === undefined || item.path === "") {
109
- problem(path, "every other file has a path");
129
+ const other = pathText(item.path, path, "every other file has a path", problem);
130
+ if (other === undefined)
110
131
  continue;
111
- }
112
- const other = String(item.path);
113
132
  if (item.reason === null || String(item.reason).trim() === "")
114
133
  problem(path, `${other}: every other file gives the reason the manifest leaves it out`);
115
134
  if (other.includes("\\"))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scientific-method/standard-checker",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "Checks a restoration's spec/, parity/ and deviations/ against version 1 of the dinorefurb documentation standard.",
5
5
  "type": "module",
6
6
  "license": "MIT",