From f086de5b50f1d26286bed33e15569882f7628b30 Mon Sep 17 00:00:00 2001 From: Tokesh Date: Sun, 22 Dec 2024 16:45:24 +0500 Subject: [PATCH 1/9] ignoring hyperlinks in descriptions for vale Signed-off-by: Tokesh --- tools/src/prepare-for-vale/KeepDescriptions.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index e680da819..99d7207fe 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -45,7 +45,8 @@ export default class KeepDescriptions { } else if (inside_text && line.match(/^[\s]*[\w\\$]*:/)) { inside_text = false } else if (inside_text) { - fs.writeSync(writer, this.prune_vars(line)) + const cleanedLine = line.replace(/\[([^\]]+)\]\([^\)]+\)/g, '$1'); + fs.writeSync(writer, this.prune_vars(cleanedLine)); } if (line.length > 0) { fs.writeSync(writer, "\n") From 02c75b10e694d0a6f4a815cbea998b10caba8684 Mon Sep 17 00:00:00 2001 From: Tokesh Date: Sun, 22 Dec 2024 17:41:37 +0500 Subject: [PATCH 2/9] hotfix linter Signed-off-by: Tokesh --- tools/src/prepare-for-vale/KeepDescriptions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index 99d7207fe..d2b67f3f9 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -45,8 +45,8 @@ export default class KeepDescriptions { } else if (inside_text && line.match(/^[\s]*[\w\\$]*:/)) { inside_text = false } else if (inside_text) { - const cleanedLine = line.replace(/\[([^\]]+)\]\([^\)]+\)/g, '$1'); - fs.writeSync(writer, this.prune_vars(cleanedLine)); + const cleaned_line = line.replace(/\[([^\]]+)\]\([^\)]+\)/g, '$1'); + fs.writeSync(writer, this.prune_vars(cleaned_line)); } if (line.length > 0) { fs.writeSync(writer, "\n") From cf93ff21bdf33725c6857e9c50b21efa4b5bdeec Mon Sep 17 00:00:00 2001 From: Tokesh Date: Sun, 22 Dec 2024 17:45:15 +0500 Subject: [PATCH 3/9] deleting not necessary sign to pass ci linter Signed-off-by: Tokesh --- tools/src/prepare-for-vale/KeepDescriptions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index d2b67f3f9..65d205c31 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -45,8 +45,8 @@ export default class KeepDescriptions { } else if (inside_text && line.match(/^[\s]*[\w\\$]*:/)) { inside_text = false } else if (inside_text) { - const cleaned_line = line.replace(/\[([^\]]+)\]\([^\)]+\)/g, '$1'); - fs.writeSync(writer, this.prune_vars(cleaned_line)); + const cleaned_line = line.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') + fs.writeSync(writer, this.prune_vars(cleaned_line)) } if (line.length > 0) { fs.writeSync(writer, "\n") From 365c94b80750623b72e6006b43e161c38bd95ebc Mon Sep 17 00:00:00 2001 From: Tokesh Date: Mon, 23 Dec 2024 13:30:19 +0500 Subject: [PATCH 4/9] added separate method and tests Signed-off-by: Tokesh --- .../src/prepare-for-vale/KeepDescriptions.ts | 6 +++- .../prepare-for-vale/prepare-for-vale.test.ts | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index 65d205c31..82c692252 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -45,7 +45,7 @@ export default class KeepDescriptions { } else if (inside_text && line.match(/^[\s]*[\w\\$]*:/)) { inside_text = false } else if (inside_text) { - const cleaned_line = line.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') + const cleaned_line = this.remove_links(line) fs.writeSync(writer, this.prune_vars(cleaned_line)) } if (line.length > 0) { @@ -63,4 +63,8 @@ export default class KeepDescriptions { return Array(match.length + 1).join(char) }) } + + remove_links(line: string): string { + return line.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') + } } diff --git a/tools/tests/prepare-for-vale/prepare-for-vale.test.ts b/tools/tests/prepare-for-vale/prepare-for-vale.test.ts index c46fc7340..7d3de7d0a 100644 --- a/tools/tests/prepare-for-vale/prepare-for-vale.test.ts +++ b/tools/tests/prepare-for-vale/prepare-for-vale.test.ts @@ -20,3 +20,31 @@ const spec = (args: string[]): any => { test('--help', () => { expect(spec(['--help']).stdout).toContain('Usage: prepare-for-vale [options]') }) + +test('process single link', () => { + const input = ['description: This is a [link](https://opensearch.org).'] + const expectedOutput = 'description: This is a link.\n' + const result = spec(input).stdout + expect(result).toBe(expectedOutput) +}) + +test('process two links', () => { + const input = ['description: Here is [link one](https://opensearch.org) and [link two](https://opensearch.org/).'] + const expectedOutput = 'description: Here is link one and link two.\n' + const result = spec(input).stdout + expect(result).toBe(expectedOutput) +}) + +test('process plain text without links', () => { + const input = ['description: This is plain text without any links.'] + const expectedOutput = 'description: This is plain text without any links.\n' + const result = spec(input).stdout + expect(result).toBe(expectedOutput) +}) + +test('process complex link structures', () => { + const input = ['description: Check this [link with a title](https://opensearch.org "title").'] + const expectedOutput = 'description: Check this link with a title.\n' + const result = spec(input).stdout + expect(result).toBe(expectedOutput) +}) From 9263f3e85262844db73cc1c665b1b26919d220b7 Mon Sep 17 00:00:00 2001 From: Tokesh Date: Mon, 23 Dec 2024 19:14:23 +0500 Subject: [PATCH 5/9] added expect with contain Signed-off-by: Tokesh --- .../prepare-for-vale/prepare-for-vale.test.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tools/tests/prepare-for-vale/prepare-for-vale.test.ts b/tools/tests/prepare-for-vale/prepare-for-vale.test.ts index 7d3de7d0a..215a11f98 100644 --- a/tools/tests/prepare-for-vale/prepare-for-vale.test.ts +++ b/tools/tests/prepare-for-vale/prepare-for-vale.test.ts @@ -23,28 +23,26 @@ test('--help', () => { test('process single link', () => { const input = ['description: This is a [link](https://opensearch.org).'] - const expectedOutput = 'description: This is a link.\n' - const result = spec(input).stdout - expect(result).toBe(expectedOutput) + expect(spec(input).stdout).toContain('description: This is a link.\n') }) test('process two links', () => { const input = ['description: Here is [link one](https://opensearch.org) and [link two](https://opensearch.org/).'] - const expectedOutput = 'description: Here is link one and link two.\n' + const expected_output = 'description: Here is link one and link two.\n' const result = spec(input).stdout - expect(result).toBe(expectedOutput) + expect(result).toBe(expected_output) }) test('process plain text without links', () => { const input = ['description: This is plain text without any links.'] - const expectedOutput = 'description: This is plain text without any links.\n' + const expected_output = 'description: This is plain text without any links.\n' const result = spec(input).stdout - expect(result).toBe(expectedOutput) + expect(result).toBe(expected_output) }) test('process complex link structures', () => { const input = ['description: Check this [link with a title](https://opensearch.org "title").'] - const expectedOutput = 'description: Check this link with a title.\n' + const expected_output = 'description: Check this link with a title.\n' const result = spec(input).stdout - expect(result).toBe(expectedOutput) + expect(result).toBe(expected_output) }) From 56d4fc74913f5d6b92e1d337d83eae86195d7c74 Mon Sep 17 00:00:00 2001 From: Tokesh Date: Mon, 23 Dec 2024 22:18:18 +0500 Subject: [PATCH 6/9] added tests and fixing code style Signed-off-by: Tokesh --- .../src/prepare-for-vale/KeepDescriptions.ts | 10 ++++--- .../tests/prepare-for-vale/fixtures/spec.txt | 6 ++--- .../tests/prepare-for-vale/fixtures/spec.yaml | 6 ++--- .../prepare-for-vale/prepare-for-vale.test.ts | 26 ------------------- 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index 82c692252..4982ee6b3 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -41,12 +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):/, ' '))) + var cleaned_line = this.prune(line, /(description|x-deprecation-message):/, ' ') + cleaned_line = this.remove_links(line) + cleaned_line = this.prune_vars(cleaned_line) + fs.writeSync(writer, cleaned_line) } else if (inside_text && line.match(/^[\s]*[\w\\$]*:/)) { inside_text = false } else if (inside_text) { - const cleaned_line = this.remove_links(line) - fs.writeSync(writer, this.prune_vars(cleaned_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") diff --git a/tools/tests/prepare-for-vale/fixtures/spec.txt b/tools/tests/prepare-for-vale/fixtures/spec.txt index f9ada2c25..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. + 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 diff --git a/tools/tests/prepare-for-vale/fixtures/spec.yaml b/tools/tests/prepare-for-vale/fixtures/spec.yaml index 6ca62c5de..f4688d63f 100644 --- a/tools/tests/prepare-for-vale/fixtures/spec.yaml +++ b/tools/tests/prepare-for-vale/fixtures/spec.yaml @@ -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 diff --git a/tools/tests/prepare-for-vale/prepare-for-vale.test.ts b/tools/tests/prepare-for-vale/prepare-for-vale.test.ts index 215a11f98..c46fc7340 100644 --- a/tools/tests/prepare-for-vale/prepare-for-vale.test.ts +++ b/tools/tests/prepare-for-vale/prepare-for-vale.test.ts @@ -20,29 +20,3 @@ const spec = (args: string[]): any => { test('--help', () => { expect(spec(['--help']).stdout).toContain('Usage: prepare-for-vale [options]') }) - -test('process single link', () => { - const input = ['description: This is a [link](https://opensearch.org).'] - expect(spec(input).stdout).toContain('description: This is a link.\n') -}) - -test('process two links', () => { - const input = ['description: Here is [link one](https://opensearch.org) and [link two](https://opensearch.org/).'] - const expected_output = 'description: Here is link one and link two.\n' - const result = spec(input).stdout - expect(result).toBe(expected_output) -}) - -test('process plain text without links', () => { - const input = ['description: This is plain text without any links.'] - const expected_output = 'description: This is plain text without any links.\n' - const result = spec(input).stdout - expect(result).toBe(expected_output) -}) - -test('process complex link structures', () => { - const input = ['description: Check this [link with a title](https://opensearch.org "title").'] - const expected_output = 'description: Check this link with a title.\n' - const result = spec(input).stdout - expect(result).toBe(expected_output) -}) From b02b5e965c86cd2bcab8feb79f3a3ef5654002c4 Mon Sep 17 00:00:00 2001 From: Tokesh Date: Mon, 23 Dec 2024 22:21:20 +0500 Subject: [PATCH 7/9] hotfix code style in keepdescriptions Signed-off-by: Tokesh --- tools/src/prepare-for-vale/KeepDescriptions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index 4982ee6b3..b2d0d33f3 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -41,9 +41,9 @@ 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]+/)) { - var cleaned_line = this.prune(line, /(description|x-deprecation-message):/, ' ') - cleaned_line = this.remove_links(line) + 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 From 03cbf9d1a020d739f0bec7a88f1ba02df92b5b65 Mon Sep 17 00:00:00 2001 From: Tokesh Date: Tue, 24 Dec 2024 23:31:31 +0500 Subject: [PATCH 8/9] chore: added spaces outside of regex match Signed-off-by: Tokesh --- tools/src/prepare-for-vale/KeepDescriptions.ts | 5 ++++- tools/tests/prepare-for-vale/fixtures/spec.txt | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index b2d0d33f3..002d7015a 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -69,6 +69,9 @@ export default class KeepDescriptions { } remove_links(line: string): string { - return line.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') + return line.replace(/\[([^\]]+)\]\([^)]+\)/g, (match, p1) => { + const spaces = ' '.repeat(match.length - p1.length-1); + return ' ' + p1 + spaces; + }); } } diff --git a/tools/tests/prepare-for-vale/fixtures/spec.txt b/tools/tests/prepare-for-vale/fixtures/spec.txt index 3f29f1c05..8070b934e 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 From 9b2b62d95e70728fc6d4cb5ea7ddc79b4a6a14e9 Mon Sep 17 00:00:00 2001 From: Tokesh Date: Fri, 27 Dec 2024 17:40:29 +0500 Subject: [PATCH 9/9] chore: formatting code by linter Signed-off-by: Tokesh --- tools/src/prepare-for-vale/KeepDescriptions.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/src/prepare-for-vale/KeepDescriptions.ts b/tools/src/prepare-for-vale/KeepDescriptions.ts index 002d7015a..fa5699e58 100644 --- a/tools/src/prepare-for-vale/KeepDescriptions.ts +++ b/tools/src/prepare-for-vale/KeepDescriptions.ts @@ -70,8 +70,8 @@ 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; - }); + const spaces = ' '.repeat(match.length - p1.length - 1) + return ' ' + p1 + spaces + }) } }