From f81e8f3afae82140b945d9987339ea244c2ff1b2 Mon Sep 17 00:00:00 2001 From: "Theo N. Truong" Date: Fri, 28 Feb 2025 19:47:28 -0700 Subject: [PATCH] Remove empty spaces in links when producing text masks for vale. (#825) Signed-off-by: Theo Truong --- tools/src/prepare-for-vale/KeepDescriptions.ts | 14 +++++--------- tools/tests/prepare-for-vale/fixtures/spec.txt | 6 +++--- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index fa5699e58..60415e00d 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -24,7 +24,6 @@ export default class KeepDescriptions { } process(): void { - this.root_folder const files = fg.globSync([`${this.root_folder}/**/*.{yaml,yml}`], { dot: true }) files.forEach((path) => { this.logger.log(path) @@ -38,14 +37,14 @@ export default class KeepDescriptions { var inside_text = false contents.split(/\r?\n/).forEach((line) => { - if (line.match(/^[\s]+((description|x-deprecation-message): \|)/)) { + if (line.match(/^\s+((description|x-deprecation-message): \|)/)) { inside_text = true - } else if (line.match(/^[\s]+((description|x-deprecation-message):)[\s]+/)) { + } else if (line.match(/^\s+((description|x-deprecation-message):)[\s]+/)) { let cleaned_line = this.prune(line, /(description|x-deprecation-message):/, ' ') cleaned_line = this.prune_vars(cleaned_line) cleaned_line = this.remove_links(cleaned_line) fs.writeSync(writer, cleaned_line) - } else if (inside_text && line.match(/^[\s]*[\w\\$]*:/)) { + } else if (inside_text && line.match(/^\s*[\w\\$]*:/)) { inside_text = false } else if (inside_text) { let cleaned_line = this.remove_links(line) @@ -59,7 +58,7 @@ export default class KeepDescriptions { } prune_vars(line: string): string { - return this.prune(line, /([`])(?:(?=(\\?))\2.)*?\1/g, '*') + return this.prune(line, /(`)(?:(?=(\\?))\2.)*?\1/g, '*') } prune(line: string, regex: RegExp, char: string): string { @@ -69,9 +68,6 @@ export default class KeepDescriptions { } remove_links(line: string): string { - return line.replace(/\[([^\]]+)\]\([^)]+\)/g, (match, p1) => { - const spaces = ' '.repeat(match.length - p1.length - 1) - return ' ' + p1 + spaces - }) + return line.replace(/\[([^\]]+)]\([^)]+\)/g, '$1') } } diff --git a/tools/tests/prepare-for-vale/fixtures/spec.txt b/tools/tests/prepare-for-vale/fixtures/spec.txt index 8070b934e..3f29f1c05 100644 --- a/tools/tests/prepare-for-vale/fixtures/spec.txt +++ b/tools/tests/prepare-for-vale/fixtures/spec.txt @@ -9,15 +9,15 @@ - For a successful response, this value is always true. On failure, an exception is returned instead Supported units . + For a successful response, this value is always true. On failure, an exception is returned instead Supported units. - The item level REST category class codes during indexing link with a title . + The item level REST category class codes during indexing link with a title. - Here is link one and link two . + Here is link one and link two. Line two