Permalink
Browse files

Improve test coverage (100%), add changelog and minor JSON change.

  • Loading branch information...
1 parent 6ae9db4 commit bb7ce6c301842d67e1d399a1b6f26657f60fa32b @tmcw tmcw committed Oct 21, 2013
View
@@ -0,0 +1,5 @@
+## 0.2.0
+
+* JSON parse errors are now parsed and output as objects rather than raw
+ errors with strings.
+* Stricter checking of LinearRing and Line coordinate length.
View
@@ -15,13 +15,17 @@ var fs = require('fs'),
var errors = geojsonhint.hint(fs.readFileSync(argv._[0], 'utf8'));
if (errors) {
- if (errors instanceof Error) {
- console.log('invalid JSON');
- throw errors;
- }
if (argv.json) {
- console.log(JSON.stringify(errors, null, 2));
+ if (errors instanceof Error) {
+ console.log(JSON.stringify(errors.toString(), null, 2));
+ } else {
+ console.log(JSON.stringify(errors, null, 2));
+ }
} else {
+ if (errors instanceof Error) {
+ console.log('invalid JSON');
+ throw errors;
+ }
errors.forEach(function(e) {
console.log('line %s, %s', (''+e.line), e.message.red);
});
View
@@ -96,13 +96,6 @@ function hint(str) {
if (depth === 0) {
return position(coords, line);
} else {
- if (!Array.isArray(coords)) {
- return errors.push({
- message: 'coordinates should be an array, are an ' + (typeof coords) +
- 'instead',
- line: line
- });
- }
if (depth === 1 && type) {
if (type === 'LinearRing' && coords.length < 4) {
errors.push({
@@ -258,7 +251,14 @@ function hint(str) {
try {
gj = jsonlint.parse(str);
} catch(e) {
- return e;
+ var match = e.message.match(/line (\d+)/),
+ lineNumber = 0;
+ if (match) lineNumber = parseInt(match[1], 10);
+ return {
+ line: lineNumber,
+ message: e.message,
+ error: e
+ };
}
if (typeof gj !== 'object' ||
@@ -0,0 +1,4 @@
+{
+ "type": "MultiPoint"
+ "coordinates": [["foo", "bar"]]
+}
@@ -0,0 +1,5 @@
+{
+ "line": 2,
+ "message": "Parse error on line 2:\n...\": \"MultiPoint\" \"coordinates\": [[\"fo\n----------------------^\nExpecting 'EOF', '}', ':', ',', ']', got 'STRING'",
+ "error": {}
+}
@@ -0,0 +1,8 @@
+{
+ "crs": {
+ "type": 10,
+ "properties": { }
+ },
+ "type": "Point",
+ "coordinates": [2, 2]
+}
@@ -0,0 +1,6 @@
+[
+ {
+ "message": "\"type\" property should be string, but is an number instead",
+ "line": 2
+ }
+]
@@ -0,0 +1,8 @@
+{
+ "crs": {
+ "type": "link",
+ "properties": { }
+ },
+ "type": "Point",
+ "coordinates": [2, 2]
+}
@@ -0,0 +1,6 @@
+[
+ {
+ "message": "\"href\" property required",
+ "line": 4
+ }
+]
@@ -0,0 +1,8 @@
+{
+ "crs": {
+ "type": "name",
+ "properties": {}
+ },
+ "type": "Point",
+ "coordinates": [2, 2]
+}
@@ -0,0 +1,6 @@
+[
+ {
+ "message": "\"name\" property required",
+ "line": 4
+ }
+]

0 comments on commit bb7ce6c

Please sign in to comment.