mozilla / scanjs

[DEPRECATED] Static analysis tool for javascript code.
Other
429 stars 39 forks source link

Change rule format to allow rules to be written in JS #129

Closed pauljt closed 10 years ago

pauljt commented 10 years ago

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:

This is awesome since it allows a bunch of cool features:

member: {
      nodeType: "MemberExpression",
      test: function (rule, node) {
        var testNode=rule.statement.expression;
        if (node.property.name == testNode.property.name) {
          aw_found(rule, node);
        }
      }
    },

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

pauljt commented 10 years ago

All rules refactored. Separate tests now for production and test rules. Just needs a little bit of UI cleanup, and maybe a readme update, and this will be ready to merge.

mozfreddyb commented 10 years ago

I get "error parsing nfc manager permission. the test is empty for source, testhit and testmiss. According to https://bugzilla.mozilla.org/show_bug.cgi?id=952217#c17 the patch that landed doesn't make it so easy to test if something has nfc-manager, but I'm not sure I get it. Removing this makes things work ;)

The Experiment tab doesn't work completely: We need a button since I find the onkey-thing for the rule field unintuitive :)

mozfreddyb commented 10 years ago

Also client/js/rules.js is somehow broken, the check for localStorage exists but everything using localStorage is outside of this. I dont know how this happens but I will fix this separately from this.

pauljt commented 10 years ago

Re the empty rule. You get an error, but it still works - the rule parser is error tolerant I hope. THe reason for this is nfc is a difficult permission to scan for. We can remove it for now though.

The experiment tab does work completely, its your brain which is broken ;) But yeh I can add a button if you want.

Actually rule.js and scan.js are basically ready to be removed. My plan was once this is landed, to add a seperate patch which remove the old scan.js and rules js, and renames AcornWalker.js to scan.js

Make sense?