-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
; Vale configuration file to test the `UnsetAttributes` rule | ||
StylesPath = ../../../styles | ||
MinAlertLevel = error | ||
[*.adoc] | ||
AsciiDoc.UnsetAttributes = YES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
:context: creating-infrastructure-machinesets | ||
|
||
ifeval::["{context}" == "creating-infrastructure-machinesets"] | ||
:infra: | ||
endif::[] | ||
|
||
Vale reports lots of errors, it should also report an attribute that you forgot to unset | ||
|
||
//// | ||
Ignore multi-line comments | ||
:!infra: | ||
//// | ||
|
||
//ignore comments | ||
//:!infra: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
:context: creating-infrastructure-machinesets | ||
|
||
ifeval::["{context}" == "creating-infrastructure-machinesets"] | ||
//vale-fixture | ||
:infra: | ||
endif::[] | ||
|
||
Vale reports lots of errors, it should also report an attribute that you forgot to unset | ||
|
||
ifeval::["{context}" == "creating-infrastructure-machinesets"] | ||
//vale-fixture | ||
:!infra: | ||
endif::[] | ||
|
||
//This is really just unsetting a second time, but it should not trip the rule | ||
ifeval::["{context}" == "creating-infrastructure"] | ||
//vale-fixture | ||
:infra!: | ||
endif::[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
extends: script | ||
level: error | ||
message: "Set attribute has not been unset in the current file." | ||
link: https://docs.asciidoctor.org/asciidoc/latest/attributes/unset-attributes/#unset-a-document-attribute-in-the-header | ||
scope: raw | ||
script: | | ||
text := import("text") | ||
matches := [] | ||
// trim extra whitespace | ||
scope = text.trim_space(scope) | ||
// add a newline, it might be missing | ||
scope += "\n" | ||
// clean out multi-line comments | ||
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "") | ||
attr_regex := "^:[\\w-]+:$" | ||
unset_attr_pref := "" | ||
unset_attr_suff := "" | ||
for line in text.split(scope, "\n") { | ||
if text.re_match(attr_regex, line) { | ||
start := text.index(scope, line) | ||
matches = append(matches, {begin: start, end: start + len(line)}) | ||
unset_attr_pref = `^:!` + text.trim_prefix(line, `:`) | ||
unset_attr_suff = `^` + text.trim_suffix(line, `:`) + `!:` | ||
// loop through lines for every attr found | ||
for line in text.split(scope, "\n") { | ||
if text.re_match(unset_attr_pref, line) { | ||
if len(matches) > 0 { | ||
// remove the most recently added match | ||
matches = matches[:len(matches)-1] | ||
} else if text.re_match(unset_attr_suff, line) { | ||
if len(matches) > 0 { | ||
matches = matches[:len(matches)-1] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Tengo Language | ||
$ tengo UnsetAttributes.tengo <asciidoc_file_to_validate> | ||
*/ | ||
|
||
fmt := import("fmt") | ||
os := import("os") | ||
text := import("text") | ||
|
||
input := os.args() | ||
scope := os.read_file(input[2]) | ||
matches := [] | ||
|
||
// trim extra whitespace | ||
scope = text.trim_space(scope) | ||
// add a newline, it might be missing | ||
scope += "\n" | ||
// clean out multi-line comments | ||
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "") | ||
|
||
attr_regex := "^:[\\w-]+:$" | ||
unset_attr_pref := "" | ||
unset_attr_suff := "" | ||
|
||
for line in text.split(scope, "\n") { | ||
if text.re_match(attr_regex, line) { | ||
start := text.index(scope, line) | ||
matches = append(matches, {begin: start, end: start + len(line)}) | ||
unset_attr_pref = `^:!` + text.trim_prefix(line, `:`) | ||
unset_attr_suff = `^` + text.trim_suffix(line, `:`) + `!:` | ||
// loop through lines for every attr found | ||
for line in text.split(scope, "\n") { | ||
if text.re_match(unset_attr_pref, line) { | ||
if len(matches) > 0 { | ||
// remove the most recently added match | ||
matches = matches[:len(matches)-1] | ||
} else if text.re_match(unset_attr_suff, line) { | ||
if len(matches) > 0 { | ||
matches = matches[:len(matches)-1] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if len(matches) == 0 { | ||
fmt.println("Attributes are unset properly") | ||
} else { | ||
fmt.println(matches) | ||
} |