Skip to content

Commit

Permalink
Changing the module context rule as it doesn't highlight anything in …
Browse files Browse the repository at this point in the history
…VS Code. Using tengo you can highlight first line.
  • Loading branch information
rohennes committed Oct 13, 2023
1 parent c378f60 commit 191fc5a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
31 changes: 26 additions & 5 deletions .vale/styles/OpenShiftAsciiDoc/ModuleContainsContentType.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
---
extends: occurrence
scope: raw
extends: script
message: "Module is missing the \"_content-type\" variable."
level: error
link: https://github.com/openshift/openshift-docs/blob/main/contributing_to_docs/doc_guidelines.adoc#module-file-metadata
message: "Module is missing the \"_content-type\" variable."
min: 1
token: '(?<!\/\/):_content-type:(\s)?(CONCEPT|PROCEDURE|REFERENCE|ASSEMBLY|SNIPPET)'
scope: raw
script: |
text := import("text")
matches := []
//trim extra whitespace
scope = text.trim_space(scope)
//add a newline, it might be missing
scope += "\n"
context_regex := ":_content-type: (CONCEPT|SNIPPET|ASSEMBLY|PROCEDURE|REFERENCE)"
match := false
//Check if context declaration is on any line
for line in text.split(scope, "\n") {
if text.re_match(context_regex, line){
match = true
}
}
//Highlight first line if context declaration not found in file
if match == false {
matches = append(matches, {begin: 1, end: 10})
}
36 changes: 36 additions & 0 deletions tengo-rule-scripts/ModuleContainsContextType.tengo
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Tengo Language
Checks that lines are not hard-wrapped.
$ tengo HardWrappedLines.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"

context_regex := ":_content-type: (CONCEPT|SNIPPET|ASSEMBLY|PROCEDURE|REFERENCE)"
match := false

//Check if context declaration is on any line
for line in text.split(scope, "\n") {
if text.re_match(context_regex, line){
match = true
fmt.println("Found content-type declaration")
}
}

//Highlight first line if context declaration not found in file
if match == false {
matches = append(matches, {begin: 1, end: 10})
fmt.println("Did not find content-type declaration")
fmt.println(matches)
}

0 comments on commit 191fc5a

Please sign in to comment.