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/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 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) +}