From 9f7b7280dbe05c2d955041105ba0538d483e8ee2 Mon Sep 17 00:00:00 2001 From: yassh Date: Sat, 27 Aug 2016 22:44:36 +0900 Subject: [PATCH 1/3] add -n/--insert-final-newline option --- lib/cli.js | 9 +++++++-- lib/formatter.js | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 981c15f..211d008 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -36,6 +36,11 @@ var options = require("nomnom") "default": " ", help: 'character(s) to use for indentation' }, + insertFinalNewline : { + flag : true, + string: '-n, --insert-final-newline', + help: 'ensure JSON string ends with a newline' + }, compact : { flag : true, string: '-c, --compact', @@ -90,7 +95,7 @@ function parse (source) { } } - return JSON.stringify(parsed, null, options.indent); + return JSON.stringify(parsed, null, options.indent) + (options.insertFinalNewline ? "\n" : ""); } catch (e) { if (options.forcePrettyPrint) { /* From https://github.com/umbrae/jsonlintdotcom: @@ -100,7 +105,7 @@ function parse (source) { */ try { - formatted = formatter.formatJson(source, options.indent); + formatted = formatter.formatJson(source, options.indent, options.insertFinalNewline); // Re-parse so exception output gets better line numbers parsed = parser.parse(formatted); } catch (e) { diff --git a/lib/formatter.js b/lib/formatter.js index e6e2726..de398a6 100644 --- a/lib/formatter.js +++ b/lib/formatter.js @@ -16,7 +16,7 @@ var formatter = (function () { return new Array(count + 1).join(s); } - function formatJson(json, indentChars) { + function formatJson(json, indentChars, insertFinalNewline) { var i = 0, il = 0, tab = (typeof indentChars !== "undefined") ? indentChars : " ", @@ -80,6 +80,8 @@ var formatter = (function () { } } + if (insertFinalNewline) newJson += "\n"; + return newJson; } From 382875536ca1ab2023b06a2d20ce162272a76651 Mon Sep 17 00:00:00 2001 From: yassh Date: Sat, 27 Aug 2016 22:49:56 +0900 Subject: [PATCH 2/3] Adding in the -n/--insert-final-newline option to the Readme.md --- README.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 58a1aa1..e9b3a97 100644 --- a/README.md +++ b/README.md @@ -27,15 +27,16 @@ jsonlint will either report a syntax error with details or pretty print the sour file file to parse; otherwise uses stdin Options: - -v, --version print version and exit - -s, --sort-keys sort object keys - -i, --in-place overwrite the file - -t CHAR, --indent CHAR character(s) to use for indentation [ ] - -c, --compact compact error display - -V, --validate a JSON schema to use for validation - -e, --environment which specification of JSON Schema the validation file uses [json-schema-draft-03] - -q, --quiet do not print the parsed json to STDOUT [false] - -p, --pretty-print force pretty printing even if invalid + -v, --version print version and exit + -s, --sort-keys sort object keys + -i, --in-place overwrite the file + -t CHAR, --indent CHAR character(s) to use for indentation [ ] + -n, --insert-final-newline ensure JSON string ends with a newline + -c, --compact compact error display + -V, --validate a JSON schema to use for validation + -e, --environment which specification of JSON Schema the validation file uses [json-schema-draft-03] + -q, --quiet do not print the parsed json to STDOUT [false] + -p, --pretty-print force pretty printing even if invalid ## Module interface From c28bea28da5cee83c65479f4b404710925f18703 Mon Sep 17 00:00:00 2001 From: kevcenteno Date: Mon, 19 Jun 2017 17:37:46 -0400 Subject: [PATCH 3/3] Prep package for publish --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b94e7b6..3b496db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "author": "Zach Carter (http://zaa.ch)", - "name": "jsonlint", + "name": "jsonlint-newline-fork", "description": "Validate JSON", "keywords": [ "json", @@ -8,14 +8,14 @@ "lint", "jsonlint" ], - "version": "1.6.2", + "version": "1.6.3", "preferGlobal": true, "repository": { "type": "git", - "url": "git://github.com/zaach/jsonlint.git" + "url": "git://github.com/kevcenteno/jsonlint.git" }, "bugs": { - "url": "http://github.com/zaach/jsonlint/issues" + "url": "http://github.com/kevcenteno/jsonlint/issues" }, "main": "lib/jsonlint.js", "bin": {