Slide 15
Slide 15 text
function checkStyle(code, filename) {
var ast = esprima.parse(code, parseOptions);
var errors = [];
estraverse.traverse(ast, {
enter: function(node, parent) {
if (node.type === 'VariableDeclaration')
checkVariableNames(node, errors);
}
});
return formatErrors(code, errors, filename);
}
function checkVariableNames(node, errors) {
_.each(node.declarations, function(decl) {
if (decl.id.name.indexOf('_') >= 0) {
return errors.push({
location: decl.loc,
message: 'Use camelCase, not hacker_style!'
});
}
});
}
function checkVariableNames(node, errors) {
_.each(node.declarations, function(decl) {
if (decl.id.name.indexOf('_') >= 0) {
return errors.push({
location: decl.loc,
message: 'Use camelCase, not hacker_style!'
});
}
});
}