@prantlf/jsonlint 11.5.0 → 11.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/lib/cli.js +8 -5
- package/lib/jsonlint.d.ts +3 -0
- package/lib/jsonlint.js +19 -1
- package/lib/validator.js +1 -0
- package/package.json +14 -14
- package/web/ajv.min.js.map +1 -1
- package/web/formatter.min.js.map +1 -1
- package/web/jsonlint.min.js +1 -1
- package/web/jsonlint.min.js.map +1 -1
- package/web/printer.min.js.map +1 -1
- package/web/schema-drafts.min.js.map +1 -1
- package/web/sorter.min.js.map +1 -1
- package/web/validator.min.js +1 -1
- package/web/validator.min.js.map +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ This is a fork of the original project ([zaach/jsonlint](https://github.com/zaac
|
|
|
12
12
|
* Handles multiple files on the command line (by Greg Inman).
|
|
13
13
|
* Walks directories recursively (by Paul Vollmer).
|
|
14
14
|
* Provides 100% compatible interface to the native `JSON.parse` method.
|
|
15
|
+
* Optionally ignores the leading UTF-8 byte-order mark (BOM).
|
|
15
16
|
* Optionally recognizes JavaScript-style comments (CJSON) and single quoted strings (JSON5).
|
|
16
17
|
* Optionally ignores trailing commas and reports duplicate object keys as an error.
|
|
17
18
|
* Optionally checks that also the expected format matches, including sorted object keys.
|
|
@@ -129,6 +130,7 @@ Usage: `jsonlint [options] [<file, directory, pattern> ...]`
|
|
|
129
130
|
-c, --compact compact error display
|
|
130
131
|
-M, --mode [mode] set other parsing flags according to a format
|
|
131
132
|
type (default: "json")
|
|
133
|
+
-B, --bom ignore the leading UTF-8 byte-order mark
|
|
132
134
|
-C, --comments recognize and ignore JavaScript-style comments
|
|
133
135
|
-S, --single-quoted-strings support single quotes as string delimiters
|
|
134
136
|
-T, --trailing-commas ignore trailing commas in objects and arrays
|
|
@@ -136,6 +138,7 @@ Usage: `jsonlint [options] [<file, directory, pattern> ...]`
|
|
|
136
138
|
-V, --validate [file] JSON schema file to use for validation
|
|
137
139
|
-e, --environment [env] which specification of JSON Schema the
|
|
138
140
|
validation file uses
|
|
141
|
+
-x, --context [num] line count used as the diff context (default: 3)
|
|
139
142
|
-l, --log-files print only the parsed file names to stdout
|
|
140
143
|
-q, --quiet do not print the parsed json to stdout
|
|
141
144
|
-n, --continue continue with other files if an error occurs
|
|
@@ -156,7 +159,7 @@ Usage: `jsonlint [options] [<file, directory, pattern> ...]`
|
|
|
156
159
|
-h, --help output usage information
|
|
157
160
|
|
|
158
161
|
You can use BASH patterns for including and excluding files (only files).
|
|
159
|
-
Patterns are case-sensitive and have to use slashes as
|
|
162
|
+
Patterns are case-sensitive and have to use slashes as directory separators.
|
|
160
163
|
A pattern to exclude from processing starts with "!".
|
|
161
164
|
|
|
162
165
|
Parsing mode can be "cjson" or "json5" to enable other flags automatically.
|
|
@@ -193,6 +196,7 @@ The configuration is an object with the following properties, described above, w
|
|
|
193
196
|
| indent | |
|
|
194
197
|
| compact | |
|
|
195
198
|
| mode | |
|
|
199
|
+
| bom | |
|
|
196
200
|
| comments | |
|
|
197
201
|
| single-quoted-strings | singleQuotedStrings |
|
|
198
202
|
| trailing-commas | trailingCommas |
|
|
@@ -250,6 +254,7 @@ The `parse` method offers more detailed [error information](#error-handling), th
|
|
|
250
254
|
|
|
251
255
|
| Option | Description |
|
|
252
256
|
| -------------------------- | ------------------------------------------- |
|
|
257
|
+
| `ignoreBOM` | ignores the leading UTF-8 byte-order mark (boolean) |
|
|
253
258
|
| `ignoreComments` | ignores single-line and multi-line JavaScript-style comments during parsing as another "whitespace" (boolean) |
|
|
254
259
|
| `ignoreTrailingCommas` | ignores trailing commas in objects and arrays (boolean) |
|
|
255
260
|
| `allowSingleQuotedStrings` | accepts strings delimited by single-quotes too (boolean) |
|
package/lib/cli.js
CHANGED
|
@@ -26,12 +26,14 @@ const commander = require('commander')
|
|
|
26
26
|
.option('-t, --indent [num|char]', 'number of spaces or specific characters to use for indentation', 2)
|
|
27
27
|
.option('-c, --compact', 'compact error display')
|
|
28
28
|
.option('-M, --mode [mode]', 'set other parsing flags according to a format type', 'json')
|
|
29
|
+
.option('-B, --bom', 'ignore the leading UTF-8 byte-order mark')
|
|
29
30
|
.option('-C, --comments', 'recognize and ignore JavaScript-style comments')
|
|
30
31
|
.option('-S, --single-quoted-strings', 'support single quotes as string delimiters')
|
|
31
32
|
.option('-T, --trailing-commas', 'ignore trailing commas in objects and arrays')
|
|
32
33
|
.option('-D, --no-duplicate-keys', 'report duplicate object keys as an error')
|
|
33
34
|
.option('-V, --validate [file]', 'JSON schema file to use for validation')
|
|
34
35
|
.option('-e, --environment [env]', 'which specification of JSON Schema the validation file uses')
|
|
36
|
+
.option('-x, --context [num]', 'line count used as the diff context', 3)
|
|
35
37
|
.option('-l, --log-files', 'print only the parsed file names to stdout')
|
|
36
38
|
.option('-q, --quiet', 'do not print the parsed json to stdout')
|
|
37
39
|
.option('-n, --continue', 'continue with other files if an error occurs')
|
|
@@ -48,7 +50,7 @@ const commander = require('commander')
|
|
|
48
50
|
.on('--help', () => {
|
|
49
51
|
console.log()
|
|
50
52
|
console.log('You can use BASH patterns for including and excluding files (only files).')
|
|
51
|
-
console.log('Patterns are case-sensitive and have to use slashes as
|
|
53
|
+
console.log('Patterns are case-sensitive and have to use slashes as directory separators.')
|
|
52
54
|
console.log('A pattern to exclude from processing starts with "!".')
|
|
53
55
|
console.log()
|
|
54
56
|
console.log('Parsing mode can be "cjson" or "json5" to enable other flags automatically.')
|
|
@@ -134,6 +136,7 @@ function processContents (source, file) {
|
|
|
134
136
|
try {
|
|
135
137
|
parserOptions = {
|
|
136
138
|
mode: options.mode,
|
|
139
|
+
ignoreBOM: options.bom,
|
|
137
140
|
ignoreComments: options.comments,
|
|
138
141
|
ignoreTrailingCommas: options.trailingCommas,
|
|
139
142
|
allowSingleQuotedStrings: options.singleQuotedStrings,
|
|
@@ -218,9 +221,8 @@ function ensureLineBreak (parsed, source) {
|
|
|
218
221
|
|
|
219
222
|
function checkContents (file, source, parsed) {
|
|
220
223
|
const { createTwoFilesPatch, structuredPatch } = require('diff')
|
|
221
|
-
const structured = structuredPatch(`${file}.orig`, file, source, parsed, '', '', { context:
|
|
224
|
+
const structured = structuredPatch(`${file}.orig`, file, source, parsed, '', '', { context: options.context })
|
|
222
225
|
const length = structured.hunks && structured.hunks.length
|
|
223
|
-
const diff = createTwoFilesPatch(`${file}.orig`, file, source, parsed, '', '', { context: 3 })
|
|
224
226
|
if (length > 0) {
|
|
225
227
|
const hunk = length === 1 ? 'hunk differs' : 'hunks differ'
|
|
226
228
|
const message = `${length} ${hunk}`
|
|
@@ -232,6 +234,7 @@ function checkContents (file, source, parsed) {
|
|
|
232
234
|
console.error(message)
|
|
233
235
|
}
|
|
234
236
|
if (!options.quiet) {
|
|
237
|
+
const diff = createTwoFilesPatch(`${file}.orig`, file, source, parsed, '', '', { context: options.context })
|
|
235
238
|
console.log(diff)
|
|
236
239
|
}
|
|
237
240
|
if (options.continue) {
|
|
@@ -253,10 +256,10 @@ function diffContents (file, source, parsed) {
|
|
|
253
256
|
const compact = options.quiet || options.compact
|
|
254
257
|
let diff, length
|
|
255
258
|
if (compact) {
|
|
256
|
-
diff = structuredPatch(`${file}.orig`, file, source, parsed, '', '', { context:
|
|
259
|
+
diff = structuredPatch(`${file}.orig`, file, source, parsed, '', '', { context: options.context })
|
|
257
260
|
length = diff.hunks && diff.hunks.length
|
|
258
261
|
} else {
|
|
259
|
-
diff = createTwoFilesPatch(`${file}.orig`, file, source, parsed, '', '', { context:
|
|
262
|
+
diff = createTwoFilesPatch(`${file}.orig`, file, source, parsed, '', '', { context: options.context })
|
|
260
263
|
length = diff.split(/\r?\n/).length - 4
|
|
261
264
|
}
|
|
262
265
|
if (length > 0) {
|
package/lib/jsonlint.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
type ParseMode = 'json' | 'cjson' | 'json5'
|
|
2
2
|
|
|
3
3
|
interface ParseOptions {
|
|
4
|
+
ignoreBOM?: boolean
|
|
4
5
|
ignoreComments?: boolean
|
|
5
6
|
ignoreTrailingCommas?: boolean
|
|
6
7
|
allowSingleQuotedStrings?: boolean
|
|
@@ -27,6 +28,7 @@ interface ParseOptions {
|
|
|
27
28
|
declare function parse (input: string, reviverOrOptions?: Function | ParseOptions): object
|
|
28
29
|
|
|
29
30
|
interface TokenizeOptions {
|
|
31
|
+
ignoreBOM?: boolean
|
|
30
32
|
ignoreComments?: boolean
|
|
31
33
|
ignoreTrailingCommas?: boolean
|
|
32
34
|
allowSingleQuotedStrings?: boolean
|
|
@@ -58,6 +60,7 @@ declare module '@prantlf/jsonlint/lib/validator' {
|
|
|
58
60
|
type Environment = 'json-schema-draft-04' | 'json-schema-draft-06' | 'json-schema-draft-07'
|
|
59
61
|
|
|
60
62
|
interface CompileOptions {
|
|
63
|
+
ignoreBOM?: boolean
|
|
61
64
|
ignoreComments?: boolean
|
|
62
65
|
ignoreTrailingCommas?: boolean
|
|
63
66
|
allowSingleQuotedStrings?: boolean
|
package/lib/jsonlint.js
CHANGED
|
@@ -84,6 +84,12 @@ function isDecDigit (x) {
|
|
|
84
84
|
return x >= '0' && x <= '9'
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
function isBOM (x) {
|
|
88
|
+
// This catches EFBBBF (UTF-8 BOM) because the buffer-to-string
|
|
89
|
+
// conversion in `fs.readFileSync()` translates it to FEFF (UTF-16 BOM).
|
|
90
|
+
return x.charCodeAt(0) === 0xFEFF
|
|
91
|
+
}
|
|
92
|
+
|
|
87
93
|
const unescapeMap = {
|
|
88
94
|
'\'': '\'',
|
|
89
95
|
'"': '"',
|
|
@@ -103,6 +109,7 @@ function parseInternal (input, options) {
|
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
const json5 = options.mode === 'json5'
|
|
112
|
+
const ignoreBOM = options.ignoreBOM
|
|
106
113
|
const ignoreComments = options.ignoreComments || options.mode === 'cjson' || json5
|
|
107
114
|
const ignoreTrailingCommas = options.ignoreTrailingCommas || json5
|
|
108
115
|
const allowSingleQuotedStrings = options.allowSingleQuotedStrings || json5
|
|
@@ -289,6 +296,14 @@ function parseInternal (input, options) {
|
|
|
289
296
|
}
|
|
290
297
|
}
|
|
291
298
|
|
|
299
|
+
function skipBOM () {
|
|
300
|
+
if (isBOM(input)) {
|
|
301
|
+
startToken && startToken()
|
|
302
|
+
++position
|
|
303
|
+
endToken && endToken('bom')
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
292
307
|
function skipWhiteSpace () {
|
|
293
308
|
let insideWhiteSpace
|
|
294
309
|
function startWhiteSpace () {
|
|
@@ -683,6 +698,9 @@ function parseInternal (input, options) {
|
|
|
683
698
|
fail()
|
|
684
699
|
}
|
|
685
700
|
|
|
701
|
+
if (ignoreBOM) {
|
|
702
|
+
skipBOM()
|
|
703
|
+
}
|
|
686
704
|
skipWhiteSpace()
|
|
687
705
|
let returnValue = parseGeneric()
|
|
688
706
|
if (returnValue !== undefined || position < inputLength) {
|
|
@@ -929,7 +947,7 @@ const isSafari = typeof navigator !== 'undefined' && /Safari/.test(navigator.use
|
|
|
929
947
|
const oldNode = typeof process !== 'undefined' && process.version.startsWith('v4.')
|
|
930
948
|
|
|
931
949
|
function needsCustomParser (options) {
|
|
932
|
-
return options.ignoreComments || options.ignoreTrailingCommas ||
|
|
950
|
+
return options.ignoreBOM || options.ignoreComments || options.ignoreTrailingCommas ||
|
|
933
951
|
options.allowSingleQuotedStrings || options.allowDuplicateObjectKeys === false ||
|
|
934
952
|
options.mode === 'cjson' || options.mode === 'json5' || isSafari || oldNode
|
|
935
953
|
}
|
package/lib/validator.js
CHANGED
|
@@ -148,6 +148,7 @@
|
|
|
148
148
|
const ajv = createAjv(environment)
|
|
149
149
|
const parseOptions = {
|
|
150
150
|
mode: options.mode,
|
|
151
|
+
ignoreBOM: options.ignoreBOM,
|
|
151
152
|
ignoreComments: options.ignoreComments,
|
|
152
153
|
ignoreTrailingCommas: options.ignoreTrailingCommas,
|
|
153
154
|
allowSingleQuotedStrings: options.allowSingleQuotedStrings,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prantlf/jsonlint",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.7.0",
|
|
4
4
|
"description": "JSON/CJSON/JSON5 parser, syntax and schema validator and pretty-printer.",
|
|
5
5
|
"author": "Ferdinand Prantl <prantlf@gmail.com> (http://prantl.tk)",
|
|
6
6
|
"contributors": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"url": "https://github.com/prantlf/jsonlint/blob/master/LICENSE"
|
|
17
17
|
}
|
|
18
18
|
],
|
|
19
|
-
"homepage": "http://prantlf.github.
|
|
19
|
+
"homepage": "http://prantlf.github.io/jsonlint/",
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
22
|
"url": "https://github.com/prantlf/jsonlint.git"
|
|
@@ -76,28 +76,28 @@
|
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"ajv": "6.12.6",
|
|
79
|
-
"commander": "9.
|
|
79
|
+
"commander": "9.4.0",
|
|
80
80
|
"cosmiconfig": "7.0.1",
|
|
81
|
-
"diff": "5.
|
|
82
|
-
"fast-glob": "3.2.
|
|
81
|
+
"diff": "5.1.0",
|
|
82
|
+
"fast-glob": "3.2.12"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@semantic-release/changelog": "6.0.1",
|
|
86
86
|
"@semantic-release/git": "10.0.1",
|
|
87
|
-
"@types/node": "
|
|
88
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
89
|
-
"@typescript-eslint/parser": "5.
|
|
90
|
-
"eslint": "8.
|
|
87
|
+
"@types/node": "18.7.21",
|
|
88
|
+
"@typescript-eslint/eslint-plugin": "5.38.0",
|
|
89
|
+
"@typescript-eslint/parser": "5.38.0",
|
|
90
|
+
"eslint": "8.24.0",
|
|
91
91
|
"eslint-config-standard": "17.0.0",
|
|
92
92
|
"eslint-plugin-import": "2.26.0",
|
|
93
|
-
"eslint-plugin-n": "15.
|
|
94
|
-
"eslint-plugin-promise": "6.0.
|
|
95
|
-
"http-server": "14.1.
|
|
93
|
+
"eslint-plugin-n": "15.3.0",
|
|
94
|
+
"eslint-plugin-promise": "6.0.1",
|
|
95
|
+
"http-server": "14.1.1",
|
|
96
96
|
"js-yaml": "4.1.0",
|
|
97
97
|
"nyc": "15.1.0",
|
|
98
|
-
"terser": "5.
|
|
98
|
+
"terser": "5.15.0",
|
|
99
99
|
"test": "0.6.0",
|
|
100
|
-
"typescript": "4.
|
|
100
|
+
"typescript": "4.8.3"
|
|
101
101
|
},
|
|
102
102
|
"keywords": [
|
|
103
103
|
"json",
|