Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require an introductory paragraph in docs pages #43222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/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 the guide introduces a feature, describe the purpose and benefits of the feature. If there is already an "Introduction" H2 or similar, 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()
Loading