From f40b36af1648c89c848d0b81941b821562213039 Mon Sep 17 00:00:00 2001 From: Gaurav Nelson Date: Thu, 9 Nov 2023 12:55:03 +1000 Subject: [PATCH] Added rule for Lists --- .vale/fixtures/RedHat/Lists/.vale.ini | 5 +++++ .vale/fixtures/RedHat/Lists/testinvalid.adoc | 5 +++++ .vale/fixtures/RedHat/Lists/testvalid.adoc | 5 +++++ .vale/styles/RedHat/Lists.yml | 22 ++++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 .vale/fixtures/RedHat/Lists/.vale.ini create mode 100644 .vale/fixtures/RedHat/Lists/testinvalid.adoc create mode 100644 .vale/fixtures/RedHat/Lists/testvalid.adoc create mode 100644 .vale/styles/RedHat/Lists.yml diff --git a/.vale/fixtures/RedHat/Lists/.vale.ini b/.vale/fixtures/RedHat/Lists/.vale.ini new file mode 100644 index 000000000..cc3030b28 --- /dev/null +++ b/.vale/fixtures/RedHat/Lists/.vale.ini @@ -0,0 +1,5 @@ +; Vale configuration file to test the `Lists` rule +StylesPath = ../../../styles +MinAlertLevel = suggestion +[*.adoc] +RedHat.Lists = YES diff --git a/.vale/fixtures/RedHat/Lists/testinvalid.adoc b/.vale/fixtures/RedHat/Lists/testinvalid.adoc new file mode 100644 index 000000000..661ac69a8 --- /dev/null +++ b/.vale/fixtures/RedHat/Lists/testinvalid.adoc @@ -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 diff --git a/.vale/fixtures/RedHat/Lists/testvalid.adoc b/.vale/fixtures/RedHat/Lists/testvalid.adoc new file mode 100644 index 000000000..e2749643d --- /dev/null +++ b/.vale/fixtures/RedHat/Lists/testvalid.adoc @@ -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. diff --git a/.vale/styles/RedHat/Lists.yml b/.vale/styles/RedHat/Lists.yml new file mode 100644 index 000000000..d382c3e3f --- /dev/null +++ b/.vale/styles/RedHat/Lists.yml @@ -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)}) + } + } + }