Skip to content

Commit b64dc26

Browse files
committed
feat: Upgrade jsonlint to get better JSON Schema support
BREAKING CHANGE: Dropped support for Node.js 12 . The minimum supported version is Node.js 14. * The default environment recognises only JSON Schema drafts 06 and 07 automatically. Not 04 any more. The environment for JSON Schema drafts 04 has to be selected explicitly. Also, JSON Schema drafts 06 and 07 are handled by AJV@8 instead of AJV@6. It shouldn't make any difference, but the implementation is new and could perform a stricter validation.
1 parent 9a7cbf1 commit b64dc26

File tree

6 files changed

+585
-313
lines changed

6 files changed

+585
-313
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout Sources
12-
uses: actions/checkout@v2
12+
uses: actions/checkout@v3
1313
- name: Install Node
14-
uses: actions/setup-node@v2
14+
uses: actions/setup-node@v3
1515
with:
1616
node-version: 'lts/*'
1717
registry-url: 'https://registry.npmjs.org'
1818
- name: Install PNPM
1919
uses: pnpm/action-setup@v2
2020
with:
21-
version: '>=6'
21+
version: latest
2222
run_install: |
23-
- args: [--frozen-lockfile, --no-verify-store-integrity, --no-optional]
23+
- args: [--frozen-lockfile, --no-verify-store-integrity]
2424
- name: Test
2525
run: npm test
2626
- name: Coverage
27-
run: pnpx codecov --disable=gcov
27+
uses: codecov/codecov-action@v3
2828
- name: Publish
2929
uses: cycjimmy/semantic-release-action@v2
3030
with:
31-
semantic_version: 18
31+
semantic_version: 19
3232
branches: master
3333
env:
3434
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
This is a fork of the original package with the following enhancements:
1111

1212
* Validates with both [JSON] and [JSON5] standards.
13-
* Supports [JSON Schema] drafts 04, 06 and 07.
13+
* Supports [JSON Schema] drafts 04, 06, 07, 2019-09 and 2020-12.
14+
* Supports [JSON Type Definition].
1415
* Optionally recognizes JavaScript-style comments and single quoted strings.
1516
* Optionally ignores trailing commas and reports duplicate object keys as an error.
1617
* Can sort object keys alphabetically.
@@ -109,18 +110,18 @@ Options can be passed as keys in an object to the `jsonlint` function. The follo
109110

110111
#### Schema Validation
111112

112-
You can validate JSON files using JSON Schema drafts 04, 06 or 07, if you specify the schema in addition to other options:
113+
You can validate JSON files using [JSON Schema] drafts 04, 06, 07, 2019-09 or 2020-12, or using [JSON Type Definition] if you specify the schema in addition to other options:
113114

114115
jsonlint({
115116
schema: {
116117
src: 'some/manifest-schema.json',
117-
environment: 'json-schema-draft-04'
118+
environment: 'draft-04'
118119
}
119120
})
120121

121122
* `schema`, when set the source file will be validated using ae JSON Schema in addition to the syntax checks
122-
* `src`, when filled with a file path, the file will be used as a source of the JSON Schema
123-
* `environment`, can specify the version of the JSON Schema draft to use for validation: "json-schema-draft-04", "json-schema-draft-06" or "json-schema-draft-07" (if not set, the schema draft version will be inferred automatically)
123+
* `src`, when filled with one or more file paths, the files will be used as a source of the JSON Schema
124+
* `environment`, can specify the version of the JSON Schema draft to use for validation: "draft-04", "draft-06", "draft-07", "draft-2019-09", "draft-2020-12" or "jtd" (if not set, the supported schema draft versions will be 06 and 07)
124125

125126
### jsonlint.reporter(customReporter)
126127

@@ -274,5 +275,6 @@ Licensed under the [MIT License].
274275
[JSON]: https://tools.ietf.org/html/rfc8259
275276
[JSON5]: https://spec.json5.org
276277
[JSON Schema]: https://json-schema.org
278+
[JSON Type Definition]: https://jsontypedef.com/
277279

278280
[gulpfile.js]: ./gulpfile.js

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
var fs = require('fs')
3+
var { readFile } = require('fs/promises')
44
var mapStream = require('map-stream')
55
var colors = require('ansi-colors')
66
var jsonlint = require('@prantlf/jsonlint')
@@ -103,14 +103,14 @@ var jsonLintPlugin = function(options) {
103103
if (schemaContent) {
104104
validateSchema(data, file, finish)
105105
} else {
106-
fs.readFile(schema.src, 'utf-8', function(error, fileContent) {
107-
if (error) {
108-
finish(error)
109-
} else {
110-
schemaContent = fileContent
106+
const schemas = Array.isArray(schema.src) ? schema.src : [schema.src]
107+
Promise
108+
.all(schemas.map(schema => readFile(schema, 'utf-8')))
109+
.then(content => {
110+
schemaContent = content
111111
validateSchema(data, file, finish)
112-
}
113-
})
112+
})
113+
.catch(error => finish(error))
114114
}
115115
}
116116

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"lib"
2727
],
2828
"engines": {
29-
"node": ">=6"
29+
"node": ">=14"
3030
},
3131
"scripts": {
3232
"pretest": "npm run lint",
@@ -43,27 +43,27 @@
4343
]
4444
},
4545
"dependencies": {
46-
"@prantlf/jsonlint": "11.6.0",
47-
"ansi-colors": "4.1.1",
46+
"@prantlf/jsonlint": "14.0.0",
47+
"ansi-colors": "4.1.3",
4848
"fancy-log": "2.0.0",
4949
"map-stream": "0.0.7",
50-
"plugin-error": "1.0.1",
50+
"plugin-error": "2.0.1",
5151
"through2": "4.0.2"
5252
},
5353
"devDependencies": {
54-
"c8": "7.11.2",
55-
"eslint": "8.14.0",
54+
"c8": "7.13.0",
55+
"eslint": "8.35.0",
5656
"eslint-config-standard": "17.0.0",
57-
"eslint-plugin-import": "2.26.0",
58-
"eslint-plugin-n": "15.2.0",
57+
"eslint-plugin-import": "2.27.5",
58+
"eslint-plugin-n": "15.6.1",
5959
"eslint-plugin-node": "11.1.0",
60-
"eslint-plugin-promise": "6.0.0",
60+
"eslint-plugin-promise": "6.1.1",
6161
"eslint-plugin-standard": "4.1.0",
6262
"gulp": "4.0.2",
63-
"mocha": "10.0.0",
64-
"prettier": "2.6.2",
63+
"mocha": "10.2.0",
64+
"prettier": "2.8.4",
6565
"should": "13.2.3",
66-
"vinyl": "2.2.1"
66+
"vinyl": "3.0.0"
6767
},
6868
"keywords": [
6969
"gulpplugin",

0 commit comments

Comments
 (0)