From 8dbe982f5287ab799ffc704c3929ca7ec5ea8961 Mon Sep 17 00:00:00 2001 From: dblock Date: Tue, 19 Nov 2024 13:59:19 -0500 Subject: [PATCH 1/2] Fix: capture lines. Signed-off-by: dblock --- tools/src/prepare-for-vale/KeepDescriptions.ts | 2 +- tools/tests/prepare-for-vale/fixtures/spec.txt | 5 +++++ tools/tests/prepare-for-vale/fixtures/spec.yaml | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index f3f7149cb..3922df1e2 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -43,7 +43,7 @@ export default class KeepDescriptions { inside_description = true } else if (line.match(/^[\s]+(description:)[\s]+/)) { fs.writeSync(writer, this.prune(line).replace("description:", " ")) - } else if (inside_description && line.match(/^[\s]*[\w]*:/)) { + } else if (inside_description && line.match(/^[\s]*[\w\\$]*:/)) { inside_description = false } else if (inside_description) { fs.writeSync(writer, this.prune(line)) diff --git a/tools/tests/prepare-for-vale/fixtures/spec.txt b/tools/tests/prepare-for-vale/fixtures/spec.txt index 55fb7ab28..13f1140d2 100644 --- a/tools/tests/prepare-for-vale/fixtures/spec.txt +++ b/tools/tests/prepare-for-vale/fixtures/spec.txt @@ -30,3 +30,8 @@ Line one Line with backticks: that includes *******. Line with two backticks: that includes ******* and *******. + + + + Line one. + diff --git a/tools/tests/prepare-for-vale/fixtures/spec.yaml b/tools/tests/prepare-for-vale/fixtures/spec.yaml index 09b51c951..313ea8c19 100644 --- a/tools/tests/prepare-for-vale/fixtures/spec.yaml +++ b/tools/tests/prepare-for-vale/fixtures/spec.yaml @@ -30,3 +30,8 @@ components: Line one Line with backticks: that includes `x.y.z`. Line with two backticks: that includes `x.y.z` and `z.y.x`. + ObjectWithDescriptionAndRef: + type: object + description: |- + Line one. + $ref: '_common.yaml#/components/schemas/HumanReadableByteCount' From 68d446a039f9b3b60ed9cbbd7eb43ba663b0a756 Mon Sep 17 00:00:00 2001 From: dblock Date: Tue, 19 Nov 2024 14:16:37 -0500 Subject: [PATCH 2/2] Keep x-deprecation-message. Signed-off-by: dblock --- .../src/prepare-for-vale/KeepDescriptions.ts | 29 ++++++++++--------- .../tests/prepare-for-vale/fixtures/spec.txt | 10 +++++++ .../tests/prepare-for-vale/fixtures/spec.yaml | 10 +++++++ 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index 3922df1e2..9110ea21a 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -36,17 +36,16 @@ export default class KeepDescriptions { const contents = fs.readFileSync(filename, 'utf-8') var writer = fs.openSync(filename, 'w+') - var inside_description = false + var inside_text = false contents.split(/\r?\n/).forEach((line) => { - // TODO: keep x-deprecation-message - if (line.match(/^[\s]+(description: \|)/)) { - inside_description = true - } else if (line.match(/^[\s]+(description:)[\s]+/)) { - fs.writeSync(writer, this.prune(line).replace("description:", " ")) - } else if (inside_description && line.match(/^[\s]*[\w\\$]*:/)) { - inside_description = false - } else if (inside_description) { - fs.writeSync(writer, this.prune(line)) + if (line.match(/^[\s]+((description|x-deprecation-message): \|)/)) { + inside_text = true + } else if (line.match(/^[\s]+((description|x-deprecation-message):)[\s]+/)) { + fs.writeSync(writer, this.prune_vars(this.prune(line, /(description|x-deprecation-message):/, ' '))) + } else if (inside_text && line.match(/^[\s]*[\w\\$]*:/)) { + inside_text = false + } else if (inside_text) { + fs.writeSync(writer, this.prune_vars(line)) } if (line.length > 0) { fs.writeSync(writer, "\n") @@ -54,9 +53,13 @@ export default class KeepDescriptions { }) } - prune(line: string): string { - return line.replace(/([`])(?:(?=(\\?))\2.)*?\1/g, (match) => { - return Array(match.length + 1).join('*') + prune_vars(line: string): string { + return this.prune(line, /([`])(?:(?=(\\?))\2.)*?\1/g, '*') + } + + prune(line: string, regex: RegExp, char: string): string { + return line.replace(regex, (match) => { + return Array(match.length + 1).join(char) }) } } diff --git a/tools/tests/prepare-for-vale/fixtures/spec.txt b/tools/tests/prepare-for-vale/fixtures/spec.txt index 13f1140d2..f9ada2c25 100644 --- a/tools/tests/prepare-for-vale/fixtures/spec.txt +++ b/tools/tests/prepare-for-vale/fixtures/spec.txt @@ -35,3 +35,13 @@ Line one. + + + Deprecation message. + Line one. + + + + Line one. + Line two. + Line one. diff --git a/tools/tests/prepare-for-vale/fixtures/spec.yaml b/tools/tests/prepare-for-vale/fixtures/spec.yaml index 313ea8c19..6ca62c5de 100644 --- a/tools/tests/prepare-for-vale/fixtures/spec.yaml +++ b/tools/tests/prepare-for-vale/fixtures/spec.yaml @@ -35,3 +35,13 @@ components: description: |- Line one. $ref: '_common.yaml#/components/schemas/HumanReadableByteCount' + ObjectWithDeprecationMessageOneLine: + type: object + x-deprecation-message: Deprecation message. + description: Line one. + ObjectWithDeprecationMessageTwoLines: + type: object + x-deprecation-message: |- + Line one. + Line two. + description: Line one.