@zgeoff/chex 0.0.11 → 0.0.13

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.0.11",
3
+ "version": "0.0.13",
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",
@@ -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, 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, 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
@@ -284,10 +284,12 @@ sub list_references {
284
284
  sub check_frontmatter {
285
285
  my ($dir, $skill, @lines) = @_;
286
286
  my ($name, $description, $in_description, $closed, $raw_description, $folded, $style, $colon);
287
+ my @block;
287
288
 
288
289
  if (@lines && $lines[0] eq "---") {
289
290
  for my $line (@lines[1 .. $#lines]) {
290
291
  if ($line eq "---") { $closed = 1; last }
292
+ push @block, $line;
291
293
  if ($line =~ /^name:\s*(.*?)\s*$/) {
292
294
  $name = unquote($1);
293
295
  $in_description = 0;
@@ -334,6 +336,32 @@ sub check_frontmatter {
334
336
 
335
337
  fail($skill, "description holds a colon and a space, which YAML reads as a key in a plain scalar; reword it, or quote it or write it as a block scalar (>-)")
336
338
  if $colon;
339
+
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 (>-)")
343
+ if defined $yaml_error;
344
+ }
345
+
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
+ sub read_yaml_error {
349
+ my ($text) = @_;
350
+ my $parse = q{try { Bun.YAML.parse(process.argv.at(-1)) } catch (error) { console.log(error.message); process.exit(1) }};
351
+ my $parser;
352
+ # The check prints its own message when bun is missing, in place of the warning perl adds.
353
+ no warnings "exec";
354
+ unless (open $parser, "-|", "bun", "-e", $parse, to_bytes($text)) {
355
+ print STDERR "check-skill: cannot run bun to parse the frontmatter: $!\n";
356
+ exit 2;
357
+ }
358
+ my $output = do { local $/; <$parser> } // "";
359
+ close $parser;
360
+ return undef if $? == 0;
361
+ utf8::decode($output);
362
+ $output =~ s/\s+\z//;
363
+ $output =~ s/\s*\n\s*/ /g;
364
+ return $output eq "" ? "bun exited with status " . ($? >> 8) : $output;
337
365
  }
338
366
 
339
367
  # Returns block, quoted or plain for the text after a key, or undef when the text is empty or only a