Skip to content

Commit

Permalink
Adjust Vale rules to ignore links (opensearch-project#753)
Browse files Browse the repository at this point in the history
* ignoring hyperlinks in descriptions for vale

Signed-off-by: Tokesh <[email protected]>

* hotfix linter

Signed-off-by: Tokesh <[email protected]>

* deleting not necessary sign to pass ci linter

Signed-off-by: Tokesh <[email protected]>

* added separate method and tests

Signed-off-by: Tokesh <[email protected]>

* added expect with contain

Signed-off-by: Tokesh <[email protected]>

* added tests and fixing code style

Signed-off-by: Tokesh <[email protected]>

* hotfix code style in keepdescriptions

Signed-off-by: Tokesh <[email protected]>

* chore: added spaces outside of regex match

Signed-off-by: Tokesh <[email protected]>

* chore: formatting code by linter

Signed-off-by: Tokesh <[email protected]>

---------

Signed-off-by: Tokesh <[email protected]>
  • Loading branch information
Tokesh authored Dec 27, 2024
1 parent 1dac3c9 commit 0e0e072
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
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)
return ' ' + p1 + spaces
})
}
}
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

0 comments on commit 0e0e072

Please sign in to comment.