Skip to content

Commit 8ef2cc4

Browse files
committed
Added rule for Lists
1 parent f6406f8 commit 8ef2cc4

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

.vale/fixtures/RedHat/Lists/.vale.ini

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; Vale configuration file to test the `Lists` rule
2+
StylesPath = ../../../styles
3+
MinAlertLevel = suggestion
4+
[*.adoc]
5+
RedHat.Lists = YES
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Remove the cover:
2+
3+
- Loosen the captive screws on the side of the cover.
4+
- Slide the cover toward the back of the computer until the cover clicks
5+
- Lift the cover straight up
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Remove the cover:
2+
3+
* Loosen the captive screws on the side of the cover.
4+
* Slide the cover toward the back of the computer until the cover clicks.
5+
* Lift the cover straight up.

.vale/styles/RedHat/Lists.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
extends: script
3+
message: "Write lists so that all or none of the items start with complete sentences. If list items comprise only complete sentences, include a period after each sentence. Except in definition lists, do not include any end punctuation if list items comprise only sentence fragments."
4+
link: https://tengolang.com/
5+
# The unprocessed file contents.
6+
#
7+
# We need this to access list item markup.
8+
scope: raw
9+
script: |
10+
text := import("text")
11+
matches := []
12+
pattern := "[.*-]\\s+(.*)"
13+
// Define a function to check if a string is a complete sentence
14+
is_complete_sentence := func(s string) bool {
15+
// A complete sentence has a capital letter at the beginning and a period at the end
16+
return text.has_prefix(s, text.to_upper(text.slice(s, 0, 1))) && text.has_suffix(s, ".")
17+
}
18+
// Loop through each line of the document
19+
for line in text.split(document, "\n") {
20+
// Check if the line matches the pattern
21+
match := text.re_find(pattern, line)
22+
if match != undefined {
23+
// Extract the list item from the match
24+
item := match[1]
25+
// Check if the item is a complete sentence
26+
if is_complete_sentence(item) {
27+
// If yes, do nothing
28+
} else {
29+
// If no, add the match to the matches array
30+
start := text.index(scope, line)
31+
matches = append(matches, {begin: start, end: start + len(line)})
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)