From 13c3461f0dac7e5440b89a566824d57eabe615f2 Mon Sep 17 00:00:00 2001 From: Ronan Hennessy Date: Tue, 3 Oct 2023 15:20:46 +0100 Subject: [PATCH] Changing the module context rule as it doesn't highlight anything in VS Code. Using tengo you can highlight first line. --- .../ModuleContainsContentType.yml | 31 +++++++++++++--- .../ModuleContainsContextType.tengo | 36 +++++++++++++++++++ 2 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 tengo-rule-scripts/ModuleContainsContextType.tengo diff --git a/.vale/styles/OpenShiftAsciiDoc/ModuleContainsContentType.yml b/.vale/styles/OpenShiftAsciiDoc/ModuleContainsContentType.yml index d5b8062a8..e9f5e9f05 100644 --- a/.vale/styles/OpenShiftAsciiDoc/ModuleContainsContentType.yml +++ b/.vale/styles/OpenShiftAsciiDoc/ModuleContainsContentType.yml @@ -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: '(? +*/ + +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) + }