Skip to content

Commit

Permalink
differentiate errors from warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
perrygeo committed Jul 7, 2016
1 parent fa8fd26 commit c35d9b0
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 19 deletions.
28 changes: 22 additions & 6 deletions bin/geojsonhint
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,39 @@ function hint(input) {
console.log(chalk.red('invalid JSON'));
throw errors;
}
var nWarnings = 0;
var nErrors = 0;
var output = table(errors.map(function(e) {
return [
e.line + ':',
chalk.red(e.message)
];
if (e.level === "warn") {
nWarnings += 1;
return [
e.line + ':',
chalk.yellow(e.message)
];
} else {
// Assume "error" level by default
nErrors += 1;
return [
e.line + ':',
chalk.red(e.message)
];
}
}), {
align: ['r', 'l']
}) + '\n\n' + errors.length + ' ' + pluralize('error', errors.length);
})
output += '\n\n' + nErrors + ' ' + chalk.red(pluralize('error', nErrors));
output += '\n' + nWarnings + ' ' + chalk.yellow(pluralize('warning', nWarnings));
console.log(output);
} else if (format === 'compact') {
if (errors instanceof Error) {
console.log(chalk.red('invalid JSON'));
throw errors;
}
var filePart = filename ? filename + ': ' : '';
var level;
errors.forEach(function(e) {
console.log(filePart + 'line ' + e.line + ' - ' + e.message);
level = e.level ? e.level : "error";
console.log(filePart + 'line ' + e.line + ' - ' + e.message + " - " + level);
});
} else {
throw new Error('Format unknown');
Expand Down
6 changes: 6 additions & 0 deletions object.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ function hint(gj, options) {
if (precision > maxPrecision) {
return errors.push({
message: "precision of coordinates should be reduced",
level: "warn",
line: _.__line__ || line
});
}
Expand Down Expand Up @@ -212,6 +213,7 @@ function hint(gj, options) {
if (!rhr) {
errors.push({
message: 'Polygons and MultiPolygons should follow the right-hand rule',
level: 'warn',
line: geometry.__line__
});
}
Expand Down Expand Up @@ -252,11 +254,13 @@ function hint(gj, options) {
if (typeof _.crs === 'object' && _.crs.properties && _.crs.properties.name === defaultCRSName) {
errors.push({
message: "old-style crs member is not recommended, this object is equivalent to the default and should be removed",
level: "warn",
line: _.__line__
});
} else {
errors.push({
message: "old-style crs member is not recommended",
level: "warn",
line: _.__line__
});
}
Expand Down Expand Up @@ -379,6 +383,7 @@ function hint(gj, options) {
if (geometryCollection.geometries.length == 1) {
errors.push({
message: 'GeometryCollection with a single geometry should be avoided in favor of single part or a single object of multi-part type',
level: 'warn',
line: geometryCollection.geometries.__line__
});
}
Expand All @@ -387,6 +392,7 @@ function hint(gj, options) {
if (geometry.type === "GeometryCollection") {
errors.push({
message: "GeometryCollection should avoid nested geometry collections",
level: 'warn',
line: geometryCollection.geometries.__line__
});
}
Expand Down
1 change: 1 addition & 0 deletions test/data/bad/bad-polygonloop.result
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,7 @@
},
{
"message": "Polygons and MultiPolygons should follow the right-hand rule",
"level": "warn",
"line": 2
}
]
3 changes: 2 additions & 1 deletion test/data/bad/bad-polygonloop.result-object
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,7 @@
"message": "a number was found where a coordinate array should have been found: this needs to be nested more deeply"
},
{
"message": "Polygons and MultiPolygons should follow the right-hand rule"
"message": "Polygons and MultiPolygons should follow the right-hand rule",
"level": "warn"
}
]
2 changes: 1 addition & 1 deletion test/data/bad/crs_nolongervalidtype.result
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"old-style crs member is not recommended","line":1}]
[{"message":"old-style crs member is not recommended","line":1,"level":"warn"}]
2 changes: 1 addition & 1 deletion test/data/bad/crs_nolongervalidtype.result-object
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"old-style crs member is not recommended"}]
[{"message":"old-style crs member is not recommended","level":"warn"}]
2 changes: 1 addition & 1 deletion test/data/bad/crs_notvalid_evencrs84.result
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"old-style crs member is not recommended, this object is equivalent to the default and should be removed","line":1}]
[{"message":"old-style crs member is not recommended, this object is equivalent to the default and should be removed","line":1,"level":"warn"}]
2 changes: 1 addition & 1 deletion test/data/bad/crs_notvalid_evencrs84.result-object
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"old-style crs member is not recommended, this object is equivalent to the default and should be removed"}]
[{"message":"old-style crs member is not recommended, this object is equivalent to the default and should be removed","level":"warn"}]
2 changes: 1 addition & 1 deletion test/data/bad/excessive_precision.result
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"precision of coordinates should be reduced","line":1}]
[{"message":"precision of coordinates should be reduced","level":"warn","line":1}]
2 changes: 1 addition & 1 deletion test/data/bad/excessive_precision.result-object
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"precision of coordinates should be reduced"}]
[{"message":"precision of coordinates should be reduced","level":"warn"}]
2 changes: 1 addition & 1 deletion test/data/bad/geometrycollection_nested.result
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"GeometryCollection should avoid nested geometry collections","line":2}]
[{"message":"GeometryCollection should avoid nested geometry collections","level":"warn","line":2}]
2 changes: 1 addition & 1 deletion test/data/bad/geometrycollection_nested.result-object
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"GeometryCollection should avoid nested geometry collections"}]
[{"message":"GeometryCollection should avoid nested geometry collections","level":"warn"}]
2 changes: 1 addition & 1 deletion test/data/bad/geometrycollection_single.result
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"GeometryCollection with a single geometry should be avoided in favor of single part or a single object of multi-part type","line":2}]
[{"message":"GeometryCollection with a single geometry should be avoided in favor of single part or a single object of multi-part type","level":"warn","line":2}]
2 changes: 1 addition & 1 deletion test/data/bad/geometrycollection_single.result-object
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"GeometryCollection with a single geometry should be avoided in favor of single part or a single object of multi-part type"}]
[{"message":"GeometryCollection with a single geometry should be avoided in favor of single part or a single object of multi-part type","level":"warn"}]
2 changes: 1 addition & 1 deletion test/data/bad/polygon_winding_order.result
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"Polygons and MultiPolygons should follow the right-hand rule","line":1}]
[{"message":"Polygons and MultiPolygons should follow the right-hand rule","level":"warn","line":1}]
2 changes: 1 addition & 1 deletion test/data/bad/polygon_winding_order.result-object
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"Polygons and MultiPolygons should follow the right-hand rule"}]
[{"message":"Polygons and MultiPolygons should follow the right-hand rule","level":"warn"}]

0 comments on commit c35d9b0

Please sign in to comment.