source: Dev/trunk/node_modules/grunt-coffeelint/tasks/coffeelint.js @ 516

Last change on this file since 516 was 516, checked in by hendrikvanantwerpen, 11 years ago

Enable deployment with Grunt.

File size: 1.7 KB
Line 
1module.exports = function(grunt) {
2  var coffeelint = require('coffeelint');
3
4  grunt.registerMultiTask('coffeelint', 'Validate files with CoffeeLint', function() {
5
6    var errorCount = 0;
7    var warnCount = 0;
8    var files = this.filesSrc;
9    var options = this.options();
10
11    if (options.configFile != undefined) {
12      var config = grunt.file.readJSON(options.configFile);
13      options.configFile = undefined;
14      for (var key in options) {
15          config[key] = options[key];
16      }
17      options = config;
18    }
19
20    files.forEach(function(file) {
21      grunt.verbose.writeln('Linting ' + file + '...');
22
23      var literate = !!file.match(/\.(litcoffee|coffee\.md)$/i);
24      var errors = coffeelint.lint(grunt.file.read(file), options, literate);
25
26      if (!errors.length) {
27        return grunt.verbose.ok();
28      }
29
30      errors.forEach(function(error) {
31        var status, message;
32
33        if (error.level === 'error') {
34          errorCount += 1;
35          status = "[error]".red;
36        } else if (error.level === 'warn') {
37          warnCount += 1;
38          status = "[warn]".yellow;
39        } else {
40          return;
41        }
42
43        message = file + ':' + error.lineNumber + ' ' + error.message +
44            ' (' + error.rule + ')';
45
46        grunt.log.writeln(status + ' ' + message);
47        grunt.event.emit('coffeelint:' + error.level, error.level, message);
48        grunt.event.emit('coffeelint:any', error.level, message);
49      });
50    });
51
52    if (errorCount && !options.force) {
53      return false;
54    }
55
56    if (!warnCount && !errorCount) {
57      grunt.log.ok(files.length + ' file' + (files.length === 1 ? '' : 's') + ' lint free.');
58    }
59  });
60};
Note: See TracBrowser for help on using the repository browser.