Last change
on this file was
505,
checked in by hendrikvanantwerpen, 11 years ago
|
Added linting of json files.
|
File size:
944 bytes
|
Rev | Line | |
---|
[505] | 1 | /* |
---|
| 2 | * grunt-jsonlint |
---|
| 3 | * https://github.com/brandonsramirez/grunt-jsonlint |
---|
| 4 | * |
---|
| 5 | * Copyright (c) 2013 Brandon Ramirez |
---|
| 6 | * Licensed under the MIT license. |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | module.exports = function (grunt) { |
---|
| 10 | "use strict"; |
---|
| 11 | |
---|
| 12 | var jsonlint = require('jsonlint'); |
---|
| 13 | |
---|
| 14 | grunt.registerMultiTask("jsonlint", "Validate JSON files.", function () { |
---|
| 15 | if (this.filesSrc != null) { |
---|
| 16 | var failed = 0; |
---|
| 17 | this.filesSrc.forEach(function (file) { |
---|
| 18 | grunt.log.debug('Validating "' + file + '"...'); |
---|
| 19 | |
---|
| 20 | try { |
---|
| 21 | jsonlint.parse(grunt.file.read(file)); |
---|
| 22 | grunt.verbose.ok('File "' + file + '" is valid JSON.'); |
---|
| 23 | } |
---|
| 24 | catch (e) { |
---|
| 25 | failed++; |
---|
| 26 | grunt.log.error('File "' + file + '" failed JSON validation.'); |
---|
| 27 | grunt.fail.warn(e); |
---|
| 28 | } |
---|
| 29 | }); |
---|
| 30 | var successful = this.filesSrc.length - failed; |
---|
| 31 | grunt.log.ok(successful + ' file' + (successful === 1 ? '' : 's') + ' lint free.'); |
---|
| 32 | } |
---|
| 33 | }); |
---|
| 34 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.