forked from joliss/broccoli-coffee
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Coffeelint and literate coffee support
- Loading branch information
Showing
2 changed files
with
55 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 : '')); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
], | ||
"dependencies": { | ||
"coffee-script": "~1.7.1", | ||
"coffeelint": "^1.6.0", | ||
"broccoli-filter": "^0.1.6" | ||
} | ||
} |