Skip to content

Commit e5318eb

Browse files
committed
feat: Allow to continue processing in case of error
1 parent 91346d9 commit e5318eb

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ By default, `jsonlint` will either report a syntax error with details or pretty-
7474

7575
$ jsonlint -h
7676

77-
Usage: jsonlint [options] [<file or directory> ...]
77+
Usage: jsonlint [options] [<file, directory, pattern> ...]
7878

7979
JSON parser, syntax and schema validator and pretty-printer.
8080

@@ -97,6 +97,7 @@ By default, `jsonlint` will either report a syntax error with details or pretty-
9797
validation file uses
9898
-l, --log-files print only the parsed file names to stdout
9999
-q, --quiet do not print the parsed json to stdout
100+
-n, --continue continue with other files if an error occurs
100101
-p, --pretty-print prettify the input instead of stringifying
101102
the parsed object
102103
-P, --pretty-print-invalid force pretty-printing even for invalid input
@@ -113,6 +114,10 @@ By default, `jsonlint` will either report a syntax error with details or pretty-
113114
-v, --version output the version number
114115
-h, --help output usage information
115116

117+
You can use BASH patterns for including and excluding files (only files).
118+
Patterns are case-sensitive and have to use slashes as a path separators.
119+
A pattern to exclude from processing starts with "!".
120+
116121
Parsing mode can be "cjson" or "json5" to enable other flags automatically.
117122
If no files or directories are specified, stdin will be parsed. Environments
118123
for JSON schema validation are "json-schema-draft-04", "json-schema-draft-06"

lib/cli.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const collectValues = extension => extension.split(',')
1414

1515
const commander = require('commander')
1616
.name('jsonlint')
17-
.usage('[options] [<pattern> ...]')
17+
.usage('[options] [<file, directory, pattern> ...]')
1818
.description(description)
1919
.option('-s, --sort-keys', 'sort object keys (not when prettifying)')
2020
.option('-E, --extensions [ext]', 'file extensions to process for directory walk', collectValues, ['json', 'JSON'])
@@ -30,6 +30,7 @@ const commander = require('commander')
3030
.option('-e, --environment [env]', 'which specification of JSON Schema the validation file uses')
3131
.option('-l, --log-files', 'print only the parsed file names to stdout')
3232
.option('-q, --quiet', 'do not print the parsed json to stdout')
33+
.option('-n, --continue', 'continue with other files if an error occurs')
3334
.option('-p, --pretty-print', 'prettify the input instead of stringifying the parsed object')
3435
.option('-P, --pretty-print-invalid', 'force pretty-printing even for invalid input')
3536
.option('-r, --trailing-newline', 'ensure a line break at the end of the output')
@@ -57,6 +58,9 @@ const options = commander.opts()
5758
const extensions = options.extensions.map(extension => '.' + extension)
5859

5960
function logNormalError (error, file) {
61+
if (process.exitCode > 0) {
62+
console.log()
63+
}
6064
console.log('File:', file)
6165
console.error(error.message)
6266
}
@@ -135,7 +139,11 @@ function processContents (source, file) {
135139
logNormalError(e, file)
136140
}
137141
}
138-
process.exit(1)
142+
if (options.continue) {
143+
process.exitCode = 1
144+
} else {
145+
process.exit(1)
146+
}
139147
}
140148
}
141149

0 commit comments

Comments
 (0)