Skip to content

Commit 0e470ce

Browse files
committed
update
Signed-off-by: A.Arnold <[email protected]>
1 parent 9060484 commit 0e470ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3487
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
extends: existence
3+
scope: raw
4+
level: error
5+
message: "Attribute block is not closed."
6+
raw:
7+
- '(?<!.)(\[(?!{)[^\]\n]+)\n'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
extends: existence
3+
scope: raw
4+
level: error
5+
message: "Quoted ID value is not closed."
6+
raw:
7+
- '(?<!.)\[id=(["\x27]).*(?<!\1)\]'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
extends: existence
3+
scope: raw
4+
level: warning
5+
link: https://redhat-documentation.github.io/supplementary-style-guide/#cloud-services-images
6+
message: "Image is missing accessibility alt tags."
7+
raw:
8+
- 'image::?.*\[\]'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
extends: existence
3+
scope: raw
4+
level: warning
5+
ignorecase: true
6+
nonword: true
7+
link: https://redhat-documentation.github.io/supplementary-style-guide/#cloud-services-links-hypertext
8+
message: "Link is missing descriptive link text for accessibility."
9+
raw:
10+
- 'link:.*(\[\]|\[click here\]|\[here\]|\[this\])'
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
extends: script
3+
message: "Corresponding callout not found."
4+
level: warning
5+
link: https://docs.asciidoctor.org/asciidoc/latest/verbatim/callouts/
6+
scope: raw
7+
script: |
8+
text := import("text")
9+
matches := []
10+
11+
// clean out multi-line comments
12+
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
13+
//add a newline, it might be missing
14+
scope += "\n"
15+
16+
num_codeblock_callouts := 0
17+
num_callouts := 0
18+
codeblock_callout_regex := ".+<(\\.)>"
19+
callout_regex := "^<(\\.)>"
20+
21+
for line in text.split(scope, "\n") {
22+
// trim trailing whitespace
23+
line = text.trim_space(line)
24+
if text.re_match(codeblock_callout_regex, line) {
25+
//restart for new listingblock
26+
num_callouts = 0
27+
//account for lines with multiple callouts
28+
num_callouts_in_line := text.count(line, "<.>")
29+
if num_callouts_in_line > 1 {
30+
num_codeblock_callouts = num_codeblock_callouts + num_callouts_in_line
31+
} else {
32+
num_codeblock_callouts++
33+
}
34+
}
35+
36+
if text.re_match(callout_regex, line) {
37+
num_callouts++
38+
if num_callouts > num_codeblock_callouts {
39+
start := text.index(scope, line)
40+
matches = append(matches, {begin: start, end: start + len(line)})
41+
}
42+
if num_callouts == num_codeblock_callouts {
43+
num_callouts = 0
44+
num_codeblock_callouts = 0
45+
}
46+
}
47+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
extends: script
3+
message: "Corresponding callout not found."
4+
level: warning
5+
link: https://docs.asciidoctor.org/asciidoc/latest/verbatim/callouts/
6+
scope: raw
7+
script: |
8+
text := import("text")
9+
matches := []
10+
11+
// clean out multi-line comments
12+
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
13+
//add a newline, it might be missing
14+
scope += "\n"
15+
16+
codeblock_callout_regex := ".+(<\\d+>)+"
17+
callout_regex := "^<(\\d+)>"
18+
codeblock_callouts := []
19+
inside := false
20+
found := false
21+
num_callouts := 0
22+
23+
num_lines := len(text.split(scope, "\n"))
24+
25+
for line in text.split(scope, "\n") {
26+
// trim trailing whitespace
27+
line = text.trim_space(line)
28+
if text.re_match(codeblock_callout_regex, line) {
29+
inside = true
30+
//account for lines with multiple callouts
31+
for i := 1; i < num_lines; i++ {
32+
//text.contains must be str, not regex
33+
str := "<" + i + ">"
34+
if text.contains(line, str) {
35+
codeblock_callouts = append(codeblock_callouts, i)
36+
}
37+
}
38+
} else if text.re_match(callout_regex, line) {
39+
inside = false
40+
found = false
41+
num_callouts = 1
42+
for i in codeblock_callouts {
43+
//cast int > string
44+
j := text.itoa(i)
45+
str := "<" + j + ">"
46+
if text.contains(line, str) {
47+
//setting found allows us to loop through the list of possible matches
48+
found = true
49+
}
50+
num_callouts++
51+
}
52+
if !found {
53+
start := text.index(scope, line)
54+
matches = append(matches, {begin: start, end: start + len(line)})
55+
}
56+
} else if codeblock_callouts && inside == false {
57+
//cycled through num_callouts, reset for next codeblock
58+
if num_callouts == len(codeblock_callouts) {
59+
codeblock_callouts = []
60+
}
61+
}
62+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
extends: script
3+
message: "Numbered callout does not follow sequentially."
4+
level: warning
5+
link: https://docs.asciidoctor.org/asciidoc/latest/verbatim/callouts/
6+
scope: raw
7+
script: |
8+
text := import("text")
9+
matches := []
10+
11+
// clean out multi-line comments
12+
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
13+
//add a newline, it might be missing
14+
scope += "\n"
15+
16+
prev_num := 0
17+
callout_regex := "^<(\\d+)>"
18+
listingblock_delim_regex := "^-{4,}$"
19+
if_regex := "^ifdef::|ifndef::"
20+
endif_regex := "^endif::\\[\\]"
21+
inside_if := false
22+
23+
for line in text.split(scope, "\n") {
24+
// trim trailing whitespace
25+
line = text.trim_space(line)
26+
27+
// check if we're entering a conditional block
28+
if text.re_match(if_regex, line) {
29+
inside_if = true
30+
} else if text.re_match(endif_regex, line) {
31+
inside_if = false
32+
}
33+
34+
//reset count if we hit a listing block delimiter
35+
if text.re_match(listingblock_delim_regex, line) {
36+
prev_num = 0
37+
}
38+
39+
//only count callouts where there are no ifdefs
40+
if !inside_if {
41+
if text.re_match(callout_regex, line) {
42+
callout := text.re_find("<(\\d+)>", line)
43+
for key, value in callout {
44+
//trim angle brackets from string
45+
trimmed := callout[key][0]["text"]
46+
trimmed = text.trim_prefix(trimmed, "<")
47+
trimmed = text.trim_suffix(trimmed, ">")
48+
//cast string > int
49+
num := text.atoi(trimmed)
50+
//start counting
51+
if num != prev_num+1 {
52+
start := text.index(scope, line)
53+
matches = append(matches, {begin: start, end: start + len(line)})
54+
}
55+
prev_num = num
56+
}
57+
}
58+
}
59+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
extends: script
3+
level: suggestion
4+
message: "Set attribute directive does not have a corresponding unset attribute directive."
5+
link: https://docs.asciidoctor.org/asciidoc/latest/attributes/unset-attributes/#unset-a-document-attribute-in-the-body
6+
scope: raw
7+
script: |
8+
text := import("text")
9+
matches := []
10+
11+
// trim extra whitespace
12+
scope = text.trim_space(scope)
13+
// add a newline, it might be missing
14+
scope += "\n"
15+
// clean out multi-line comments
16+
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
17+
18+
attr_regex := "^:[\\w-_]+:.*$"
19+
context_mod_docs_regex := "^:context|_content-type|_mod-docs-content-type:.*$"
20+
attr_name_regex := ":[\\w-_]+:"
21+
attr_name := ""
22+
unset_attr_pref := ""
23+
unset_attr_suff := ""
24+
25+
for line in text.split(scope, "\n") {
26+
if text.re_match(attr_regex, line) {
27+
if !text.re_match(context_mod_docs_regex, line) {
28+
start := text.index(scope, line)
29+
matches = append(matches, {begin: start, end: start + len(line)})
30+
// re_find returns an array holding all matches
31+
attr_name = ((text.re_find(attr_name_regex, line))[0][0])["text"]
32+
unset_attr_pref = `^:!` + text.trim_prefix(attr_name, `:`)
33+
unset_attr_suff = `^` + text.trim_suffix(attr_name, `:`) + `!:`
34+
// loop through lines for every attr found
35+
for line in text.split(scope, "\n") {
36+
if text.re_match(unset_attr_pref, line) {
37+
if len(matches) > 0 {
38+
// remove the most recently added match
39+
matches = matches[:len(matches)-1]
40+
} else if text.re_match(unset_attr_suff, line) {
41+
if len(matches) > 0 {
42+
matches = matches[:len(matches)-1]
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
extends: script
3+
level: error
4+
message: "Unterminated admonition block found in file."
5+
link: https://docs.asciidoctor.org/asciidoc/latest/blocks/admonitions/
6+
scope: raw
7+
script: |
8+
text := import("text")
9+
matches := []
10+
11+
// clean out multi-line comments
12+
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
13+
//add a newline, it might be missing
14+
scope += "\n"
15+
16+
admon_delim_regex := "^={4}$"
17+
count := 0
18+
19+
for line in text.split(scope, "\n") {
20+
// trim trailing whitespace
21+
line = text.trim_space(line)
22+
if text.re_match(admon_delim_regex, line) {
23+
count += 1
24+
start := text.index(scope, line)
25+
matches = append(matches, {begin: start, end: start + len(line)})
26+
} else if count > 1 {
27+
count = 0 // admonition block is closed, reset the count
28+
matches = []
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
extends: script
3+
level: error
4+
message: "Unterminated listing block found in file."
5+
link: https://docs.asciidoctor.org/asciidoc/latest/verbatim/listing-blocks/
6+
scope: raw
7+
script: |
8+
text := import("text")
9+
matches := []
10+
11+
// clean out multi-line comments
12+
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
13+
//add a newline, it might be missing
14+
scope += "\n"
15+
16+
listingblock_delim_regex := "^-{4}$"
17+
count := 0
18+
19+
for line in text.split(scope, "\n") {
20+
// trim trailing whitespace
21+
line = text.trim_space(line)
22+
if text.re_match(listingblock_delim_regex, line) {
23+
count += 1
24+
start := text.index(scope, line)
25+
matches = append(matches, {begin: start, end: start + len(line)})
26+
} else if count > 1 {
27+
count = 0 // listing block is closed, reset the count
28+
matches = []
29+
}
30+
}

0 commit comments

Comments
 (0)