Skip to content

Commit

Permalink
Add Coffeelint and literate coffee support
Browse files Browse the repository at this point in the history
  • Loading branch information
Truffula committed Sep 21, 2014
1 parent d1e6d83 commit 822946b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
71 changes: 54 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,63 @@
var Filter = require('broccoli-filter')
/* jshint node: true */

var Filter = require('broccoli-filter');
var coffeeScript = require('coffee-script')
var CoffeeLint = require('CoffeeLint');

module.exports = CoffeeScriptFilter;
CoffeeScriptFilter.prototype = Object.create(Filter.prototype);
CoffeeScriptFilter.prototype.constructor = CoffeeScriptFilter;

module.exports = CoffeeScriptFilter
CoffeeScriptFilter.prototype = Object.create(Filter.prototype)
CoffeeScriptFilter.prototype.constructor = CoffeeScriptFilter
function CoffeeScriptFilter (inputTree, options) {
if (!(this instanceof CoffeeScriptFilter)) return new CoffeeScriptFilter(inputTree, options)
Filter.call(this, inputTree, options)
options = options || {}
this.bare = options.bare
if (!(this instanceof CoffeeScriptFilter)) {
return new CoffeeScriptFilter(inputTree, options);
}
Filter.call(this, inputTree, options);

this.options = options || {};
this.bare = options.bare;
this.CoffeeLint = CoffeeLint;

if (options.coffeelintOptions) {
this.coffeelintOptions = options.coffeelintOptions;
delete this.options.coffeelintOptions;
} else if (!this.coffeelintOptions) {
this.coffeelintOptions = {};
}
this.logger = options.logger || console.log.bind(console);

}

CoffeeScriptFilter.prototype.extensions = ['coffee']
CoffeeScriptFilter.prototype.targetExtension = 'js'
CoffeeScriptFilter.prototype.extensions = ['coffee','litcoffee','coffee.md'];
CoffeeScriptFilter.prototype.targetExtension = 'js';

CoffeeScriptFilter.prototype.processString = function (string, srcFile) {
console.log('Coffeescript processString');
// throw new error;
var coffeeScriptOptions = {
bare: this.bare,
literate: coffeeScript.helpers.isLiterate(srcFile)
};
var errors = this.CoffeeLint.lint(string, this.coffeelintOptions, coffeeScriptOptions.literate);

if (errors && errors.length) {
this.reportLintErrors(srcFile, errors);
}

CoffeeScriptFilter.prototype.processString = function (string) {
var coffeeScriptOptions = { bare: this.bare }
try {
return coffeeScript.compile(string, coffeeScriptOptions)
return coffeeScript.compile(string, coffeeScriptOptions);
} catch (err) {
err.line = err.location && err.location.first_line
err.column = err.location && err.location.first_column
throw err
err.line = err.location && err.location.first_line;
err.column = err.location && err.location.first_column;
throw err;
}
}
};

CoffeeScriptFilter.prototype.reportLintErrors = function CoffeeScriptFilter_reportLintErrors(relativePath, errors) {
var self = this;

for (var i = 0; i < errors.length; i++) {
var e = errors[i];
self.logger(relativePath + ':' + e.lineNumber + ': ' + e.message + (e.context? ': ' + e.context : ''));
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
],
"dependencies": {
"coffee-script": "~1.7.1",
"coffeelint": "^1.6.0",
"broccoli-filter": "^0.1.6"
}
}

0 comments on commit 822946b

Please sign in to comment.