mozilla/scanjs — pull request #129 by pauljt (2014-04-23 10:50:19+00:00)
Title: Change rule format to allow rules to be written in JS

So in pondering how we make more readable rules, I realized that if we can write rules in Javascript use a JS parser (e.g. acorn) to parse rules.
This is a work in progress, but currently this PR makes the following changes:
- rules are now specified by a single javascript statement (rule.source)
- rule.source is parsed in an AST
- we test the AST to decide which rule template suits

This is _awesome_ since it allows a bunch of cool features:
- you dont have to specify rule.type any more (this is determined from rule.source)
- template tests are now much easier to read:
```
member: {
nodeType: "MemberExpression",
test: function (rule, node) {
var testNode=rule.statement.expression;
if (node.property.name == testNode.property.name) {
aw_found(rule, node);
}
}
},
```
- using JS source to specify rules allows for richer rule types. This allows more complex rules, like the callwithargs template, which checks the the literal arguments to a function, and only matches if the function name matches AND all the literal arguments match (respecting order)

I'm just refactoring the new rules to use this format, then this will be ready to go.