Skip to content

Commit

Permalink
Continue Vale GH action setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
wmat committed Nov 15, 2024
1 parent 0db30a7 commit 2957750
Show file tree
Hide file tree
Showing 55 changed files with 3,504 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/.vale.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
StylesPath = .github/styles
MinAlertLevel = suggestion

Packages = RedHat, AsciiDoc

# Ignore files in dirs starting with `.` to avoid raising errors for `.vale/fixtures/*/testinvalid.adoc` files
[[!.]*.adoc]
BasedOnStyles = RedHat, AsciiDoc
7 changes: 7 additions & 0 deletions .github/styles/AsciiDoc/ClosedAttributeBlocks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
extends: existence
scope: raw
level: error
message: "Attribute block is not closed."
raw:
- '(?<!.)(\[(?!{)[^\]\n]+)\n'
7 changes: 7 additions & 0 deletions .github/styles/AsciiDoc/ClosedIdQuotes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
extends: existence
scope: raw
level: error
message: "Quoted ID value is not closed."
raw:
- '(?<!.)\[id=(["\x27]).*(?<!\1)\]'
8 changes: 8 additions & 0 deletions .github/styles/AsciiDoc/ImageContainsAltText.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
extends: existence
scope: raw
level: warning
link: https://redhat-documentation.github.io/supplementary-style-guide/#cloud-services-images
message: "Image is missing accessibility alt tags."
raw:
- 'image::?.*\[\]'
10 changes: 10 additions & 0 deletions .github/styles/AsciiDoc/LinkContainsLinkText.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
extends: existence
scope: raw
level: warning
ignorecase: true
nonword: true
link: https://redhat-documentation.github.io/supplementary-style-guide/#cloud-services-links-hypertext
message: "Link is missing descriptive link text for accessibility."
raw:
- 'link:.*(\[\]|\[click here\]|\[here\]|\[this\])'
47 changes: 47 additions & 0 deletions .github/styles/AsciiDoc/MatchingDotCallouts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
extends: script
message: "Corresponding callout not found."
level: warning
link: https://docs.asciidoctor.org/asciidoc/latest/verbatim/callouts/
scope: raw
script: |
text := import("text")
matches := []
// clean out multi-line comments
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
//add a newline, it might be missing
scope += "\n"
num_codeblock_callouts := 0
num_callouts := 0
codeblock_callout_regex := ".+<(\\.)>"
callout_regex := "^<(\\.)>"
for line in text.split(scope, "\n") {
// trim trailing whitespace
line = text.trim_space(line)
if text.re_match(codeblock_callout_regex, line) {
//restart for new listingblock
num_callouts = 0
//account for lines with multiple callouts
num_callouts_in_line := text.count(line, "<.>")
if num_callouts_in_line > 1 {
num_codeblock_callouts = num_codeblock_callouts + num_callouts_in_line
} else {
num_codeblock_callouts++
}
}
if text.re_match(callout_regex, line) {
num_callouts++
if num_callouts > num_codeblock_callouts {
start := text.index(scope, line)
matches = append(matches, {begin: start, end: start + len(line)})
}
if num_callouts == num_codeblock_callouts {
num_callouts = 0
num_codeblock_callouts = 0
}
}
}
62 changes: 62 additions & 0 deletions .github/styles/AsciiDoc/MatchingNumberedCallouts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
extends: script
message: "Corresponding callout not found."
level: warning
link: https://docs.asciidoctor.org/asciidoc/latest/verbatim/callouts/
scope: raw
script: |
text := import("text")
matches := []
// clean out multi-line comments
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
//add a newline, it might be missing
scope += "\n"
codeblock_callout_regex := ".+(<\\d+>)+"
callout_regex := "^<(\\d+)>"
codeblock_callouts := []
inside := false
found := false
num_callouts := 0
num_lines := len(text.split(scope, "\n"))
for line in text.split(scope, "\n") {
// trim trailing whitespace
line = text.trim_space(line)
if text.re_match(codeblock_callout_regex, line) {
inside = true
//account for lines with multiple callouts
for i := 1; i < num_lines; i++ {
//text.contains must be str, not regex
str := "<" + i + ">"
if text.contains(line, str) {
codeblock_callouts = append(codeblock_callouts, i)
}
}
} else if text.re_match(callout_regex, line) {
inside = false
found = false
num_callouts = 1
for i in codeblock_callouts {
//cast int > string
j := text.itoa(i)
str := "<" + j + ">"
if text.contains(line, str) {
//setting found allows us to loop through the list of possible matches
found = true
}
num_callouts++
}
if !found {
start := text.index(scope, line)
matches = append(matches, {begin: start, end: start + len(line)})
}
} else if codeblock_callouts && inside == false {
//cycled through num_callouts, reset for next codeblock
if num_callouts == len(codeblock_callouts) {
codeblock_callouts = []
}
}
}
59 changes: 59 additions & 0 deletions .github/styles/AsciiDoc/SequentialNumberedCallouts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
extends: script
message: "Numbered callout does not follow sequentially."
level: warning
link: https://docs.asciidoctor.org/asciidoc/latest/verbatim/callouts/
scope: raw
script: |
text := import("text")
matches := []
// clean out multi-line comments
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
//add a newline, it might be missing
scope += "\n"
prev_num := 0
callout_regex := "^<(\\d+)>"
listingblock_delim_regex := "^-{4,}$"
if_regex := "^ifdef::|ifndef::"
endif_regex := "^endif::\\[\\]"
inside_if := false
for line in text.split(scope, "\n") {
// trim trailing whitespace
line = text.trim_space(line)
// check if we're entering a conditional block
if text.re_match(if_regex, line) {
inside_if = true
} else if text.re_match(endif_regex, line) {
inside_if = false
}
//reset count if we hit a listing block delimiter
if text.re_match(listingblock_delim_regex, line) {
prev_num = 0
}
//only count callouts where there are no ifdefs
if !inside_if {
if text.re_match(callout_regex, line) {
callout := text.re_find("<(\\d+)>", line)
for key, value in callout {
//trim angle brackets from string
trimmed := callout[key][0]["text"]
trimmed = text.trim_prefix(trimmed, "<")
trimmed = text.trim_suffix(trimmed, ">")
//cast string > int
num := text.atoi(trimmed)
//start counting
if num != prev_num+1 {
start := text.index(scope, line)
matches = append(matches, {begin: start, end: start + len(line)})
}
prev_num = num
}
}
}
}
49 changes: 49 additions & 0 deletions .github/styles/AsciiDoc/UnsetAttributes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
extends: script
level: warning
message: "Set attribute directive does not have a corresponding unset attribute directive."
link: https://docs.asciidoctor.org/asciidoc/latest/attributes/unset-attributes/#unset-a-document-attribute-in-the-body
scope: raw
script: |
text := import("text")
matches := []
// trim extra whitespace
scope = text.trim_space(scope)
// add a newline, it might be missing
scope += "\n"
// clean out multi-line comments
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
attr_regex := "^:[\\w-_]+:.*$"
context_mod_docs_regex := "^:context|_content-type|_mod-docs-content-type:.*$"
attr_name_regex := ":[\\w-_]+:"
attr_name := ""
unset_attr_pref := ""
unset_attr_suff := ""
for line in text.split(scope, "\n") {
if text.re_match(attr_regex, line) {
if !text.re_match(context_mod_docs_regex, line) {
start := text.index(scope, line)
matches = append(matches, {begin: start, end: start + len(line)})
// re_find returns an array holding all matches
attr_name = ((text.re_find(attr_name_regex, line))[0][0])["text"]
unset_attr_pref = `^:!` + text.trim_prefix(attr_name, `:`)
unset_attr_suff = `^` + text.trim_suffix(attr_name, `:`) + `!:`
// loop through lines for every attr found
for line in text.split(scope, "\n") {
if text.re_match(unset_attr_pref, line) {
if len(matches) > 0 {
// remove the most recently added match
matches = matches[:len(matches)-1]
} else if text.re_match(unset_attr_suff, line) {
if len(matches) > 0 {
matches = matches[:len(matches)-1]
}
}
}
}
}
}
}
30 changes: 30 additions & 0 deletions .github/styles/AsciiDoc/ValidAdmonitionBlocks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
extends: script
level: error
message: "Unterminated admonition block found in file."
link: https://docs.asciidoctor.org/asciidoc/latest/blocks/admonitions/
scope: raw
script: |
text := import("text")
matches := []
// clean out multi-line comments
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
//add a newline, it might be missing
scope += "\n"
admon_delim_regex := "^={4}$"
count := 0
for line in text.split(scope, "\n") {
// trim trailing whitespace
line = text.trim_space(line)
if text.re_match(admon_delim_regex, line) {
count += 1
start := text.index(scope, line)
matches = append(matches, {begin: start, end: start + len(line)})
} else if count > 1 {
count = 0 // admonition block is closed, reset the count
matches = []
}
}
30 changes: 30 additions & 0 deletions .github/styles/AsciiDoc/ValidCodeBlocks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
extends: script
level: error
message: "Unterminated listing block found in file."
link: https://docs.asciidoctor.org/asciidoc/latest/verbatim/listing-blocks/
scope: raw
script: |
text := import("text")
matches := []
// clean out multi-line comments
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
//add a newline, it might be missing
scope += "\n"
listingblock_delim_regex := "^-{4}$"
count := 0
for line in text.split(scope, "\n") {
// trim trailing whitespace
line = text.trim_space(line)
if text.re_match(listingblock_delim_regex, line) {
count += 1
start := text.index(scope, line)
matches = append(matches, {begin: start, end: start + len(line)})
} else if count > 1 {
count = 0 // listing block is closed, reset the count
matches = []
}
}
37 changes: 37 additions & 0 deletions .github/styles/AsciiDoc/ValidConditions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
extends: script
level: error
message: "File contains unbalanced if statements. Review the file to ensure it contains matching opening and closing if statements."
link: https://docs.asciidoctor.org/asciidoc/latest/directives/ifdef-ifndef/
scope: raw
script: |
text := import("text")
matches := []
// clean out multi-line comments
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
//add a newline, it might be missing
scope += "\n"
if_regex := "^ifdef::.+\\[\\]"
ifn_regex := "^ifndef::.+\\[\\]"
ifeval_regex := "ifeval::\\[.+\\]"
endif_regex := "^endif::.*\\[\\]"
for line in text.split(scope, "\n") {
// trim trailing whitespace
line = text.trim_space(line)
if text.re_match(if_regex, line) || text.re_match(ifn_regex, line) || text.re_match(ifeval_regex, line) {
start := text.index(scope, line)
matches = append(matches, {begin: start, end: start + len(line)})
} else if text.re_match(endif_regex, line) {
if len(matches) > 0 {
//remove the most recently added open ifdef match
matches = matches[:len(matches)-1]
} else if len(matches) == 0 {
//add orphan endif::[] statements
start := text.index(scope, line)
matches = append(matches, {begin: start, end: start + len(line)})
}
}
}
30 changes: 30 additions & 0 deletions .github/styles/AsciiDoc/ValidTableBlocks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
extends: script
level: error
message: "Unterminated table block found in file."
link: https://docs.asciidoctor.org/asciidoc/latest/tables/build-a-basic-table/
scope: raw
script: |
text := import("text")
matches := []
// clean out multi-line comments
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
//add a newline, it might be missing
scope += "\n"
tbl_delim_regex := "^\\|={3,}$"
count := 0
for line in text.split(scope, "\n") {
// trim trailing whitespace
line = text.trim_space(line)
if text.re_match(tbl_delim_regex, line) {
count += 1
start := text.index(scope, line)
matches = append(matches, {begin: start, end: start + len(line)})
} else if count > 1 {
count = 0 //code block is closed, reset the count
matches = []
}
}
Loading

0 comments on commit 2957750

Please sign in to comment.