My Account   Contact Us    
» HomeProductsSupportDeveloper CommunityCompany

Code Review Tool - Documentation - Creating your own reviews

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 Works

The 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

Step 1 - Create the Review Definition

Open the file codereview/config/ Create a structure in this file using the example below.

Example Review Definition Structure:

<cfset = StructNew()>
<cfset = "IMG tags should define height and width">
<cfset = "Set the height and width attribute on your img tags.">
<cfset = "style">
<cfset = 3>
<cfset = "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

Using the above variables you can easily determine if the tag instance has the issue your looking for. If you find the issue your looking for, you can call the AddIssue function. The function expects three arguments: an issuename (this should be your file name), a context (string showing where the problem is, code sample), and the position in the file where the issue begins. Here's an example code review that makes sure a tag has the height attribute defined:
<cfif NOT ReFindNoCase("height[[:space:]]*=", tagInfo.attributeContent)>
	<cfset context = "<" & tagName & tagInfo.attributeContent & ">">
	<cfset AddIssue("myreview", context, tagInfo.startPos)>
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).

Sign up for our newsletter: | Subscribe with RSS: RSS
© ActivSoftware 1999 to 2005 | Privacy Statement