diff --git a/.changeset/warm-donkeys-applaud/changes.json b/.changeset/warm-donkeys-applaud/changes.json new file mode 100644 index 00000000..bc12303d --- /dev/null +++ b/.changeset/warm-donkeys-applaud/changes.json @@ -0,0 +1,4 @@ +{ + "releases": [{ "name": "better-ajv-errors", "type": "minor" }], + "dependents": [] +} diff --git a/.changeset/warm-donkeys-applaud/changes.md b/.changeset/warm-donkeys-applaud/changes.md new file mode 100644 index 00000000..ee0917b3 --- /dev/null +++ b/.changeset/warm-donkeys-applaud/changes.md @@ -0,0 +1 @@ +Include data path in CLI output diff --git a/media/screenshot.svg b/media/screenshot.svg index 4983ecbd..52211f49 100644 --- a/media/screenshot.svg +++ b/media/screenshot.svg @@ -1 +1 @@ -ENUMshouldbeequaltooneoftheallowedvalues(paragraph,bulletList,mediaSingle,codeBlock,orderedList,heading,panel,blockquote,mediaGroup,decisionList,taskList,table,bodiedExtension,layoutSection)4|"content":[5|{>6|"type":"paragarph",|^^^^^^^^^^^👈🏽Didyoumeanparagraphhere?7|"content":[8|{9|"type":"text", \ No newline at end of file +(paragraph,bulletList,mediaSingle,codeBlock,orderedList,heading,panel,blockquote,mediaGroup,decisionList,taskList,table,bodiedExtension,layoutSection)4|"content":[5|{>6|"type":"paragarph",|^^^^^^^^^^^👈🏽Didyoumeanparagraphhere?7|"content":[8|{9|"type":"text",@/content/0/type \ No newline at end of file diff --git a/src/validation-errors/__tests__/__snapshots__/enum.js.snap b/src/validation-errors/__tests__/__snapshots__/enum.js.snap index 860494b4..ff3c3d67 100644 --- a/src/validation-errors/__tests__/__snapshots__/enum.js.snap +++ b/src/validation-errors/__tests__/__snapshots__/enum.js.snap @@ -38,7 +38,9 @@ Array [ "  1 | { > 2 |  \\"id\\": \\"baz\\"   |  ^^^^^ 👈🏽 Did you mean bar here? -  3 | }", +  3 | } + + @ /id", ] `; @@ -50,7 +52,9 @@ Array [ "  1 | { > 2 |  \\"id\\": \\"baz\\"   |  ^^^^^ 👈🏽 Did you mean bar here? -  3 | }", +  3 | } + + @ /id", ] `; @@ -62,6 +66,8 @@ Array [ "  1 | { > 2 |  \\"id\\": \\"baz\\"   |  ^^^^^ 👈🏽 Unexpected value, should be equal to one of the allowed values -  3 | }", +  3 | } + + @ /id", ] `; diff --git a/src/validation-errors/__tests__/__snapshots__/required.js.snap b/src/validation-errors/__tests__/__snapshots__/required.js.snap index 756e4664..bbec5441 100644 --- a/src/validation-errors/__tests__/__snapshots__/required.js.snap +++ b/src/validation-errors/__tests__/__snapshots__/required.js.snap @@ -7,6 +7,8 @@ Array [ "  1 | { > 2 |  \\"nested\\": {}   |  ^ ☹️ id is missing here! -  3 | }", +  3 | } + + @ /nested", ] `; diff --git a/src/validation-errors/base.js b/src/validation-errors/base.js index 4a890d62..c74c68ba 100644 --- a/src/validation-errors/base.js +++ b/src/validation-errors/base.js @@ -1,5 +1,6 @@ import { codeFrameColumns } from '@babel/code-frame'; import { getMetaFromPath, getDecoratedDataPath } from '../json'; +import chalk from 'chalk'; export default class BaseValidationError { constructor( @@ -32,10 +33,19 @@ export default class BaseValidationError { } getCodeFrame(message, dataPath = this.options.dataPath) { - return codeFrameColumns(this.jsonRaw, this.getLocation(dataPath), { - highlightCode: true, - message, - }); + const formattedDataPath = dataPath + ? chalk`\n\n {yellow @} {grey ${dataPath}}` + : ''; + const codeFrame = codeFrameColumns( + this.jsonRaw, + this.getLocation(dataPath), + { + highlightCode: true, + message, + } + ); + + return codeFrame + formattedDataPath; } print() {