diff --git a/.vale/fixtures/RedHat/YamlEllipses/testinvalid.adoc b/.vale/fixtures/RedHat/YamlEllipses/testinvalid.adoc index 1948a057..7bddadf2 100644 --- a/.vale/fixtures/RedHat/YamlEllipses/testinvalid.adoc +++ b/.vale/fixtures/RedHat/YamlEllipses/testinvalid.adoc @@ -9,4 +9,5 @@ ---- ... ... ----- \ No newline at end of file + ... +---- diff --git a/.vale/fixtures/RedHat/YamlEllipses/testvalid.adoc b/.vale/fixtures/RedHat/YamlEllipses/testvalid.adoc index 64c67365..e6508464 100644 --- a/.vale/fixtures/RedHat/YamlEllipses/testvalid.adoc +++ b/.vale/fixtures/RedHat/YamlEllipses/testvalid.adoc @@ -1,9 +1,9 @@ [source,yaml] ---- # ... + # ... +# This is an ordinary comment ---- -[source,terminal] ----- ... ----- \ No newline at end of file + diff --git a/.vale/styles/RedHat/YamlEllipses.yml b/.vale/styles/RedHat/YamlEllipses.yml index 28253e5d..41f31336 100644 --- a/.vale/styles/RedHat/YamlEllipses.yml +++ b/.vale/styles/RedHat/YamlEllipses.yml @@ -1,7 +1,7 @@ --- -extends: existence +extends: script level: suggestion -message: "Use '# ...' rather than '...' as ellipsis in YAML code blocks." +message: "Use '# ...' instead of '...' in YAML code blocks." link: https://yaml.org/spec/1.2.2/#22-structures scope: raw script: | @@ -14,18 +14,22 @@ script: | scope += "\n" codeblock_delim_regex := "^-{4,}$" - source_block_regex := "^\\[(source,yaml).*\\]" - ellipses := 0 - reg_ellipsis := "^\\s*\\.\\.\\." + comment_ellipsis := "^# \\.{3}$" + reg_ellipsis := "^\\s*\\.{3}$" + inside_codeblock := false for line in text.split(scope, "\n") { // trim trailing whitespace line = text.trim_space(line) - if text.re_match(source_block_regex, line){ + //ignore content in codeblocks + if text.re_match(codeblock_delim_regex, line) && inside_codeblock == false { + inside_codeblock = true + } else if text.re_match(codeblock_delim_regex, line) && inside_codeblock == true { + inside_codeblock = false + } + if !text.re_match(comment_ellipsis, line) && text.re_match(reg_ellipsis, line) && inside_codeblock == true { start := text.index(scope, line) matches = append(matches, {begin: start, end: start + len(line)}) - } else if text.re_match(reg_ellipsis, line){ - ellipses ++ } } diff --git a/modules/reference-guide/pages/ellipses.adoc b/modules/reference-guide/pages/ellipses.adoc index ad3d863a..9abbc474 100644 --- a/modules/reference-guide/pages/ellipses.adoc +++ b/modules/reference-guide/pages/ellipses.adoc @@ -5,8 +5,12 @@ Avoid ellipsis (...) except to indicate omitted words. +Use a commented out ellipsis (# ...) in YAML code blocks. YAML uses '...' to indicate the end of a document without starting a new one. + .Additional resources * link:{ibmsg-url-print}[{ibmsg-print} - Ellipses, p. 49] * link:{ibmsg-url}?topic=punctuation-ellipses[{ibmsg} - Ellipses] * link:{repository-url}blob/main/.vale/styles/RedHat/Ellipses.yml[`Ellipses.yml` source code] +* link:https://yaml.org/spec/1.2.2/#22-structures[YAML 1.2: Structures] +* link:{repository-url}blob/main/.vale/styles/RedHat/YamlEllipses.yml[`YamlEllipses.yml` source code] diff --git a/tengo-rule-scripts/YamlEllipses.tengo b/tengo-rule-scripts/YamlEllipses.tengo index a5541414..2ab90ccc 100644 --- a/tengo-rule-scripts/YamlEllipses.tengo +++ b/tengo-rule-scripts/YamlEllipses.tengo @@ -17,20 +17,26 @@ scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "") scope += "\n" codeblock_delim_regex := "^-{4,}$" -source_block_regex := "^\\[(yml|yaml).*\\]" +yaml_block_regex := "^\\[(source,yaml).*\\]" ellipses := 0 -reg_ellipsis := "^\\s*\\.\\.\\." +comment_ellipsis := "^# \\.{3}$" +reg_ellipsis := "^\\s*\\.{3}$" +inside_codeblock := false for line in text.split(scope, "\n") { // trim trailing whitespace line = text.trim_space(line) - if text.re_match(source_block_regex, line){ + //ignore content in codeblocks + if text.re_match(codeblock_delim_regex, line) && inside_codeblock == false { + inside_codeblock = true + } else if text.re_match(codeblock_delim_regex, line) && inside_codeblock == true { + inside_codeblock = false + } + if !text.re_match(comment_ellipsis, line) && text.re_match(reg_ellipsis, line) && inside_codeblock == true { start := text.index(scope, line) matches = append(matches, {begin: start, end: start + len(line)}) - } else if text.re_match(reg_ellipsis, line){ - ellipses ++ } } -fmt.println(ellipses) fmt.println(matches) +