Skip to content

Commit b23948d

Browse files
committed
Merge remote-tracking branch 'origin/dev' into master, v0.4.6
2 parents 9f358c0 + 29743e0 commit b23948d

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

COMPARISON.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Here I'd like to give an overview of what the validators are capable of and what
1414

1515
| | Python Validator | PySTAC | STAC Node Validator |
1616
| :------------------------- | ------------------------------------------ | ------------------- | ------------------- |
17-
| Validator Version | 1.0.1 | 0.5.2 | 0.4.4 |
17+
| Validator Version | 1.0.1 | 0.5.2 | 0.4.6 |
1818
| Language | Python 3.6 | Python 3 | NodeJS |
1919
| CLI | Yes | No | Yes |
2020
| Programmatic | Yes | Yes | Planned |

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ See the [STAC Validator Comparison](COMPARISON.md) for the features supported by
66

77
## Versions
88

9-
**Current version: 0.4.5**
9+
**Current version: 0.4.6**
1010

1111
| STAC Node Validator Version | Supported STAC Versions |
1212
| --------------------------- | ----------------------- |
@@ -37,7 +37,7 @@ Further options to add to the commands above:
3737

3838
- To validate against schemas in a local STAC folder (e.g. `dev` branch): `--schemas /path/to/stac/folder`
3939
- To not verify SSL/TLS certificates: `--ignoreCerts`
40-
- To lint local JSON files: `--lint`
40+
- To lint local JSON files: `--lint` (add `--verbose` to get a diff with the changes required)
4141
- To format / pretty-print local JSON files: `--format` (Attention: this will override the source files without warning!)
4242

4343
**Note on API support:** Validating lists of STAC items/collections (i.e. `GET /collections` and `GET /collections/:id/items`) is partially supported.

index.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const klaw = require('klaw');
55
const path = require('path')
66
const minimist = require('minimist');
77
const compareVersions = require('compare-versions');
8+
const {diffStringsUnified} = require('jest-diff');
89

910
let DEBUG = false;
1011
let COMPILED = {};
@@ -91,15 +92,17 @@ async function run() {
9192
}
9293
}
9394
else {
94-
let fileContent = await fs.readFile(file);
95+
let fileContent = await fs.readFile(file, "utf8");
9596
json = JSON.parse(fileContent);
9697
if (doLint || doFormat) {
97-
// 2 spaces, *nix newlines, newline at end of file
98-
const expectedContent = JSON.stringify(json, null, 2).replace(/(\r\n|\r)/g, "\n") + "\n";
99-
if (fileContent !== expectedContent) {
98+
const expectedContent = JSON.stringify(json, null, 2);
99+
if (!matchFile(fileContent, expectedContent)) {
100100
stats.malformed++;
101101
if (doLint) {
102102
console.warn("--- Lint: File is malformed -> use `--format` to fix the issue");
103+
if (typeof args.verbose !== 'undefined') {
104+
console.log(diffStringsUnified(fileContent, expectedContent));
105+
}
103106
}
104107
if (doFormat) {
105108
console.warn("--- Format: File was malformed -> fixed the issue");
@@ -221,7 +224,8 @@ async function run() {
221224
if (doLint || doFormat) {
222225
console.info("Malformed: " + stats.malformed);
223226
}
224-
process.exit(stats.invalid);
227+
let errored = (stats.invalid > 0 || (doLint && !doFormat && stats.malformed > 0)) ? 1 : 0;
228+
process.exit(errored);
225229
}
226230
catch(error) {
227231
console.error(error);
@@ -231,6 +235,15 @@ async function run() {
231235

232236
const SUPPORTED_PROTOCOLS = ['http', 'https'];
233237

238+
function matchFile(given, expected) {
239+
return normalizeNewline(given) === normalizeNewline(expected);
240+
}
241+
242+
function normalizeNewline(str) {
243+
// 2 spaces, *nix newlines, newline at end of file
244+
return str.trimRight().replace(/(\r\n|\r)/g, "\n") + "\n";
245+
}
246+
234247
function isUrl(uri) {
235248
let part = uri.match(/^(\w+):\/\//i);
236249
if(part) {

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stac-node-validator",
3-
"version": "0.4.5",
3+
"version": "0.4.6",
44
"description": "STAC Validator for NodeJS",
55
"author": "Matthias Mohr",
66
"license": "Apache-2.0",
@@ -29,6 +29,7 @@
2929
"ajv": "^6.12.2",
3030
"compare-versions": "^3.6.0",
3131
"fs-extra": "^9.0.0",
32+
"jest-diff": "^26.6.2",
3233
"klaw": "^3.0.0",
3334
"minimist": "^1.2.5"
3435
}

0 commit comments

Comments
 (0)