Skip to content

Commit

Permalink
Follow grunt 0.4 convention (change options syntax) + some formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina committed Feb 20, 2013
1 parent a6f011a commit fee8a22
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 24 deletions.
23 changes: 16 additions & 7 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,34 @@ module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({

coffeelint: {
// global options
options: {
indentation: {
value: 4,
level: 'warn'
}
},

// a target that overrides default options
one: {
files: {
src: ['test/fixtures/*.coffee'],
src: ['test/fixtures/*.coffee']
},
options: {
indentation: {
value: 2,
level: "warn"
level: 'warn'
},
"no_trailing_semicolons": {
level: "warn"
'no_trailing_semicolons': {
level: 'warn'
}
}
},
two: ['test/fixtures/correct.coffee', 'test/fixtures/some.coffee']
},
coffeelintOptions: {

// a simple target
two: ['test/fixtures/correct.coffee', 'test/fixtures/some.coffee']
}
});

Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ grunt.initConfig({
app: ['app/*.coffee', 'scripts/*.coffee'],
tests: {
files: {
src: ['tests/*.coffee'],
}
src: ['tests/*.coffee']
},
options: {
"no_trailing_whitespace": {
"level": "error"
'no_trailing_whitespace': {
'level': 'error'
}
}
}
Expand All @@ -56,9 +56,11 @@ grunt.initConfig({
````javascript
grunt.initConfig({
...
coffeelintOptions: {
"no_trailing_whitespace": {
"level": "error"
coffeelint: {
options: {
'no_trailing_whitespace': {
'level': 'error'
}
}
},
...
Expand Down
33 changes: 23 additions & 10 deletions tasks/coffeelint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,44 @@ module.exports = function(grunt) {
var coffeelint = require('coffeelint');

grunt.registerMultiTask('coffeelint', 'Validate files with CoffeeLint', function() {
var options = this.data.options || grunt.config('coffeelintOptions') || {};

var files = this.filesSrc;
var options = this.options()
var errorCount = 0;
var warnCount = 0;

this.filesSrc.forEach(function(file) {
files.forEach(function(file) {
grunt.verbose.writeln('Linting ' + file + '...');

var errors = coffeelint.lint(grunt.file.read(file), options);

if (!errors.length) {
grunt.verbose.ok();
} else {
errors.forEach(function(error) {
var status = "[warn]".yellow;
if(/error/.test(error.level)){
var status;

if (error.level === 'error') {
errorCount += 1;
status = "[error]".red;
} else if (error.level === 'warn') {
warnCount += 1;
status = "[warn]".yellow;
} else {
return;
}
grunt.log.writeln(status + ' ' +file + ':' + error.lineNumber + ' ' + error.message + ' (' + error.rule + ')');

grunt.log.writeln(status + ' ' + file + ':' + error.lineNumber + ' ' + error.message + ' (' + error.rule + ')');
});
}
});

if(!errorCount){
grunt.log.write("Lint free");
} else {

if (errorCount) {
return false;
}

if (!warnCount) {
grunt.log.ok(files.length + ' file' + (files.length === 1 ? '' : 's') + ' lint free.');
}
});
};

0 comments on commit fee8a22

Please sign in to comment.