From 144a3c26348f5713dea3fd454f31b761e8a54fed Mon Sep 17 00:00:00 2001 From: Hakim Cassimally Date: Wed, 10 Sep 2025 10:53:45 +0100 Subject: [PATCH 1/2] DOC-13478 Vale review Capella API POC These Views are customized to either: - `description` at top-level (Included) - `properties.*.description` This requires us to explicitly tell Vale which files are of which type in the .vale.ini like this example: ``` [cmd/cp-open-api/specs/schemas/alertIntegration/{BasicAuth,*AlertIntegration*,Exclude,Reque st*, Response*}.yaml] BasedOnStyles = Vale, write-good, proselint, Couchbase, Google View = OpenAPI [cmd/cp-open-api/specs/schemas/alertIntegration/{Token}.yaml] BasedOnStyles = Vale, write-good, proselint, Couchbase, Google View = OpenAPIInclude ``` (This restriction may go away with dasel 3, once Vale integrates that) --- ValeStyles/config/views/OpenAPI.yml | 4 ++++ ValeStyles/config/views/OpenAPIInclude.yml | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 ValeStyles/config/views/OpenAPI.yml create mode 100644 ValeStyles/config/views/OpenAPIInclude.yml diff --git a/ValeStyles/config/views/OpenAPI.yml b/ValeStyles/config/views/OpenAPI.yml new file mode 100644 index 0000000..183b82c --- /dev/null +++ b/ValeStyles/config/views/OpenAPI.yml @@ -0,0 +1,4 @@ +engine: dasel +scopes: + - expr: properties.all().property(description?) + type: md diff --git a/ValeStyles/config/views/OpenAPIInclude.yml b/ValeStyles/config/views/OpenAPIInclude.yml new file mode 100644 index 0000000..55b8af7 --- /dev/null +++ b/ValeStyles/config/views/OpenAPIInclude.yml @@ -0,0 +1,4 @@ +engine: dasel +scopes: + - expr: description + type: md From ffef7ca0dc30476ad9923833deeb8acda7b14b15 Mon Sep 17 00:00:00 2001 From: Hakim Cassimally Date: Tue, 7 Oct 2025 15:16:24 +0100 Subject: [PATCH 2/2] Test .yml view (dasel) - Span incorrect It looks like the behaviour of Vale with dasel view of a Yaml file gives inconsistent results for Line and Span. EXPECT: ====== the .Line and .Span records should point to the location in the file that the .Match text comes from. ACTUAL: ====== * For .adoc, this expectation is true. * For rules like Couchbase.VentilatedProse (theory: with `scope: raw`), we instead get the .Line indexed from the position of the Yaml token selected. For example, on the first line of the `.description`, it is marked as Line: 1 * For rules like Vale.Terms, we do get the correct .Line, but the .Span is indexed based on *YAML*'s understanding of the parsed content, not the textual source of the .yaml file contents. --- ValeStyles/.vale.ini | 6 +++- ValeStyles/test/expected.js | 2 +- ValeStyles/test/fixtures/test.yml | 7 +++++ ValeStyles/test/view-span.js | 51 +++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 ValeStyles/test/fixtures/test.yml create mode 100644 ValeStyles/test/view-span.js diff --git a/ValeStyles/.vale.ini b/ValeStyles/.vale.ini index 80279fb..393da0f 100644 --- a/ValeStyles/.vale.ini +++ b/ValeStyles/.vale.ini @@ -26,7 +26,11 @@ experimental = YES attribute-missing = drop +Vale.Spelling = NO + [*.{adoc,md,txt}] BasedOnStyles = Vale, write-good, proselint, Couchbase, Google -Vale.Spelling = NO +[test/fixtures/test.yml] +BasedOnStyles = Vale, write-good, proselint, Couchbase, Google +View = OpenAPIInclude diff --git a/ValeStyles/test/expected.js b/ValeStyles/test/expected.js index eeebb76..615f786 100644 --- a/ValeStyles/test/expected.js +++ b/ValeStyles/test/expected.js @@ -14,7 +14,7 @@ describe('run vale against test files', function () { 'vale', [ '--output', 'JSON', - 'test/fixtures/' + 'test/fixtures/*.adoc' ] ) } diff --git a/ValeStyles/test/fixtures/test.yml b/ValeStyles/test/fixtures/test.yml new file mode 100644 index 0000000..d646b43 --- /dev/null +++ b/ValeStyles/test/fixtures/test.yml @@ -0,0 +1,7 @@ +type: test +content: + foo: 1 + bar: 2 +description: | + First sentence. Second sentence. + Test couchbase. diff --git a/ValeStyles/test/view-span.js b/ValeStyles/test/view-span.js new file mode 100644 index 0000000..34bde16 --- /dev/null +++ b/ValeStyles/test/view-span.js @@ -0,0 +1,51 @@ +const {range, zip, escape} = require('lodash'); + +// this test file is designed to be run with Mocha +const assert = require('assert') +const fs = require('fs') +const ok = specify +const { spawnSync } = require('node:child_process') + +describe('check spans for Yaml', function () { + testSpans('test/fixtures/test.yml') +}) + +describe('check spans for Asciidoc', function () { + testSpans('test/fixtures/basic.adoc') +}) + +function testSpans(file) { + const vale = runVale(file) + + const text = fs.readFileSync(file).toString() + const lines = text.match(/^.*?(\n|$)/gm) + + for (const item of vale[file]) { + const line = lines[item.Line - 1] + const [from,to] = item.Span + const span = line.substr(from - 1, to-from+1) + + ok(`Match ${item.Match}`, function () { + assert.equal(item.Match, span) + console.log({line, span, match: item.Match}) + }) + } +} + +function runVale(file) { + let vale + try { + vale = spawnSync( + 'vale', + [ + '--output', 'JSON', + file + ] + ) + } + catch (err) { + console.log("Failed to run vale", err) + } + + return JSON.parse(vale.stdout) +}