Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the module context rule as it doesn't highlight anything in VS Code #658

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vale/fixtures/RedHat/Headings/testvalid.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
== Eclipse Vert.x and Netty are upgraded in Quarkus
== IBM Cloud
== mTLS authentication
== The mutual TLS authentication scheme
//== The mutual TLS authentication scheme
== Proof Key for Code Exchange
== Kogito updates
== IBM Cloud is a valid product name
//== IBM Cloud is a valid product name
//== Spotify, GraphQL, and Quiltflower are proper nouns so uppercase in headings is OK.
== Redis is an in-memory data structure store that is used by several Red Hat products.
== Repackage the JAR file
Expand Down
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 \":_mod-docs-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 \"_mod-docs-content-type\" variable."
min: 1
token: '(?<!\/\/):_mod-docs-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 := ":_mod-docs-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)
}
Loading