Skip to content

Commit 9da4b3b

Browse files
authored
Merge pull request #891 from aireilly/fix-ifdef-rule
Fix conditions rule for single line ifdefs
2 parents 76046e0 + 2ba1d93 commit 9da4b3b

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

.vale/fixtures/AsciiDoc/ValidConditions/testvalid.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ endif::[]
4040
ifeval::["{docname}{outfilesuffix}" == "main.html"]
4141
Some text!
4242
endif::[]
43+
44+
//vale-fixture
45+
ifndef::olmv1-pullsecret-proc[For more information, see "Creating a pull secret for catalogs hosted on a secure registry".]

.vale/styles/AsciiDoc/ValidConditions.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ script: |
1313
//add a newline, it might be missing
1414
scope += "\n"
1515
16-
if_regex := "^(ifdef::.+\\[\\]|ifndef::.+\\[\\]|ifeval::.*)"
17-
endif_regex := "^endif::.*"
16+
if_regex := "^ifdef::.+\\[\\]"
17+
ifn_regex := "^ifndef::.+\\[\\]"
18+
ifeval_regex := "ifeval::\\[.+\\]"
19+
endif_regex := "^endif::.*\\[\\]"
1820
1921
for line in text.split(scope, "\n") {
2022
// trim trailing whitespace
2123
line = text.trim_space(line)
22-
if text.re_match(if_regex, line) {
24+
if text.re_match(if_regex, line) || text.re_match(ifn_regex, line) || text.re_match(ifeval_regex, line) {
2325
start := text.index(scope, line)
2426
matches = append(matches, {begin: start, end: start + len(line)})
2527
} else if text.re_match(endif_regex, line) {

tengo-rule-scripts/ValidConditions.tengo

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
1616
//add a newline, it might be missing
1717
scope += "\n"
1818

19-
if_regex := "^(ifdef::.+\\[\\]|ifndef::.+\\[\\]|ifeval::.*)"
20-
endif_regex := "^endif::.*"
19+
if_regex := "^ifdef::.+\\[\\]"
20+
ifn_regex := "^ifndef::.+\\[\\]"
21+
ifeval_regex := "ifeval::\\[.+\\]"
22+
endif_regex := "^endif::.*\\[\\]"
2123

2224
for line in text.split(scope, "\n") {
2325
// trim trailing whitespace
2426
line = text.trim_space(line)
25-
if text.re_match(if_regex, line) {
27+
if text.re_match(if_regex, line) || text.re_match(ifn_regex, line) || text.re_match(ifeval_regex, line) {
2628
start := text.index(scope, line)
2729
matches = append(matches, {begin: start, end: start + len(line)})
2830
} else if text.re_match(endif_regex, line) {

0 commit comments

Comments
 (0)