#This script is designed to run with Understand - CodeCheck use base ("Understand::Codecheck"); use strict; use warnings; # Required - Return the short name of the check sub name { return "Test Name";} # Required - Return the short description of the check sub description { return "Test Short Description";} # Required - Return the long description of the check sub detailed_description { return "Test Long Description";} # Required - Test the language of the current file, the check will be # skipped if this returns 0 sub test_language { my $language = shift; #return $language eq "C++"; return 1; } # Required - Return 1 if this check will be run on a per-file basis sub test_entity { return 1;} # Required - Return 1 if this check should be run on the entire project # regardless of what files are selected. Should only be used for # project-level checks sub test_global { return 0;} # Optional - define configurable options for the check. sub define_options{ my $check = shift; # This object provides access to the following methods to create options: # $check->option->checkbox($name,$optionText,$default) # create a checkbox option # $check->option->checkbox_horiz($name,$optionText,@choices,@defaults) # create a horizontal group of checkbox options # $check->option->checkbox_vert($name,$optionText,@choices,@defaults) # create a vertical group of checkbox options # $check->option->choice($name,$optionText,@choices,$default) # create a choice option # $check->option->file($name,$optionText,$default) # create a file choice option # $check->option->integer($name,$optionText,$default) # create an integer option # $check->option->radio_horiz($name,$optionText,@choices,$default) # create a horizontalradio button option # $check->option->radio_vert($name,$optionText,@choices,$default) # create a vertical radio button option # $check->option->text($name,$optionText,$default) # create a text option } # Required - Run the check and return violations if any. # This is called for each file if test_entity is set to 1 and $file is the Understand::Ent object for the file # it is also called once with $file set to null if test_global is set to 1 sub check { my $check = shift; #The check object, needed to report violations and lookup option values my $file = shift; # Will be empty if test_global set to 1 and test_entity set to 0 # test_entity only runs on files for now, but could change in the future, so force the check to only run on files return unless $file->kind->check("file"); # Register a violation with the syntax below. # $check->violation($entity,$file,$line,$column,"Error String"); # $check->violation(0,0,-1,-1,"Error String") #if no entity or location # lookup the value or values for an option # my $optionVal = $check->option->lookup($name); # Return an Understand::Db object # my $db = $check->db }