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

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

Enable deployment with Grunt.

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