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

Adjust Vale rules to ignore links #753

Merged
merged 9 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
16 changes: 14 additions & 2 deletions tools/src/prepare-for-vale/KeepDescriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ export default class KeepDescriptions {
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):/, ' ')))
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\\$]*:/)) {
inside_text = false
} else if (inside_text) {
fs.writeSync(writer, this.prune_vars(line))
let cleaned_line = this.remove_links(line)
cleaned_line = this.prune_vars(cleaned_line)
fs.writeSync(writer, cleaned_line)
}
if (line.length > 0) {
fs.writeSync(writer, "\n")
Expand All @@ -62,4 +67,11 @@ export default class KeepDescriptions {
return Array(match.length + 1).join(char)
})
}

remove_links(line: string): string {
return line.replace(/\[([^\]]+)\]\([^)]+\)/g, (match, p1) => {
const spaces = ' '.repeat(match.length - p1.length-1);
Tokesh marked this conversation as resolved.
Show resolved Hide resolved
return ' ' + p1 + spaces;
Tokesh marked this conversation as resolved.
Show resolved Hide resolved
});
Tokesh marked this conversation as resolved.
Show resolved Hide resolved
}
}
6 changes: 3 additions & 3 deletions tools/tests/prepare-for-vale/fixtures/spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@



For a successful response, this value is always true. On failure, an exception is returned instead.
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.
The item level REST category class codes during indexing link with a title .



Line one
Here is link one and link two .
Line two


Expand Down
6 changes: 3 additions & 3 deletions tools/tests/prepare-for-vale/fixtures/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ components:
type: object
properties:
acknowledged:
description: For a successful response, this value is always true. On failure, an exception is returned instead.
description: For a successful response, this value is always true. On failure, an exception is returned instead [Supported units](https://opensearch.org/docs/latest/api-reference/units/).
type: boolean
ObjectWithMultilineDescriptionOneLine:
description: |-
The item level REST category class codes during indexing.
The item level REST category class codes during indexing [link with a title](https://opensearch.org "title").
type: object
ObjectWithMultilineDescriptionTwoLines:
description: |-
Line one
Here is [link one](https://opensearch.org) and [link two](https://opensearch.org/).
Line two
ObjectWithAColonInDescription:
type: object
Expand Down
Loading