Skip to content

Commit

Permalink
Merge pull request #1 from Marcisbee/line-numbers
Browse files Browse the repository at this point in the history
Adds line numbers in output errors
  • Loading branch information
Marcisbee authored Feb 4, 2021
2 parents b2d20db + 1df6a56 commit c7699e7
Show file tree
Hide file tree
Showing 14 changed files with 1,229 additions and 64 deletions.
856 changes: 820 additions & 36 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "esjson",
"version": "0.9.0",
"version": "1.0.0",
"description": "JSON Schema validator (cli)",
"main": "src/index.js",
"bin": {
"esjson": "bin/esjson.js"
},
"scripts": {
"start": "node src/index.js",
"start": "node bin/esjson.js",
"lint": "rome check",
"test": "uvu",
"coverage": "c8 --check-coverage npm test"
Expand All @@ -32,14 +32,14 @@
"devDependencies": {
"c8": "^7.3.5",
"rome": "^10.0.4-beta",
"uvu": "^0.4.1"
"uvu": "^0.5.1"
},
"files": [
"bin",
"src"
],
"dependencies": {
"arg": "^4.1.3",
"arg": "^5.0.0",
"colorette": "^1.2.1"
}
}
4 changes: 3 additions & 1 deletion src/diagnostics/validation-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ class ValidationError {
* @param {string} message
* @param {string} code
* @param {(string | number)[]=} position
* @param {number=} lineNo
* @param {string=} filePath
*/
constructor(message, code, position = [], filePath = null) {
constructor(message, code, position = [], filePath = null, lineNo = null) {
this.message = message;
this.position = position;
this.code = code;
this.path = filePath;
this.lineNo = lineNo;
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/diagnostics/warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ class Warning extends Error {
* @param {string} message
* @param {string} code
* @param {(string | number)[]} position
* @param {number=} lineNo
* @param {string=} path
*/
constructor(message, code, position, path) {
constructor(message, code, position, path, lineNo = null) {
super(message);
this.code = code;
this.position = position;
this.path = path;
this.lineNo = lineNo;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const defaultConfig = {
/**
* @typedef Context
* @property {(json: *, position: (string | number)[], currentSchema?: *) => void} validateSchema
* @property {(message: string, code: string, position: (string | number)[], ref?: Ref) => (import('./diagnostics/validation-error') | Warning | Error)} error
* @property {(message: string, code: string, position: (string | number)[], ref?: Ref, lineNo?: number) => (import('./diagnostics/validation-error') | Warning | Error)} error
* @property {(import('./diagnostics/validation-error') | Warning | Diagnostics | Error)[]} errors
* @property {Record<string, any>} schema
* @property {Record<string, any>} config
Expand Down
Loading

0 comments on commit c7699e7

Please sign in to comment.