Skip to content

Commit

Permalink
Added rule for Lists
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav-nelson committed Jan 9, 2024
1 parent f6406f8 commit f40b36a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .vale/fixtures/RedHat/Lists/.vale.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
; Vale configuration file to test the `Lists` rule
StylesPath = ../../../styles
MinAlertLevel = suggestion
[*.adoc]
RedHat.Lists = YES
5 changes: 5 additions & 0 deletions .vale/fixtures/RedHat/Lists/testinvalid.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Remove the cover:

- Loosen the captive screws on the side of the cover.
- Slide the cover toward the back of the computer until the cover clicks
- Lift the cover straight up
5 changes: 5 additions & 0 deletions .vale/fixtures/RedHat/Lists/testvalid.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Remove the cover:

* Loosen the captive screws on the side of the cover.
* Slide the cover toward the back of the computer until the cover clicks.
* Lift the cover straight up.
22 changes: 22 additions & 0 deletions .vale/styles/RedHat/Lists.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
extends: script
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."
scope: raw
script: |
text := import("text")
matches := []
pattern := "[.*-]\\s+(.*)"
is_complete_sentence := func(s string) bool {
return text.has_prefix(s, text.to_upper(text.slice(s, 0, 1))) && text.has_suffix(s, ".")
}
for line in text.split(document, "\n") {
match := text.re_find(pattern, line)
if match != undefined {
item := match[1]
if is_complete_sentence(item) {
} else {
start := text.index(scope, line)
matches = append(matches, {begin: start, end: start + len(line)})
}
}
}

0 comments on commit f40b36a

Please sign in to comment.