Code Challenge Analyzer

An API for testing JavaScript code for the presence of specific constructs.

##Usage

Dependencies:

  • Esprima parser 2.7.2
  • jQuery 1.12.1
  • normalize.css 3.0.3

To install dependencies, run:

npm install

##Example To view an example implementation, open the analyzer.html file in your browser.
The example implementation in analyzerExample.js has a whitelist that contains a 'while' loop and an 'if' statement, a blacklist that contains a 'variable' declaration, and also looks for an 'if' statement nested inside of a 'for' loop.

##API

This API's current release allows testing for the presence of 'if' statements, 'while' loops, 'for' loops, and variable declarations. It also allows for testing for the presence of one-level-deep nesting of these constructs.

To access the API, initialize a new tester object:

var tester = new Tester();

####Whitelist

The whitelist contains constructs that must be present in the code being analyzed. To add a construct to the whitelist, call:

tester.required(construct string);

Available construct strings: 'if', 'while', 'for', 'variable'.

To analyze code using the whitelist:

tester.findRequired(input string);

.findRequired eturns an error string if the constructs in the whitelist are not found, eg. "The program MUST use an 'if statement'.". Returns null if whitelist constructs are present.

####Blacklist

The blacklist contains constructs that must not be present in the code being analyzed. To add a construct to the blacklist, call:

tester.banned(construct string)

Available construct strings: 'if', 'while', 'for', 'variable'

To analyze code using the blacklist:

tester.findBanned(input string);

.findBanned returns an error string if the constructs in the blacklist are present, eg. "The program MUST NOT use an 'if statement'.". Returns null if blacklist constructs are not present.

####Nested constructs

To specify constructs that should be nested, call:

tester.nested(outer construct, inner construct)

Available constructs: 'if', 'while', 'for', 'variable'

To analyze code for nested constructs, call:

tester.findNested(input string);

.findNested returns an error string if the nesting is not present, eg. "There should be a 'while loop' and inside of it there should be an 'if statement'". Returns null if nested construct is found.