grunt-yaml-validator
Advanced tools
Comparing version 0.7.2 to 0.7.3
{ | ||
"name": "grunt-yaml-validator", | ||
"description": "Validate Yaml files and enforce a given structure", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"homepage": "https://github.com/paazmaya/grunt-yaml-validator", | ||
@@ -44,3 +44,3 @@ "author": { | ||
"grunt": "~0.4", | ||
"grunt-eslint": "~2.0", | ||
"grunt-eslint": "~2.1", | ||
"grunt-mocha-test": "~0.12", | ||
@@ -47,0 +47,0 @@ "jit-grunt": "~0.9", |
@@ -5,3 +5,6 @@ # grunt-yaml-validator | ||
[![Dependency Status](https://david-dm.org/paazmaya/grunt-yaml-validator.svg)](https://david-dm.org/paazmaya/grunt-yaml-validator) | ||
[![Dependency Status](https://img.shields.io/david-dm/paazmaya/grunt-yaml-validator.svg?style=flat-square)](https://david-dm.org/paazmaya/grunt-yaml-validator) | ||
[![Build Status](https://img.shields.io/drone/paazmaya/grunt-yaml-validator/status.svg?style=flat-square)](https://drone.io/github.com/paazmaya/grunt-yaml-validator/latest) | ||
[![Built with Grunt](http://img.shields.io/badge/Grunt-0.4-blue.svg?style=flat-square)](http://gruntjs.com/) | ||
[![Analytics](https://ga-beacon.appspot.com/UA-2643697-15/grunt-yaml-validator/index)](https://github.com/igrigorik/ga-beacon) | ||
@@ -249,2 +252,3 @@ [Yaml](http://yaml.org/) files are parsed via [`js-yaml`](https://github.com/nodeca/js-yaml) | ||
* v0.7.2 (2014-11-03) Undefined key crashes if used | ||
* v0.7.3 (2014-12-17) Try/catch around Yaml parsing to avoid breaking in between files | ||
@@ -251,0 +255,0 @@ ## License |
@@ -11,4 +11,4 @@ /** | ||
var yaml = require('js-yaml'), | ||
check = require('check-type').init(); | ||
var yaml = require('js-yaml'); | ||
var check = require('check-type').init(); | ||
@@ -28,2 +28,3 @@ var YamlValidatore = function YamlValidatore(options, grunt) { | ||
* @param {string} msg Error message | ||
* @returns {void} | ||
*/ | ||
@@ -79,3 +80,3 @@ YamlValidatore.prototype.errored = function errored(msg) { | ||
} | ||
else if (typeof item == 'object' && item !== null) { | ||
else if (typeof item === 'object' && item !== null) { | ||
notValid = validateStructure(doc[key], item, current); | ||
@@ -86,3 +87,3 @@ notFound = notFound.concat(notValid); | ||
return notFound.filter(function (item) { | ||
return notFound.filter(function filterFalse(item) { | ||
return item !== false; | ||
@@ -103,12 +104,19 @@ }); | ||
var doc = yaml.safeLoad(data, { | ||
onWarning: function onWarning(error) { | ||
hadWarning = 1; | ||
_self.errored(filepath + ' > ' + error); | ||
if (_self.options.yaml && | ||
typeof _self.options.yaml.onWarning === 'function') { | ||
_self.options.yaml.onWarning.call(this, error, filepath); | ||
var doc; | ||
try { | ||
doc = yaml.safeLoad(data, { | ||
onWarning: function onWarning(error) { | ||
hadWarning = 1; | ||
_self.errored(filepath + ' > ' + error); | ||
if (_self.options.yaml && | ||
typeof _self.options.yaml.onWarning === 'function') { | ||
_self.options.yaml.onWarning.call(this, error, filepath); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
catch (error) { | ||
this.grunt.warn.error(error); | ||
return 1; | ||
} | ||
@@ -135,2 +143,4 @@ if (this.options.writeJson) { | ||
* Create a report out of this, but in reality also run. | ||
* @param {array} files List of files that have been checked that they exist | ||
* @returns {void} | ||
*/ | ||
@@ -148,2 +158,3 @@ YamlValidatore.prototype.validate = function validate(files) { | ||
* Create a report out of this, but in reality also run. | ||
* @returns {void} | ||
*/ | ||
@@ -166,3 +177,3 @@ YamlValidatore.prototype.report = function report() { | ||
grunt.registerMultiTask('yaml_validator', 'Validate Yaml files and enforce a given structure', function() { | ||
grunt.registerMultiTask('yaml_validator', 'Validate Yaml files and enforce a given structure', function registerMulti() { | ||
@@ -169,0 +180,0 @@ // Default options |
15168
162
256