From 726651df5a4a60d17371078924f964c5a514a7d3 Mon Sep 17 00:00:00 2001 From: Lakitna Date: Sun, 13 Oct 2019 23:13:43 +0200 Subject: [PATCH 1/5] Initial implementation --- src/validation-errors/base.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/validation-errors/base.js b/src/validation-errors/base.js index 4a890d62..ea59627b 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,16 @@ 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}}` + : ''; + + return ( + codeFrameColumns(this.jsonRaw, this.getLocation(dataPath), { + highlightCode: true, + message, + }) + formattedDataPath + ); } print() { From 77f4bbf23f710570731c0eb2864320764b2101b1 Mon Sep 17 00:00:00 2001 From: Lakitna Date: Tue, 15 Oct 2019 19:45:02 +0200 Subject: [PATCH 2/5] Restructured implementation --- src/validation-errors/base.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/validation-errors/base.js b/src/validation-errors/base.js index ea59627b..c74c68ba 100644 --- a/src/validation-errors/base.js +++ b/src/validation-errors/base.js @@ -36,13 +36,16 @@ export default class BaseValidationError { const formattedDataPath = dataPath ? chalk`\n\n {yellow @} {grey ${dataPath}}` : ''; - - return ( - codeFrameColumns(this.jsonRaw, this.getLocation(dataPath), { + const codeFrame = codeFrameColumns( + this.jsonRaw, + this.getLocation(dataPath), + { highlightCode: true, message, - }) + formattedDataPath + } ); + + return codeFrame + formattedDataPath; } print() { From 4572ef11ff82095306d4f32ce6f4bb29df1a24f5 Mon Sep 17 00:00:00 2001 From: Lakitna Date: Tue, 15 Oct 2019 19:45:12 +0200 Subject: [PATCH 3/5] Updated tests --- .../__tests__/__snapshots__/enum.js.snap | 12 +++++++++--- .../__tests__/__snapshots__/required.js.snap | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) 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", ] `; From 428c0b8309bc7f710e0f0aad0851c49231e07768 Mon Sep 17 00:00:00 2001 From: Rifat Nabi Date: Sat, 30 Nov 2019 12:17:09 +1100 Subject: [PATCH 4/5] Update screenshot --- media/screenshot.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 0d4f1ab9ef5dea7f7ad47b80c884bdc40076e93c Mon Sep 17 00:00:00 2001 From: Rifat Nabi Date: Sat, 30 Nov 2019 12:19:10 +1100 Subject: [PATCH 5/5] Add changeset --- .changeset/warm-donkeys-applaud/changes.json | 4 ++++ .changeset/warm-donkeys-applaud/changes.md | 1 + 2 files changed, 5 insertions(+) create mode 100644 .changeset/warm-donkeys-applaud/changes.json create mode 100644 .changeset/warm-donkeys-applaud/changes.md 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