Skip to content

Commit

Permalink
Preprocess away backtick-quoted values.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Nov 18, 2024
1 parent 5b9f7f2 commit 1c23126
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tools/src/prepare-for-vale/KeepDescriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,21 @@ export default class KeepDescriptions {
if (line.match(/^[\s]+(description: \|)/)) {
inside_description = true
} else if (line.match(/^[\s]+(description:)[\s]+/)) {
fs.writeSync(writer, line.replace("description:", " "))
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, line)
fs.writeSync(writer, this.prune(line))
}
if (line.length > 0) {
fs.writeSync(writer, "\n")
}
})
}

prune(line: string): string {
return line.replace(/([`])(?:(?=(\\?))\2.)*?\1/g, (match) => {
return Array(match.length + 1).join('*')
})
}
}
6 changes: 6 additions & 0 deletions tools/tests/prepare-for-vale/fixtures/spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@

Line one
Line with a description: that describes itself.



Line one
Line with backticks: that includes *******.
Line with two backticks: that includes ******* and *******.
6 changes: 6 additions & 0 deletions tools/tests/prepare-for-vale/fixtures/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ components:
description: |-
Line one
Line with a description: that describes itself.
ObjectWithCode:
type: object
description: |-
Line one
Line with backticks: that includes `x.y.z`.
Line with two backticks: that includes `x.y.z` and `z.y.x`.

0 comments on commit 1c23126

Please sign in to comment.