It is very easy to create your own automated code review, most reviews are just 4 lines of CFML code!
How The Code Review Tool WorksThe code review tool first reads all the configuration settings, and review definitions. Next a list of files is generated recursively from the base path that the user wishes to review. All of the files are sequentially read, and parsed. The review definitions contain a variable called tagListener which is a list of tag names that the particular rule is interested in. Each file is checked for each tag listener in every review. When a file has an instance of the tag that the review is listening for, the review code is executed. If a file has multiple instances of the tag the review code will be executed multiple times.
The review code has several variables available which can be used to determine if there are any issues associated with a particular tag instance. If there are issues in the tag instance, then the issue is reported with the AddIssue function.
Here is some pseudo code that illustrates the process:
for each file for each review definition for each tag listener if file has tag execute review end end end end
Step 1 - Create the Review Definition
Open the file codereview/config/custom.reviews.cfm. Create a structure in this file using the example below.
Example Review Definition Structure:
<cfset config.reviews.myreview = StructNew()> <cfset config.reviews.myreview.name = "IMG tags should define height and width"> <cfset config.reviews.myreview.description = "Set the height and width attribute on your img tags."> <cfset config.reviews.myreview.type = "style"> <cfset config.reviews.myreview.severity = 3> <cfset config.reviews.myreview.taglistener = "img">
Step 2 - Write your review code
Reviews are stored in the directory codereview/framework/reviews/. Create a file using the file name specified in Step 1 (remember all lower case, no special characters).
The file you just created will be executed every time an instance of a tag in your taglistener list is found.
Each time it is executed several variables
are set, here's some variables you can use:
Review Variables
<cfif NOT ReFindNoCase("height[[:space:]]*=", tagInfo.attributeContent)> <cfset context = "<" & tagName & tagInfo.attributeContent & ">"> <cfset AddIssue("myreview", context, tagInfo.startPos)> </cfif>Yes that's all it takes to write a review 4 lines of code is very typical! Getting handy with regular expressions will also save you a lot of code. Checkout this regular expression howto, or this book for more info on Regex in ColdFusion.
Step 3 - Enabling the review
Now all thats left to do is enable your review, so the framework knows about it.
This is done by adding the file name of your review to the Reviews list in the configuration web page in the tool (visit index.cfm in your web browser and click on configuration).