Skip to content

Commit

Permalink
Require an introductory paragraph in docs pages
Browse files Browse the repository at this point in the history
Add a vale rule that requires there to be a paragraph between the second
frontmatter document separator (`---`) and the first H2-level heading of
a docs page. Introductory paragraphs are common omissions in docs pages,
but are important to help readers determine whether a guide is
appropriate for their use case.
  • Loading branch information
ptgott committed Jun 18, 2024
1 parent 899f12a commit 4e5f3e2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/vale-styles/structure/intro-paragraph.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This style enforces the presence of an introductory paragraph before the first
# H2 of a docs page.
extends: script
level: error
message: There must be a brief intro paragraph before the first H2-level section of a docs page. Use this to describe the purpose of the guide so a reader can determine whether they should continue reading. If there is an "Introduction" H2, remove the heading.
scope: raw
script: |
text := import("text")
getMatches := func() {
docSeparators := text.re_find(`\n?---\n`, scope, 2)
// This is probably not a valid MDX file, but let other linters handler the
// error.
if docSeparators == undefined || len(docSeparators) != 2 {
return []
}
// Get the first H2 section
firstH2 := text.re_find(`\n## \w`, scope, 1)
if firstH2 == undefined {
return []
}
initialText := text.substr(scope, docSeparators[1][0].end,firstH2[0][0].begin)
// Check for at least one non-empty line before the first H2.
if !text.re_match(`\n[^\n]+\n`, initialText) {
return [{
begin: docSeparators[1][0].end,
end: firstH2[0][0].begin
}]
}
}
matches := getMatches()

0 comments on commit 4e5f3e2

Please sign in to comment.