Skip to content

Instantly share code, notes, and snippets.

@jasonmit
Last active September 9, 2015 06:38
Show Gist options
  • Save jasonmit/034f3114149faa39da7d to your computer and use it in GitHub Desktop.
Save jasonmit/034f3114149faa39da7d to your computer and use it in GitHub Desktop.
Warn on jquery in controllers, routes, models
var Filter = require('broccoli-filter');
var controller = new RegExp(/(^controllers\/)|(^models\/)|(^routes\/)/);
var jquery = new RegExp(/\W(\$\.)|(\.\$\.)|(\$\()/);
NoJquery.prototype = Object.create(Filter.prototype);
NoJquery.prototype.constructor = NoJquery;
function NoJquery(inputNode) {
if (!(this instanceof NoJquery)) {
return new NoJquery(inputNode);
}
Filter.call(this, inputNode);
};
NoJquery.prototype.extensions = ['js'];
NoJquery.prototype.targetExtension = 'js';
NoJquery.prototype.processString = function (content, relativePath) {
if (controller.test(relativePath) && jquery.test(content)) {
console.error(relativePath);
content.split('\n').forEach(function(line, idx) {
var found = line.match(jquery);
if (found) {
console.error('Found some jquery on line' + idx);
console.error(line);
}
});
}
};
module.exports = NoJquery;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment