Skip to content

Instantly share code, notes, and snippets.

@jschilli
Last active August 29, 2015 14:16
Show Gist options
  • Save jschilli/2e867fc23c1eac602525 to your computer and use it in GitHub Desktop.
Save jschilli/2e867fc23c1eac602525 to your computer and use it in GitHub Desktop.
module.exports = function() {};
module.exports.prototype = {
configure: function(noHandlebarsCompileExpression) {
this._isEnabled = noHandlebarsCompileExpression;
},
getOptionName: function() {
return 'noHandlebarsCompile';
},
check: function(file, errors) {
if (!this._isEnabled) {
return;
}
file.iterateNodesByType('CallExpression', function(node) {
var lastCalleeToken = file.getLastNodeToken(node.callee);
if (lastCalleeToken.value === 'compile') {
var calleeObject = node.callee.object && node.callee.object.property;
if (calleeObject && calleeObject.name === 'Handlebars') {
errors.add(
'Don\'t call the Handlebars compile',
lastCalleeToken.loc.start
);
}
}
});
}
};
{
"additionalRules": [ "tools/jscs-rules/*.js" ],
"excludeFiles": ["tests/fixtures/*"],
"noHandlebarsCompile": true, // -> will change to true when we excise remaining em.handlebars.compile
"usePrecompileTemplateProperly": true,
...
}
module.exports = function() {};
module.exports.prototype = {
configure: function(usePrecompileProperly) {
this._isEnabled = usePrecompileProperly;
},
getOptionName: function() {
return 'usePrecompileTemplateProperly';
},
check: function(file, errors) {
if (!this._isEnabled) {
return;
}
file.iterateNodesByType('CallExpression', function(node) {
if (node.callee.name === 'precompileTemplate' && node.arguments[0] && node.arguments[0].type !== 'Literal') {
errors.add(
'precompileTemplate must be called with a literal expression to work properly\ne.g precompileTemplate("{{foo}}"',
node.loc.start
);
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment