mapbox/geojsonhint

Merge branch 'master' of github.com:mapbox/geojsonhint

2 parents 2b23cca + 317f5a3 commit 80bead59111c48211a27907ec7e091825bbca990 tmcw committed Nov 26, 2013
 @@ -65,6 +65,7 @@ Building the browser version: ## See Also +* [geojsonhint online](http://mapbox.github.io/geojsonhint/) * [grunt-geojsonhint](https://github.com/jieter/grunt-geojsonhint) does it as a Grunt task * [geojsonlint.com](http://geojsonlint.com/) does this server-side * [geojson-assert](https://github.com/calvinmetcalf/geojson-assert) does it in assertion tests
 @@ -97,11 +97,23 @@ function hint(str) { return position(coords, line); } else { if (depth === 1 && type) { - if (type === 'LinearRing' && coords.length < 4) { - errors.push({ - message: 'a LinearRing of coordinates needs to have four or more positions', - line: line - }); + if (type === 'LinearRing') { + if (coords.length < 4) { + errors.push({ + message: 'a LinearRing of coordinates needs to have four or more positions', + line: line + }); + } + if (coords.length && + (coords[coords.length - 1].length !== coords[0].length || + !coords[coords.length - 1].every(function(position, index) { + return coords[0][index] === position; + }))) { + errors.push({ + message: 'the first and last positions in a LinearRing of coordinates must be the same', + line: line + }); + } } else if (type === 'Line' && coords.length < 2) { errors.push({ message: 'a line needs to have two or more coordinates to be valid', @@ -134,6 +146,11 @@ function hint(str) { requiredProperty(_.crs.properties, 'href', 'string'); } } + } else { + errors.push({ + message: 'the value of the crs property must be an object, not a ' + (typeof _.crs), + line: _.__line__ + }); } } @@ -260,11 +277,11 @@ function hint(str) { var match = e.message.match(/line (\d+)/), lineNumber = 0; if (match) lineNumber = parseInt(match[1], 10); - return { - line: lineNumber, + return [{ + line: lineNumber - 1, message: e.message, error: e - }; + }]; } if (typeof gj !== 'object' ||
 @@ -1,6 +1,6 @@ { "name": "geojsonhint", - "version": "0.1.5", + "version": "0.2.1", "description": "validate and sanity-check geojson files", "main": "index.js", "directories": {
 @@ -1,5 +1,5 @@ -{ - "line": 2, +[{ + "line": 1, "message": "Parse error on line 2:\n...\": \"MultiPoint\" \"coordinates\": [[\"fo\n----------------------^\nExpecting 'EOF', '}', ':', ',', ']', got 'STRING'", "error": {} -} +}]
 @@ -0,0 +1,5 @@ +{ + "crs": 5, + "type": "Point", + "coordinates": [2, 2] +}
 @@ -0,0 +1,6 @@ +[ + { + "message": "the value of the crs property must be an object, not a number", + "line": 1 + } +]
 @@ -0,0 +1,5 @@ +{ "type": "Polygon", + "coordinates": [ + [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0] ] + ] + }
 @@ -0,0 +1,6 @@ +[ + { + "message": "the first and last positions in a LinearRing of coordinates must be the same", + "line": 3 + } +]
 @@ -0,0 +1,7 @@ +{ "type": "MultiPolygon", + "coordinates": [ + [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]], + [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0, 4.9]], + [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]] + ] + }
 @@ -0,0 +1,6 @@ +[ + { + "message": "the first and last positions in a LinearRing of coordinates must be the same", + "line": 4 + } +]
 @@ -1,4 +1,10 @@ -[{ +[ + { "message": "a LinearRing of coordinates needs to have four or more positions", "line": 3 -}] + }, + { + "message": "the first and last positions in a LinearRing of coordinates must be the same", + "line": 3 + } +]