Skip to content

Commit

Permalink
feat: Upgrade jsonlint to get better JSON Schema support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
prantlf committed Mar 5, 2023
1 parent 7469db7 commit 1de372b
Show file tree
Hide file tree
Showing 8 changed files with 605 additions and 489 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Sources
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'
- name: Install PNPM
uses: pnpm/action-setup@v2
with:
version: '>=6'
version: latest
run_install: |
- args: [--frozen-lockfile, --no-verify-store-integrity, --no-optional]
- args: [--frozen-lockfile, --no-verify-store-integrity]
- name: Test
run: npm test
- name: Coverage
run: pnpx codecov --disable=gcov
uses: codecov/codecov-action@v3
- name: Publish
uses: cycjimmy/semantic-release-action@v2
with:
semantic_version: 18
semantic_version: 19
branches: master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = (grunt) => {
src: [ 'test/3.json' ],
options: {
schema: {
environment: 'draft-04',
src: 'test/3.schema.json'
}
}
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ Validates [JSON]/[JSON5] files from [`Grunt`] using [`JSONLint`].

This is a fork of the original package with the following enhancements:

* Supports [JSON Schema] drafts 04, 06 and 07.
* Supports [JSON Schema] drafts 04, 06, 07, 2019-09 and 2020-12.
* Supports [JSON Type Definition].
* Optionally recognizes JavaScript-style comments and single quoted strings.
* Optionally ignores trailing commas and reports duplicate object keys as an error.
* Can sort object keys alphabetically.
* Offers pretty-printing including comment-stripping and object keys without quotes (JSON5).
* Prefers using the 7x faster native JSON parser, if possible.
* Prefers using the 10x faster native JSON parser, if possible.
* Formats column number of error occurrences too, does not report error location twice.
* Prints the same rich error information for schema validation.
* Depends on up-to-date npm modules with no installation warnings.
Expand Down Expand Up @@ -108,23 +109,23 @@ Add [parsing options](#customizing) to these formatting options as you need.

## Schema Validation

You can validate JSON files using [JSON Schema] drafts 04, 06 or 07:
You can validate JSON files using [JSON Schema] drafts 04, 06, 07, 2019-09 or 2020-12, or using JSON Type Definition:

jsonlint: {
all: {
src: [ 'some/manifest.json' ],
options: {
schema: {
src: 'some/manifest-schema.json',
environment: 'json-schema-draft-04'
environment: 'draft-04'
}
}
}
}

* `schema`, when set the source file will be validated using ae JSON Schema in addition to the syntax checks
* `src`, when filled with a file path, the file will be used as a source of the JSON Schema
* `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)
* `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)

## Reporting

Expand Down Expand Up @@ -206,3 +207,4 @@ Licensed under the [MIT License].
[JSON]: https://tools.ietf.org/html/rfc8259
[JSON5]: https://spec.json5.org
[JSON Schema]: https://json-schema.org
[JSON Type Definition]: https://jsontypedef.com/
5 changes: 3 additions & 2 deletions lib/grunt-jsonlint-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ module.exports = function makeTask(grunt, jsonlint, validator, sorter, printer)
// Parse JSON data from string by the schema validator to get
// error messages including the location in the source string.
if (schema.src) {
const parsedSchema = grunt.file.read(schema.src);
const validate = validator.compile(parsedSchema, parserOptions);
let schemas = Array.isArray(schema.src) ? schema.src : [ schema.src ];
schemas = schemas.map((file) => grunt.file.read(file));
const validate = validator.compile(schemas, parserOptions);
return validate(data, parserOptions);
}
return jsonlint.parse(data, parserOptions);
Expand Down
24 changes: 11 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"tasks"
],
"engines": {
"node": ">=6"
"node": ">=14"
},
"scripts": {
"lint": "eslint --fix tasks/ lib/ test/*.js",
Expand All @@ -41,25 +41,23 @@
]
},
"dependencies": {
"@prantlf/jsonlint": "11.6.0"
"@prantlf/jsonlint": "14.0.0"
},
"devDependencies": {
"async": "3.2.3",
"c8": "7.11.2",
"eslint": "8.14.0",
"async": "3.2.4",
"c8": "7.13.0",
"eslint": "8.35.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-import": "2.27.5",
"expect.js": "0.3.1",
"fs-writefile-promise": "3.0.2",
"grunt": "1.5.2",
"grunt-eslint": "24.0.0",
"grunt": "1.6.1",
"grunt-eslint": "24.0.1",
"grunt-mocha-test": "0.13.3",
"jshint": "2.13.4",
"jshint": "2.13.6",
"lodash": "4.17.21",
"mkdirp-promise": "5.0.1",
"mocha": "10.0.0",
"promise": "8.1.0",
"sinon": "13.0.2",
"mocha": "10.2.0",
"sinon": "15.0.1",
"sinon-expect": "0.3.0"
},
"keywords": [
Expand Down
Loading

0 comments on commit 1de372b

Please sign in to comment.