feat(docsite): require src= on Go code blocks of module READMEs (quick-261118-qsd)

This commit is contained in:
Jakub Zych
2026-11-18 20:18:38 +01:00
parent 1e56d750ef
commit 8c03cc3621
11 changed files with 43 additions and 40 deletions

View File

@@ -254,7 +254,7 @@ func TestForbiddenChecker(t *testing.T) {
}
func TestFencePolicy(t *testing.T) {
readme := "# fixture\n\nFixture does one thing.\n\n## Usage of `fixture`\n\n```go\nfixture.Run()\n```\n\n> [!TIP]\n> Fine.\n"
readme := "# fixture\n\nFixture does one thing.\n\n## Usage of `fixture`\n\n```text\nfixture.Run()\n```\n\n> [!TIP]\n> Fine.\n"
good := "## Plain heading\n\n> [!NOTE]\n> A note.\n\n> [!WARNING]\n> Careful.\n\n```text\nplain\n```\n\n" +
"```yaml\nkey: value\n```\n\n```md\n> [!DANGER]\n```\n"
assertProblems(t, checkFixture(t, fixtureCommands, map[string]string{
@@ -265,7 +265,7 @@ func TestFencePolicy(t *testing.T) {
bad := good + "\n```go\nfmt.Println()\n```\n\n> [!DANGER]\n> Boom.\n\n## Use `fixture`\n\n## Zażółć\n\n## See [start](setup/start.md)\n"
assertProblems(t, checkFixture(t, fixtureCommands, map[string]string{
"docs/index.md": page("Acme docs", "index", 0, bad),
"modules/fixture/README.md": readme + "\n> [!CAUTION]\n> No.\n",
"modules/fixture/README.md": readme + "\n> [!CAUTION]\n> No.\n\n```go\nfixture.Run()\n```\n",
}), []string{
"docs/index.md:29: snippet: go code block has no src= reference",
"docs/index.md:33: callout: unknown type DANGER (use NOTE, TIP or WARNING)",
@@ -273,6 +273,7 @@ func TestFencePolicy(t *testing.T) {
"docs/index.md:38: heading: headings must be plain ASCII text without links or code",
"docs/index.md:40: heading: headings must be plain ASCII text without links or code",
"modules/fixture/README.md:14: callout: unknown type CAUTION (use NOTE, TIP or WARNING)",
"modules/fixture/README.md:17: snippet: go code block has no src= reference",
})
}
@@ -504,9 +505,9 @@ func TestNestedFenceChecks(t *testing.T) {
"> ```",
"",
}, "\n")
// A module README's src= fences are checked like a docs/ page's: a
// matching body passes, drift, nesting and refused targets are
// reported at the README's own lines.
// A module README's fences are checked like a docs/ page's: a Go
// fence without src= is refused, a matching src= body passes, drift,
// nesting and refused targets are reported at the README's own lines.
readme := strings.Join([]string{
"# fixture",
"",
@@ -561,6 +562,7 @@ func TestNestedFenceChecks(t *testing.T) {
"docs/setup/start.md:24: snippet: main.go code block has no src= reference",
`docs/setup/start.md:34: command: "bogus:nested" is not a summer or application command`,
"docs/setup/start.md:37: snippet: config/app.yaml: " + nestedSrcMessage,
"modules/fixture/README.md:7: snippet: go code block has no src= reference",
"modules/fixture/README.md:16: snippet: body differs from " + hello + " (run: summer docs:sync)",
"modules/fixture/README.md:22: snippet: " + hello + ": " + nestedSrcMessage,
"modules/fixture/README.md:27: snippet: " + hello + ": " + nestedSrcMessage,