@zgeoff/chex 0.2.6 → 0.3.1

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/README.md CHANGED
@@ -48,7 +48,7 @@ The docs checks read the repo's READMEs, its `docs/` tree and its skills:
48
48
  | `links` | a relative link or anchor that does not resolve | the paths |
49
49
  | `readmes` | a README of none of the [five kinds](https://github.com/zgeoff/skills/blob/main/skills/docs-writing/references/readmes.md#the-five-kinds) | none |
50
50
  | `vision` | a missing `docs/vision.md`, or one past 60 lines | none |
51
- | `skill` | a skill's frontmatter, its word limit, and a link with a line anchor | the skill dirs |
51
+ | `skill` | a skill's frontmatter, its word limit, a link with a line anchor, and a coined term such as "lane" or "the unit run" | the skill dirs |
52
52
 
53
53
  The repo checks read the branch, the pushed commits and the repo's config:
54
54
 
package/lefthook.yml CHANGED
@@ -86,7 +86,7 @@ pre-push:
86
86
  glob: '*.md'
87
87
  run: '{clear-git-env} bun x --no-install diet -- bun run --silent check:docs'
88
88
  # GitHub runs no workflow from a subfolder of .github/workflows, and
89
- # sync/workflow-callers holds the workflows that tools delivers. actionlint
89
+ # sync/src/workflow-callers holds the workflows that tools delivers. actionlint
90
90
  # 1.7.12 rejects the concurrency queue key that GitHub documents, until
91
91
  # rhysd/actionlint#654 ships; the ignore lapses on the same date as in CI.
92
92
  # The workflow lint runs after actionlint, even when actionlint is missing
@@ -97,7 +97,7 @@ pre-push:
97
97
  node_modules/@zgeoff/chex/src/read-branch-files.ts
98
98
  glob:
99
99
  - '.github/workflows/*.{yml,yaml}'
100
- - 'sync/workflow-callers/*.{yml,yaml}'
100
+ - 'sync/src/workflow-callers/*.{yml,yaml}'
101
101
  run: |
102
102
  {clear-git-env}
103
103
  status=0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgeoff/chex",
3
- "version": "0.2.6",
3
+ "version": "0.3.1",
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,8 @@
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 (at the line it fails on), 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, a
12
+ # coined term outside code, such as "lane" or "the unit run", and a SKILL.md body over 1,700 words.
12
13
  # Warns on: a SKILL.md body over 1,500 words, a SKILL.md over 500
13
14
  # lines, a reference that SKILL.md does not list under ## References, a reference over 100 lines
14
15
  # 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
@@ -75,6 +76,14 @@ use warnings;
75
76
 
76
77
  my ($errors, $warnings) = (0, 0);
77
78
 
79
+ # Each coined term a skill may not use, with the plain wording that its error names. A term may
80
+ # wrap onto the next line, so a space in it matches any run of white space.
81
+ my @coined_terms = (
82
+ [qr/\blanes?\b/i, "write the command that runs those tests, such as `bun run test:e2e`, or the folder or file suffix that holds them"],
83
+ [qr/(?<![\w-])unit(?:-|\s+)runs?\b/i, "write the command that runs the tests, `bun run test`"],
84
+ [qr/\bunit\s+limit\b/i, "write the timeout and the command it applies to, such as \"the 5 s timeout of `bun run test`\""],
85
+ );
86
+
78
87
  for my $dir (@ARGV) {
79
88
  $dir =~ s{^\./}{};
80
89
  check_skill($dir);
@@ -415,9 +424,26 @@ sub check_markdown {
415
424
  my $headings = 0;
416
425
  my $reference = !$is_skill;
417
426
  my $in_comment = 0;
427
+ my ($open_span, $in_list, $in_indented_code, $after_blank) = ("", 0, 0, 1);
428
+ my ($tail, $tail_line) = ("", 0);
418
429
 
419
430
  for my $line (@lines) {
420
431
  $line_number++;
432
+ if ($open eq "") {
433
+ if ($line =~ /^\s*$/) {
434
+ $after_blank = 1;
435
+ next;
436
+ }
437
+ # Four spaces after a blank line start an indented code block, except inside a list, where
438
+ # they indent the text of the item.
439
+ if ($line =~ /^(?: {4}|\t)/ && !$in_list && ($after_blank || $in_indented_code)) {
440
+ ($in_indented_code, $after_blank) = (1, 0);
441
+ next;
442
+ }
443
+ ($in_indented_code, $after_blank) = (0, 0);
444
+ if ($line =~ /^\s*(?:[-*+]|\d+[.)])\s/) { $in_list = 1 }
445
+ elsif ($line =~ /^\S/) { $in_list = 0 }
446
+ }
421
447
  if ($line =~ /^\s*(`{3,}|~{3,})(.*)$/) {
422
448
  my ($marker, $rest) = ($1, $2);
423
449
  if ($open eq "") { $open = $marker }
@@ -430,7 +456,15 @@ sub check_markdown {
430
456
 
431
457
  # An HTML comment never renders, so its text holds no link and no path.
432
458
  # A comment marker inside inline code renders as text, so the spans hide their markers first.
433
- my $visible = $line =~ s{(`+)(.+?)\1}{my $span = $&; $span =~ s/<!--/<\x{1}!--/g; $span =~ s/-->/--\x{1}>/g; $span}ger;
459
+ # A code span may wrap onto the next line of its paragraph, so a line that only closes it starts
460
+ # after the closing backticks.
461
+ my $source = $line;
462
+ if ($open_span ne "") {
463
+ next unless $source =~ /(?<!`)\Q$open_span\E(?!`)/;
464
+ $source = substr($source, $+[0]);
465
+ $open_span = "";
466
+ }
467
+ my $visible = $source =~ s{(`+)(.+?)\1}{my $span = $&; $span =~ s/<!--/<\x{1}!--/g; $span =~ s/-->/--\x{1}>/g; $span}ger;
434
468
  if ($in_comment) {
435
469
  next unless $visible =~ s/\A.*?-->//;
436
470
  $in_comment = 0;
@@ -442,6 +476,13 @@ sub check_markdown {
442
476
  my $text = $visible;
443
477
  my @spans;
444
478
  $text =~ s/(`+)(.+?)\1/push @spans, $2; ""/ge;
479
+ # A backtick run left open starts a span only when a later line of the paragraph closes it, as
480
+ # CommonMark renders an unclosed run as text.
481
+ my ($unclosed) = $text =~ /(`+)/;
482
+ if (defined $unclosed && has_closing_run($unclosed, @lines[$line_number .. $#lines])) {
483
+ $open_span = $unclosed;
484
+ $text =~ s/`+.*\z//;
485
+ }
445
486
 
446
487
  if ($line_number <= 30) {
447
488
  $contents_links++ while $text =~ /\]\(#[^)\s]+\)/g;
@@ -458,6 +499,27 @@ sub check_markdown {
458
499
  if $target =~ /#L[0-9]+/;
459
500
  }
460
501
 
502
+ # A link target, a reference label, an HTML tag and a URL hold paths and anchors, such as #lanes,
503
+ # that the reader never reads.
504
+ my $prose = $text =~ s/\]\(\s*(?:<[^>]*>|(?:[^()\s]|\([^()\s]*\))*)[^)]*\)/]/gr
505
+ =~ s/\]\[[^\]]*\]/]/gr =~ s/^\s{0,3}\[(?!\^)[^\]]+\]:\s*\S+//r
506
+ =~ s/<\/?[A-Za-z][^>]*>|<[^>\s]*>//gr =~ s{\bhttps?://\S+}{}gr;
507
+ # The last word of the line before joins this one, so a term that wraps is read whole; a term
508
+ # inside that word alone was reported on its own line.
509
+ my $joined = $tail_line == $line_number - 1 && $tail ne "" ? "$tail $prose" : $prose;
510
+ my $start = length($joined) - length($prose);
511
+ my %seen;
512
+ for my $coined (@coined_terms) {
513
+ my ($pattern, $plain) = @$coined;
514
+ while ($joined =~ /$pattern/g) {
515
+ next if $+[0] <= $start;
516
+ my $term = lc($&) =~ s/\s+/ /gr;
517
+ next if $seen{$term}++;
518
+ fail("$file:$line_number", "\"$term\" is a coined term; $plain");
519
+ }
520
+ }
521
+ ($tail, $tail_line) = ($prose =~ /(\S+)\s*\z/ ? $1 : "", $line_number);
522
+
461
523
  # A span inside link text is already a link, so only the spans left after links drop are read.
462
524
  # A table row holds commands the agent types, such as the commands table of a skill, so it is skipped.
463
525
  next if $visible =~ /^\s*\|/;
@@ -478,6 +540,23 @@ sub check_markdown {
478
540
  }
479
541
  }
480
542
 
543
+ # Returns true when a line of the same paragraph holds a backtick run as long as the one given.
544
+ sub has_closing_run {
545
+ my ($run, @rest) = @_;
546
+ for my $line (@rest) {
547
+ return 0 if is_block_start($line);
548
+ return 1 if $line =~ /(?<!`)\Q$run\E(?!`)/;
549
+ }
550
+ return 0;
551
+ }
552
+
553
+ # A blank line, a list item, a heading, a fence, a table row or a block quote ends a paragraph, so a
554
+ # code span never runs past one.
555
+ sub is_block_start {
556
+ my ($line) = @_;
557
+ return $line =~ /^\s*$|^\s*(?:[-*+]|\d+[.)])\s|^\s{0,3}#{1,6}(?:\s|$)|^\s*(?:`{3,}|~{3,})|^\s*[|>]/;
558
+ }
559
+
481
560
  sub resolve_path {
482
561
  my ($file, $path) = @_;
483
562
  return undef if $path eq "";
@@ -28,7 +28,7 @@ export interface WorkflowsCheckOptions {
28
28
  }
29
29
 
30
30
  // GitHub runs no workflow from a subfolder of .github/workflows.
31
- const workflowPathPattern = /^(?:\.github\/workflows|sync\/workflow-callers)\/[^/]+\.ya?ml$/u;
31
+ const workflowPathPattern = /^(?:\.github\/workflows|sync\/src\/workflow-callers)\/[^/]+\.ya?ml$/u;
32
32
 
33
33
  // The check reads the files as HEAD holds them, so a push checks what it sends.
34
34
  export function runWorkflowsCheck(options: Readonly<WorkflowsCheckOptions>): WorkflowFinding[] {