Last change
on this file since 484 was
484,
checked in by hendrikvanantwerpen, 11 years ago
|
Commit node_modules, to make checkouts and builds more deterministic.
|
File size:
1.3 KB
|
Line | |
---|
1 | module.exports = function(grunt) { |
---|
2 | var coffeelint = require('coffeelint'); |
---|
3 | |
---|
4 | grunt.registerMultiTask('coffeelint', 'Validate files with CoffeeLint', function() { |
---|
5 | |
---|
6 | var files = this.filesSrc; |
---|
7 | var options = this.options(); |
---|
8 | var errorCount = 0; |
---|
9 | var warnCount = 0; |
---|
10 | |
---|
11 | files.forEach(function(file) { |
---|
12 | grunt.verbose.writeln('Linting ' + file + '...'); |
---|
13 | |
---|
14 | var errors = coffeelint.lint(grunt.file.read(file), options); |
---|
15 | |
---|
16 | if (!errors.length) { |
---|
17 | return grunt.verbose.ok(); |
---|
18 | } |
---|
19 | |
---|
20 | errors.forEach(function(error) { |
---|
21 | var status, message; |
---|
22 | |
---|
23 | if (error.level === 'error') { |
---|
24 | errorCount += 1; |
---|
25 | status = "[error]".red; |
---|
26 | } else if (error.level === 'warn') { |
---|
27 | warnCount += 1; |
---|
28 | status = "[warn]".yellow; |
---|
29 | } else { |
---|
30 | return; |
---|
31 | } |
---|
32 | |
---|
33 | message = file + ':' + error.lineNumber + ' ' + error.message + |
---|
34 | ' (' + error.rule + ')'; |
---|
35 | |
---|
36 | grunt.log.writeln(status + ' ' + message); |
---|
37 | grunt.event.emit('coffeelint:' + error.level, error.level, message); |
---|
38 | grunt.event.emit('coffeelint:any', error.level, message); |
---|
39 | }); |
---|
40 | }); |
---|
41 | |
---|
42 | if (errorCount) { |
---|
43 | return false; |
---|
44 | } |
---|
45 | |
---|
46 | if (!warnCount) { |
---|
47 | grunt.log.ok(files.length + ' file' + (files.length === 1 ? '' : 's') + |
---|
48 | ' lint free.'); |
---|
49 | } |
---|
50 | }); |
---|
51 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.