@prantlf/jsonlint 11.2.1 → 11.5.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 +149 -59
- package/lib/cli.js +168 -24
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -14,13 +14,15 @@ This is a fork of the original project ([zaach/jsonlint](https://github.com/zaac
|
|
|
14
14
|
* Provides 100% compatible interface to the native `JSON.parse` method.
|
|
15
15
|
* Optionally recognizes JavaScript-style comments (CJSON) and single quoted strings (JSON5).
|
|
16
16
|
* Optionally ignores trailing commas and reports duplicate object keys as an error.
|
|
17
|
+
* Optionally checks that also the expected format matches, including sorted object keys.
|
|
17
18
|
* Supports [JSON Schema] drafts 04, 06 and 07.
|
|
18
19
|
* Offers pretty-printing including comment-stripping and object keys without quotes (JSON5).
|
|
19
20
|
* Prefers the native JSON parser if possible to run [7x faster than the custom parser].
|
|
20
|
-
* Reports errors with rich additional information. From the
|
|
21
|
-
*
|
|
21
|
+
* Reports errors with rich additional information. From the JSON Schema validation too.
|
|
22
|
+
* Consumes configuration from both command line and [configuration files](configuration).
|
|
23
|
+
* Implements JavaScript modules using [UMD] to work in Node.js, in a browser, everywhere.
|
|
22
24
|
* Depends on up-to-date npm modules with no installation warnings.
|
|
23
|
-
* Small size - 18.
|
|
25
|
+
* Small size - 18.7 kB minified, 6.54 kB gzipped, 5.16 kB brotlied.
|
|
24
26
|
|
|
25
27
|
**Note:** In comparison with the original project, this package exports only the `parse` method; not the `Parser` object.
|
|
26
28
|
|
|
@@ -52,9 +54,11 @@ Example of an error message:
|
|
|
52
54
|
|
|
53
55
|
## Command-line Interface
|
|
54
56
|
|
|
55
|
-
Install `jsonlint` with `npm
|
|
57
|
+
Install `jsonlint` with `npm`, `pnpm` or `yarn` globally to be able to use the command-line interface in any directory:
|
|
56
58
|
|
|
57
|
-
npm i @prantlf/jsonlint
|
|
59
|
+
npm i -g @prantlf/jsonlint
|
|
60
|
+
pnpm i -g @prantlf/jsonlint
|
|
61
|
+
yarn add --global @prantlf/jsonlint
|
|
58
62
|
|
|
59
63
|
Validate a single file:
|
|
60
64
|
|
|
@@ -64,64 +68,150 @@ or pipe the JSON input into `stdin`:
|
|
|
64
68
|
|
|
65
69
|
cat myfile.json | jsonlint
|
|
66
70
|
|
|
67
|
-
or process all `.json` files in a directory:
|
|
71
|
+
or process all `.json` files in a directory and rewriting them with the pretty-printed output:
|
|
68
72
|
|
|
69
|
-
jsonlint mydir
|
|
73
|
+
jsonlint --in-place --pretty-print mydir
|
|
70
74
|
|
|
71
75
|
By default, `jsonlint` will either report a syntax error with details or pretty-print the source if it is valid.
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
77
|
+
A more complex example: check all JSON files in a Node.js project, except for dependencies in `node_modules`, allow comments (CJSON) and trailing commas, forbid duplicated object keys, print processed files names on the console, print errors on a single line and if an error occurs, continue with other files:
|
|
78
|
+
|
|
79
|
+
jsonlint --comments --trailing-commas --no-duplicate-keys \
|
|
80
|
+
--log-files --compact --continue '**/*.json' '!**/node_modules'
|
|
81
|
+
|
|
82
|
+
The same parameters can be passed from a configuration file:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"comments": true,
|
|
87
|
+
"trailing-commas": true,
|
|
88
|
+
"duplicate-keys": false,
|
|
89
|
+
"log-files": true,
|
|
90
|
+
"compact": true,
|
|
91
|
+
"continue": true,
|
|
92
|
+
"patterns": ["**/*.json", "!**/node_modules"]
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The input can be checked not only to be a valid JSON, but also to be formatted according to the coding standard. For example, check that there is a trailing li break in each JSON file, in addition to alphabetically sorted keys and no duplicate keys:
|
|
97
|
+
|
|
98
|
+
$ jsonlint -ksDr *.json
|
|
99
|
+
|
|
100
|
+
File: package.json
|
|
101
|
+
Formatted output differs
|
|
102
|
+
===================================================================
|
|
103
|
+
--- package.json.orig
|
|
104
|
+
+++ package.json
|
|
105
|
+
@@ -105,4 +105,4 @@
|
|
106
|
+
"lint",
|
|
107
|
+
"jsonlint"
|
|
108
|
+
]
|
|
109
|
+
-}
|
|
110
|
+
+}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
### Usage
|
|
114
|
+
|
|
115
|
+
Usage: `jsonlint [options] [<file, directory, pattern> ...]`
|
|
116
|
+
|
|
117
|
+
#### Options
|
|
118
|
+
|
|
119
|
+
-f, --config [file] read options from a custom configuration file
|
|
120
|
+
-F, --no-config disable searching for configuration file
|
|
121
|
+
-s, --sort-keys sort object keys (not when prettifying)
|
|
122
|
+
-E, --extensions [ext] file extensions to process for directory walk
|
|
123
|
+
(default: ["json","JSON"])
|
|
124
|
+
-i, --in-place overwrite the input files
|
|
125
|
+
-j, --diff print difference instead of writing the output
|
|
126
|
+
-k, --check check that the input is equal to the output
|
|
127
|
+
-t, --indent [num|char] number of spaces or specific characters
|
|
128
|
+
to use for indentation (default: 2)
|
|
129
|
+
-c, --compact compact error display
|
|
130
|
+
-M, --mode [mode] set other parsing flags according to a format
|
|
131
|
+
type (default: "json")
|
|
132
|
+
-C, --comments recognize and ignore JavaScript-style comments
|
|
133
|
+
-S, --single-quoted-strings support single quotes as string delimiters
|
|
134
|
+
-T, --trailing-commas ignore trailing commas in objects and arrays
|
|
135
|
+
-D, --no-duplicate-keys report duplicate object keys as an error
|
|
136
|
+
-V, --validate [file] JSON schema file to use for validation
|
|
137
|
+
-e, --environment [env] which specification of JSON Schema the
|
|
138
|
+
validation file uses
|
|
139
|
+
-l, --log-files print only the parsed file names to stdout
|
|
140
|
+
-q, --quiet do not print the parsed json to stdout
|
|
141
|
+
-n, --continue continue with other files if an error occurs
|
|
142
|
+
-p, --pretty-print prettify the input instead of stringifying
|
|
143
|
+
the parsed object
|
|
144
|
+
-P, --pretty-print-invalid force pretty-printing even for invalid input
|
|
145
|
+
-r, --trailing-newline ensure a line break at the end of the output
|
|
146
|
+
-R, --no-trailing-newline ensure no line break at the end of the output
|
|
147
|
+
--prune-comments omit comments from the prettified output
|
|
148
|
+
--strip-object-keys strip quotes from object keys if possible
|
|
149
|
+
(JSON5)
|
|
150
|
+
--enforce-double-quotes surrounds all strings with double quotes
|
|
151
|
+
--enforce-single-quotes surrounds all strings with single quotes
|
|
152
|
+
(JSON5)
|
|
153
|
+
--trim-trailing-commas omit trailing commas from objects and arrays
|
|
154
|
+
(JSON5)
|
|
155
|
+
-v, --version output the version number
|
|
156
|
+
-h, --help output usage information
|
|
157
|
+
|
|
158
|
+
You can use BASH patterns for including and excluding files (only files).
|
|
159
|
+
Patterns are case-sensitive and have to use slashes as a path separators.
|
|
160
|
+
A pattern to exclude from processing starts with "!".
|
|
161
|
+
|
|
162
|
+
Parsing mode can be "cjson" or "json5" to enable other flags automatically.
|
|
163
|
+
If no files or directories are specified, stdin will be parsed. Environments
|
|
164
|
+
for JSON schema validation are "json-schema-draft-04", "json-schema-draft-06"
|
|
165
|
+
or "json-schema-draft-07". If not specified, it will be auto-detected.
|
|
166
|
+
|
|
167
|
+
### Configuration
|
|
168
|
+
|
|
169
|
+
In addition to the command line parameters, the options can be supplied from the following files:
|
|
170
|
+
|
|
171
|
+
package.json, key jsonlint
|
|
172
|
+
.jsonlintrc
|
|
173
|
+
.jsonlintrc.json
|
|
174
|
+
.jsonlintrc.yaml
|
|
175
|
+
.jsonlintrc.yml
|
|
176
|
+
.jsonlintrc.js
|
|
177
|
+
.jsonlintrc.cjs
|
|
178
|
+
jsonlint.config.js
|
|
179
|
+
jsonlint.config.cjs
|
|
180
|
+
|
|
181
|
+
The automatic search for one of the following locations above can be disabled by the command-line parameter `-F|--no-config`. A concrete configuration file can be specified by the command-line parameter `-f|--config [file]`. Parameters from the command line will have higher priority than parameters from a configuration file.
|
|
182
|
+
|
|
183
|
+
The configuration is an object with the following properties, described above, which can be entered either in the kebab-case or in the camel-case:
|
|
184
|
+
|
|
185
|
+
| Parameter | Alias |
|
|
186
|
+
| --------- | ----- |
|
|
187
|
+
| patterns | |
|
|
188
|
+
| sort-keys | sortKeys |
|
|
189
|
+
| extensions | |
|
|
190
|
+
| in-place | inPlace |
|
|
191
|
+
| diff | |
|
|
192
|
+
| check | |
|
|
193
|
+
| indent | |
|
|
194
|
+
| compact | |
|
|
195
|
+
| mode | |
|
|
196
|
+
| comments | |
|
|
197
|
+
| single-quoted-strings | singleQuotedStrings |
|
|
198
|
+
| trailing-commas | trailingCommas |
|
|
199
|
+
| duplicate-keys | duplicateKeys |
|
|
200
|
+
| validate | |
|
|
201
|
+
| environment | |
|
|
202
|
+
| log-files | logFiles |
|
|
203
|
+
| quiet | |
|
|
204
|
+
| continue | |
|
|
205
|
+
| pretty-print | prettyPrint |
|
|
206
|
+
| pretty-print-invalid | prettyPrintInvalid |
|
|
207
|
+
| trailing-newline | trailingNewline'
|
|
208
|
+
| prune-comments | pruneComments |
|
|
209
|
+
| strip-object-keys | stripObjectKeys |
|
|
210
|
+
| enforce-double-quotes | enforceDoubleQuotes |
|
|
211
|
+
| enforce-single-quotes | enforceSingleQuotes |
|
|
212
|
+
| trim-trailing-commas | trimTrailingCommas |
|
|
213
|
+
|
|
214
|
+
The parameter `config` will be ignored in configuration files. The extra parameter `patterns` can be set to an array of strings with paths or patterns instead of putting them to the command line.
|
|
125
215
|
|
|
126
216
|
## Module Interface
|
|
127
217
|
|
package/lib/cli.js
CHANGED
|
@@ -16,9 +16,13 @@ const commander = require('commander')
|
|
|
16
16
|
.name('jsonlint')
|
|
17
17
|
.usage('[options] [<file, directory, pattern> ...]')
|
|
18
18
|
.description(description)
|
|
19
|
+
.option('-f, --config [file]', 'read options from a custom configuration file')
|
|
20
|
+
.option('-F, --no-config', 'disable searching for configuration files')
|
|
19
21
|
.option('-s, --sort-keys', 'sort object keys (not when prettifying)')
|
|
20
22
|
.option('-E, --extensions [ext]', 'file extensions to process for directory walk', collectValues, ['json', 'JSON'])
|
|
21
23
|
.option('-i, --in-place', 'overwrite the input files')
|
|
24
|
+
.option('-j, --diff', 'print difference instead of writing the output')
|
|
25
|
+
.option('-k, --check', 'check that the input is equal to the output')
|
|
22
26
|
.option('-t, --indent [num|char]', 'number of spaces or specific characters to use for indentation', 2)
|
|
23
27
|
.option('-c, --compact', 'compact error display')
|
|
24
28
|
.option('-M, --mode [mode]', 'set other parsing flags according to a format type', 'json')
|
|
@@ -54,14 +58,69 @@ const commander = require('commander')
|
|
|
54
58
|
})
|
|
55
59
|
.parse(process.argv)
|
|
56
60
|
|
|
57
|
-
const
|
|
61
|
+
const paramNames = {
|
|
62
|
+
'trailing-commas': 'trailingCommas',
|
|
63
|
+
'single-quoted-strings': 'singleQuotedStrings',
|
|
64
|
+
'duplicate-keys': 'duplicateKeys',
|
|
65
|
+
'pretty-print': 'prettyPrint',
|
|
66
|
+
'prune-comments': 'pruneComments',
|
|
67
|
+
'strip-object-keys': 'stripObjectKeys',
|
|
68
|
+
'enforce-double-quotes': 'enforceDoubleQuotes',
|
|
69
|
+
'enforce-single-quotes': 'enforceSingleQuotes',
|
|
70
|
+
'trim-trailing-commas': 'trimTrailingCommas',
|
|
71
|
+
'sort-keys': 'sortKeys',
|
|
72
|
+
'pretty-print-invalid': 'prettyPrintInvalid',
|
|
73
|
+
'log-files': 'logFiles',
|
|
74
|
+
'in-place': 'inPlace',
|
|
75
|
+
'trailing-newline': 'trailingNewline'
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const params = commander.opts()
|
|
79
|
+
let options
|
|
80
|
+
if (params.config === false) {
|
|
81
|
+
options = params
|
|
82
|
+
} else {
|
|
83
|
+
const { cosmiconfigSync } = require('cosmiconfig')
|
|
84
|
+
const configurator = cosmiconfigSync('jsonlint')
|
|
85
|
+
const { config = {} } = (params.config && configurator.load(params.config)) ||
|
|
86
|
+
configurator.search() || {}
|
|
87
|
+
options = mergeOptions({}, convertConfig(config), params)
|
|
88
|
+
}
|
|
89
|
+
|
|
58
90
|
const extensions = options.extensions.map(extension => '.' + extension)
|
|
91
|
+
let reported
|
|
59
92
|
|
|
60
|
-
function
|
|
61
|
-
|
|
93
|
+
function convertConfig (config) {
|
|
94
|
+
const result = {}
|
|
95
|
+
for (const key in config) {
|
|
96
|
+
const name = paramNames[key] || key
|
|
97
|
+
result[name] = config[key]
|
|
98
|
+
}
|
|
99
|
+
return result
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function mergeOptions (target, ...sources) {
|
|
103
|
+
for (const source of sources) {
|
|
104
|
+
for (const key in source) {
|
|
105
|
+
if (target[key] == null) {
|
|
106
|
+
target[key] = source[key]
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return target
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function separateBlocks () {
|
|
114
|
+
if (reported) {
|
|
62
115
|
console.log()
|
|
116
|
+
} else {
|
|
117
|
+
reported = true
|
|
63
118
|
}
|
|
64
|
-
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function logNormalError (error, file) {
|
|
122
|
+
separateBlocks()
|
|
123
|
+
console.info('File:', file)
|
|
65
124
|
console.error(error.message)
|
|
66
125
|
}
|
|
67
126
|
|
|
@@ -147,24 +206,96 @@ function processContents (source, file) {
|
|
|
147
206
|
}
|
|
148
207
|
}
|
|
149
208
|
|
|
209
|
+
function ensureLineBreak (parsed, source) {
|
|
210
|
+
const lines = source.split(/\r?\n/)
|
|
211
|
+
const newLine = !lines[lines.length - 1]
|
|
212
|
+
if (options.trailingNewline === true ||
|
|
213
|
+
(options.trailingNewline !== false && newLine)) {
|
|
214
|
+
parsed += '\n'
|
|
215
|
+
}
|
|
216
|
+
return parsed
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function checkContents (file, source, parsed) {
|
|
220
|
+
const { createTwoFilesPatch, structuredPatch } = require('diff')
|
|
221
|
+
const structured = structuredPatch(`${file}.orig`, file, source, parsed, '', '', { context: 3 })
|
|
222
|
+
const length = structured.hunks && structured.hunks.length
|
|
223
|
+
const diff = createTwoFilesPatch(`${file}.orig`, file, source, parsed, '', '', { context: 3 })
|
|
224
|
+
if (length > 0) {
|
|
225
|
+
const hunk = length === 1 ? 'hunk differs' : 'hunks differ'
|
|
226
|
+
const message = `${length} ${hunk}`
|
|
227
|
+
if (options.compact) {
|
|
228
|
+
console.error(`${file}: ${message}`)
|
|
229
|
+
} else {
|
|
230
|
+
separateBlocks()
|
|
231
|
+
console.info('File:', file)
|
|
232
|
+
console.error(message)
|
|
233
|
+
}
|
|
234
|
+
if (!options.quiet) {
|
|
235
|
+
console.log(diff)
|
|
236
|
+
}
|
|
237
|
+
if (options.continue) {
|
|
238
|
+
process.exitCode = 1
|
|
239
|
+
} else {
|
|
240
|
+
process.exit(1)
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
if (options.compact) {
|
|
244
|
+
console.info(`${file}: no difference`)
|
|
245
|
+
} else if (options.logFiles) {
|
|
246
|
+
console.info(file)
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function diffContents (file, source, parsed) {
|
|
252
|
+
const { createTwoFilesPatch, structuredPatch } = require('diff')
|
|
253
|
+
const compact = options.quiet || options.compact
|
|
254
|
+
let diff, length
|
|
255
|
+
if (compact) {
|
|
256
|
+
diff = structuredPatch(`${file}.orig`, file, source, parsed, '', '', { context: 3 })
|
|
257
|
+
length = diff.hunks && diff.hunks.length
|
|
258
|
+
} else {
|
|
259
|
+
diff = createTwoFilesPatch(`${file}.orig`, file, source, parsed, '', '', { context: 3 })
|
|
260
|
+
length = diff.split(/\r?\n/).length - 4
|
|
261
|
+
}
|
|
262
|
+
if (length > 0) {
|
|
263
|
+
if (compact) {
|
|
264
|
+
const hunk = length === 1 ? 'hunk differs' : 'hunks differ'
|
|
265
|
+
console.info(`${file}: ${length} ${hunk}`)
|
|
266
|
+
} else {
|
|
267
|
+
separateBlocks()
|
|
268
|
+
console.info('File:', file)
|
|
269
|
+
console.log(diff)
|
|
270
|
+
}
|
|
271
|
+
} else {
|
|
272
|
+
if (options.compact) {
|
|
273
|
+
console.info(`${file}: no difference`)
|
|
274
|
+
} else if (options.logFiles) {
|
|
275
|
+
console.info(file)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
150
280
|
function processFile (file) {
|
|
151
281
|
file = normalize(file)
|
|
152
|
-
if (options.logFiles) {
|
|
153
|
-
console.
|
|
282
|
+
if (options.logFiles && !(options.compact || options.check || options.diff)) {
|
|
283
|
+
console.info(file)
|
|
154
284
|
}
|
|
155
|
-
const
|
|
156
|
-
|
|
285
|
+
const source = readFileSync(file, 'utf8')
|
|
286
|
+
const parsed = processContents(source, file)
|
|
157
287
|
if (options.inPlace) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (options.trailingNewline === true ||
|
|
161
|
-
(options.trailingNewline !== false && newLine)) {
|
|
162
|
-
source += '\n'
|
|
288
|
+
if (options.logFiles && options.compact) {
|
|
289
|
+
console.info(file)
|
|
163
290
|
}
|
|
164
|
-
writeFileSync(file, source)
|
|
291
|
+
writeFileSync(file, ensureLineBreak(parsed, source))
|
|
292
|
+
} else if (options.check) {
|
|
293
|
+
checkContents(file, source, ensureLineBreak(parsed, source))
|
|
294
|
+
} else if (options.diff) {
|
|
295
|
+
diffContents(file, source, ensureLineBreak(parsed, source))
|
|
165
296
|
} else {
|
|
166
297
|
if (!(options.quiet || options.logFiles)) {
|
|
167
|
-
console.log(
|
|
298
|
+
console.log(parsed)
|
|
168
299
|
}
|
|
169
300
|
}
|
|
170
301
|
}
|
|
@@ -187,27 +318,30 @@ function processSource (src, checkExtension) {
|
|
|
187
318
|
}
|
|
188
319
|
}
|
|
189
320
|
} catch ({ message }) {
|
|
190
|
-
console.
|
|
321
|
+
console.warn('WARN', message)
|
|
191
322
|
}
|
|
192
323
|
}
|
|
193
324
|
|
|
194
325
|
function processPatterns (patterns) {
|
|
195
326
|
const files = sync(patterns, { onlyFiles: true })
|
|
196
327
|
if (!files.length) {
|
|
197
|
-
console.
|
|
328
|
+
console.error('no files found')
|
|
198
329
|
process.exit(1)
|
|
199
330
|
}
|
|
200
331
|
for (const file of files) {
|
|
201
332
|
try {
|
|
202
333
|
processFile(file)
|
|
203
334
|
} catch ({ message }) {
|
|
204
|
-
console.
|
|
335
|
+
console.warn('WARN', message)
|
|
205
336
|
}
|
|
206
337
|
}
|
|
207
338
|
}
|
|
208
339
|
|
|
209
340
|
function main () {
|
|
210
|
-
|
|
341
|
+
let { args: files } = commander
|
|
342
|
+
if (!files.length) {
|
|
343
|
+
files = options.patterns || []
|
|
344
|
+
}
|
|
211
345
|
if (files.length) {
|
|
212
346
|
const dynamic = files.some(file => isDynamicPattern(file))
|
|
213
347
|
if (dynamic) {
|
|
@@ -225,12 +359,22 @@ function main () {
|
|
|
225
359
|
source += chunk.toString('utf8')
|
|
226
360
|
})
|
|
227
361
|
stdin.on('end', () => {
|
|
228
|
-
|
|
229
|
-
|
|
362
|
+
const file = '<stdin>'
|
|
363
|
+
if (options.logFiles && !(options.compact || options.check || options.diff)) {
|
|
364
|
+
console.info(file)
|
|
230
365
|
}
|
|
231
|
-
const parsed = processContents(source,
|
|
232
|
-
if (
|
|
233
|
-
|
|
366
|
+
const parsed = processContents(source, file)
|
|
367
|
+
if (options.check) {
|
|
368
|
+
checkContents(file, source, ensureLineBreak(parsed, source))
|
|
369
|
+
} else if (options.diff) {
|
|
370
|
+
diffContents(file, source, ensureLineBreak(parsed, source))
|
|
371
|
+
} else {
|
|
372
|
+
if (options.logFiles && options.compact) {
|
|
373
|
+
console.info(file)
|
|
374
|
+
}
|
|
375
|
+
if (!(options.quiet || options.logFiles)) {
|
|
376
|
+
console.log(parsed)
|
|
377
|
+
}
|
|
234
378
|
}
|
|
235
379
|
})
|
|
236
380
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prantlf/jsonlint",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.5.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": [
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"build": "npm run compile && npm run compile:tests",
|
|
46
46
|
"compile": "node scripts/bundle-jsonlint && terser -o web/jsonlint.min.js --source-map \"filename='jsonlint.js',url='jsonlint.min.js.map',includeSources=true\" lib/jsonlint.js && terser -o web/validator.min.js --source-map \"filename='validator.js',url='validator.min.js.map',includeSources=true\" lib/validator.js && terser -o web/formatter.min.js --source-map \"filename='formatter.js',url='formatter.min.js.map',includeSources=true\" lib/formatter.js && terser -o web/sorter.min.js --source-map \"filename='sorter.js',url='sorter.min.js.map',includeSources=true\" lib/sorter.js && terser -o web/printer.min.js --source-map \"filename='printer.js',url='printer.min.js.map',includeSources=true\" lib/printer.js && node scripts/bundle-schema-drafts && terser -o web/schema-drafts.min.js --source-map \"filename='schema-drafts.js',url='schema-drafts.min.js.map',includeSources=true\" lib/schema-drafts.js && terser -o web/ajv.min.js --source-map \"filename='ajv.js',url='ajv.min.js.map',includeSources=true\" node_modules/ajv/dist/ajv.bundle.js",
|
|
47
47
|
"compile:tests": "tsc --lib es6 test/typings.test.ts",
|
|
48
|
-
"test": "nyc --silent node test/typings.test.js && nyc --silent --no-clean node test/parse1 && nyc --silent --no-clean node test/parse1 --native-parser && nyc --silent --no-clean node test/parse2 && nyc --silent --no-clean node test/parse3 && nyc --silent --no-clean node test/parse4 && nyc --silent --no-clean node test/parse5 && nyc --silent --no-clean node test/portable && nyc --silent --no-clean node test/tokenize && nyc --silent --no-clean node test/print && nyc --silent --no-clean node lib/cli package.json test/recursive && nyc --silent --no-clean node lib/cli -sq test/passes/hasOwnProperty.json && nyc --silent --no-clean node lib/cli -s -e json-schema-draft-04 -V test/passes/3.schema.json test/passes/3.json && nyc --silent --no-clean node lib/cli -C test/passes/comments.txt && nyc --silent --no-clean node lib/cli -pS test/passes/strings.txt && nyc --silent --no-clean node lib/cli -M json5 test/passes/json5.text && nyc --silent --no-clean node lib/cli -v && nyc --silent --no-clean node lib/cli -h && nyc --silent --no-clean node lib/cli -Pc test/fails/10.json || nyc report",
|
|
48
|
+
"test": "nyc --silent node test/typings.test.js && nyc --silent --no-clean node test/parse1 && nyc --silent --no-clean node test/parse1 --native-parser && nyc --silent --no-clean node test/parse2 && nyc --silent --no-clean node test/parse3 && nyc --silent --no-clean node test/parse4 && nyc --silent --no-clean node test/parse5 && nyc --silent --no-clean node test/portable && nyc --silent --no-clean node test/tokenize && nyc --silent --no-clean node test/print && nyc --silent --no-clean node lib/cli package.json test/recursive && nyc --silent --no-clean node lib/cli -sq test/passes/hasOwnProperty.json && nyc --silent --no-clean node lib/cli -s -e json-schema-draft-04 -V test/passes/3.schema.json test/passes/3.json && nyc --silent --no-clean node lib/cli -C test/passes/comments.txt && nyc --silent --no-clean node lib/cli -pS test/passes/strings.txt && nyc --silent --no-clean node lib/cli -M json5 test/passes/json5.text && nyc --silent --no-clean node lib/cli -v && nyc --silent --no-clean node lib/cli -h && nyc --silent --no-clean node lib/cli -Pc test/fails/10.json || nyc --silent --no-clean node lib/cli -f test/.jsonrc.yml 'test/**/*.json' '!**/fails' && nyc report",
|
|
49
49
|
"start": "http-server -c 5",
|
|
50
50
|
"web": "npm run web:sync && npm run web:deploy",
|
|
51
51
|
"web:clone": "test ! -d ../jsonlint-pages && git clone --single-branch --branch gh-pages `git remote get-url origin` ../jsonlint-pages",
|
|
@@ -77,14 +77,16 @@
|
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"ajv": "6.12.6",
|
|
79
79
|
"commander": "9.2.0",
|
|
80
|
+
"cosmiconfig": "7.0.1",
|
|
81
|
+
"diff": "5.0.0",
|
|
80
82
|
"fast-glob": "3.2.11"
|
|
81
83
|
},
|
|
82
84
|
"devDependencies": {
|
|
83
|
-
"@semantic-release/changelog": "
|
|
84
|
-
"@semantic-release/git": "
|
|
85
|
-
"@types/node": "17.0.
|
|
86
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
87
|
-
"@typescript-eslint/parser": "5.
|
|
85
|
+
"@semantic-release/changelog": "6.0.1",
|
|
86
|
+
"@semantic-release/git": "10.0.1",
|
|
87
|
+
"@types/node": "17.0.31",
|
|
88
|
+
"@typescript-eslint/eslint-plugin": "5.22.0",
|
|
89
|
+
"@typescript-eslint/parser": "5.22.0",
|
|
88
90
|
"eslint": "8.14.0",
|
|
89
91
|
"eslint-config-standard": "17.0.0",
|
|
90
92
|
"eslint-plugin-import": "2.26.0",
|