@zgeoff/chex 0.1.5 → 0.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgeoff/chex",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Run each shared docs and repo check as one subcommand, with the lefthook pre-push baseline that calls them",
5
5
  "keywords": [
6
6
  "checks",
@@ -35,15 +35,15 @@
35
35
  "typecheck": "tsrs"
36
36
  },
37
37
  "dependencies": {
38
- "@zgeoff/std": "0.4.1",
38
+ "@zgeoff/std": "0.4.2",
39
39
  "oxc-parser": "0.156.0",
40
40
  "ts-pattern": "5.9.2"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/bun": "1.4.4",
44
- "@zgeoff/rig": "0.1.3",
45
- "@zgeoff/std": "0.4.1",
46
- "@zgeoff/testing": "0.2.0",
44
+ "@zgeoff/rig": "0.1.5",
45
+ "@zgeoff/std": "0.4.2",
46
+ "@zgeoff/testing": "0.2.1",
47
47
  "tiny-invariant": "1.3.3",
48
48
  "tsrs": "0.18.0-ts7.1.0-dev.20260929",
49
49
  "typescript": "7.0.2"
@@ -8,7 +8,7 @@
8
8
  # .gitattributes.
9
9
  # Fails on: a missing name or description, a name that differs from the folder or breaks the name
10
10
  # format, a description over 1,024 characters, a plain description that holds a colon YAML reads as a
11
- # key, frontmatter that Bun.YAML.parse refuses, a link with a line anchor outside code, and a SKILL.md body over 1,700 words.
11
+ # key, frontmatter that Bun.YAML.parse refuses (at the line it fails on), a link with a line anchor outside code, and a SKILL.md body over 1,700 words.
12
12
  # Warns on: a SKILL.md body over 1,500 words, a SKILL.md over 500
13
13
  # lines, a reference that SKILL.md does not list under ## References, a reference over 100 lines
14
14
  # with two or more headings and no contents list near its top, a code-formatted span outside a table that names an existing repo file, and a bullet in
@@ -338,16 +338,30 @@ sub check_frontmatter {
338
338
  if $colon;
339
339
 
340
340
  # The colon error already names the cause of the parse error that the colon brings.
341
- my $yaml_error = $colon ? undef : read_yaml_error(join("\n", @block) . "\n");
342
- fail($skill, "frontmatter is not valid YAML ($yaml_error), so a strict loader refuses the skill; escape each quote inside a quoted value, or write the value as a block scalar (>-)")
341
+ my ($yaml_line, $yaml_error) = $colon ? () : read_yaml_error(join("\n", @block));
342
+ # The block starts on the line after the opening ---.
343
+ my $where = defined $yaml_line ? "$skill:" . ($yaml_line + 1) : $skill;
344
+ fail($where, "frontmatter is not valid YAML ($yaml_error), so a strict loader refuses the skill; escape each quote inside a quoted value, or write the value as a block scalar (>-)")
343
345
  if defined $yaml_error;
344
346
  }
345
347
 
346
- # Returns the error that Bun.YAML.parse throws on the text, or undef when the text parses. The line
347
- # reads above take a stray quote inside a quoted value as text, where a strict loader refuses it.
348
+ # Returns the line that Bun.YAML.parse fails on and its error, or an empty list when it parses.
349
+ # The error of Bun holds no line. A head cut inside a valid quoted value fails with another error,
350
+ # so the line is the first one from which each head fails with the error that the whole text gives.
348
351
  sub read_yaml_error {
349
352
  my ($text) = @_;
350
- my $parse = q{try { Bun.YAML.parse(process.argv.at(-1)) } catch (error) { console.log(error.message); process.exit(1) }};
353
+ my $parse = q{
354
+ const lines = process.argv.at(-1).split("\n");
355
+ const readError = (count) => {
356
+ try { Bun.YAML.parse(lines.slice(0, count).join("\n")); return null } catch (error) { return error.message }
357
+ };
358
+ const message = readError(lines.length);
359
+ if (message === null) process.exit(0);
360
+ let line = lines.length;
361
+ while (line > 1 && readError(line - 1) === message) line--;
362
+ console.log(`${line}\t${message}`);
363
+ process.exit(1);
364
+ };
351
365
  my $parser;
352
366
  # The check prints its own message when bun is missing, in place of the warning perl adds.
353
367
  no warnings "exec";
@@ -357,11 +371,12 @@ sub read_yaml_error {
357
371
  }
358
372
  my $output = do { local $/; <$parser> } // "";
359
373
  close $parser;
360
- return undef if $? == 0;
374
+ return () if $? == 0;
361
375
  utf8::decode($output);
362
376
  $output =~ s/\s+\z//;
363
377
  $output =~ s/\s*\n\s*/ /g;
364
- return $output eq "" ? "bun exited with status " . ($? >> 8) : $output;
378
+ return ($1, $2) if $output =~ /\A([0-9]+)\t(.+)\z/;
379
+ return (undef, $output eq "" ? "bun exited with status " . ($? >> 8) : $output);
365
380
  }
366
381
 
367
382
  # Returns block, quoted or plain for the text after a key, or undef when the text is empty or only a