Skip to content

Commit

Permalink
Fix conditions rule for single line ifdefs
Browse files Browse the repository at this point in the history
  • Loading branch information
aireilly committed Oct 2, 2024
1 parent 800a614 commit 2ba1d93
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .vale/fixtures/AsciiDoc/ValidConditions/testvalid.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ endif::[]
ifeval::["{docname}{outfilesuffix}" == "main.html"]
Some text!
endif::[]

//vale-fixture
ifndef::olmv1-pullsecret-proc[For more information, see "Creating a pull secret for catalogs hosted on a secure registry".]
8 changes: 5 additions & 3 deletions .vale/styles/AsciiDoc/ValidConditions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ script: |
//add a newline, it might be missing
scope += "\n"
if_regex := "^(ifdef::.+\\[\\]|ifndef::.+\\[\\]|ifeval::.*)"
endif_regex := "^endif::.*"
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) {
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) {
Expand Down
8 changes: 5 additions & 3 deletions tengo-rule-scripts/ValidConditions.tengo
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
//add a newline, it might be missing
scope += "\n"

if_regex := "^(ifdef::.+\\[\\]|ifndef::.+\\[\\]|ifeval::.*)"
endif_regex := "^endif::.*"
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) {
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) {
Expand Down

0 comments on commit 2ba1d93

Please sign in to comment.