Customizing the code review report

The default code review report is generated in an HTML format from a template named misrareport.template as that you can modify to customize the code review reports.

The code review HTML reports are generated from a template named misrareport.template that you can find in the following folder as a text file:
  • On Windows: <installation_directory>\lib\reports
  • On Unix: <installation_directory>/lib/reports
The template file uses the following JavaScript libraries:
  • Bootstrap
  • JQuery
  • Font Awesome
  • VisJS
  • Chart

These libraries are not provided. An internet connection is required to open the report. If you don't have any internet connection, download the libraries (.css and .js files), copy them in the folder in which the report is saved, and modify the template file as follows:

Replace the following block of lines:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.css">
…
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>
With the following one:
<link rel="stylesheet" href="./bootstrap.min.css>
<link rel="stylesheet" href="./all.css">
<link rel="stylesheet" href="./vis.min.css">
<link rel="stylesheet" href="./Chart.min.css">
…
<script src="./jquery-3.3.1.slim.min.js"></script>
<script src="./popper.min.js"></script>
<script src="./bootstrap.min.js"></script>
<script src="./vis.js"></script>
<script src="./Chart.min.js"></script>

The following sections give the list of elements that you can use in the raw data and the JavaScript functions to customize your report file.

Data format

The misrareport.template template consists of two sections:
  • The HTML section that is common to all reports,
  • A JavaScript section that sets tables depending on two variables that are initialized dynamically when the report is created:
    var data = {{json}};         // the raw data, in json format
    var d = new Date({{date}})   // the generation date
Raw data contains the following information at the top level:
  • output is the name of the json file that contains the raw data
  • title is the nternal title of the report (displayed in the “crc” file format)
  • configurationTitle is the title of the used configuration file
  • systemLevel is the C level norm used. The possible values are "C90", "C90 and Normative Addentum 1", "C99 or "C11"
  • configuration is the configuration file used to generate this report
  • date is the generation date of raw data
  • nbAnalyzedFiles is the number of analyzed files
  • nbFilesKO is the number of files containing errors
  • nbFilesOK is the number of files without errors
  • nbError is the total number of all errors in all analyzed files
  • nbWarning is the total number of all warnings in all analyzed files
  • files is the array of file element (each one represents a physical file) or array of deactivated element
  • statistics is the array of rule statistics element
    Example:
    {
    "output": "../build/fullreport_1.crc.json", 
    "title": "IBM Test RealTime MISRA C:2012 Report using C90", 
    "configurationTitle": "MISRA C:2012", 
    "systemLevel": "C90", 
    "configuration": "C:\\Program Files\\IBM\\TestRealTime/plugins/Common/lib/confrule_2012.xml", 
    "date": "Mon Oct 19 15:52:07 2020", 
    "nbAnalyzedFiles": 5, 
    "nbFilesKO": 4, 
    "nbFilesOK": 1, 
    "nbError": 49, 
    "nbWarning": 68, 
    "files": [
    ], 
    "statistics": [
    ]
    }
Each file elementfile element represents an analyzed source file. It contains the following information at the top level:
  • source is the physical location of source file
  • fileDate is the date of last editing of this source
  • nbErrorOrWarning is the total of error or warning in this file
  • content is an array of rule element (if the rule is directly raised at file level) or function element. It is always available but it can be empty (file with no function and with no error or warning)
    Each function element represents a function. It contains the following information at the top level:
    • function is the name of the function
    • kind is the analysis result of this function. The possible values are 'Failed' or 'Passed'
    • content is an array of rule element (rules that are raised inside this function). It is always available but it can be empty (function with no error or no warning)
    Examples:

    file element

    {
    "source": "C:\\workspace\\project\\src\\core.h", 
    "fileDate": "Mon Sep 07 10:31:50 2020", 
    "nbErrorOrWarning": 25, 
    "content": [
    ]
    }
    function element:
    {
    "function": "win", 
    "kind": "Failed", 
    "content": [
    ]
    }

Each rule element represents a triggered rule, justified or not. It contains the following information at the top level:

  • rule is the name of the rule, corresponding to its label defined in the configuration file
  • group is the family of this rule, it corresponds to the label of the rule’s group that is defined in the configuration file
  • kind is the severity of the rule. The possible values are 'error', 'warning' or 'info', depending on the error level in the configuration file and on the possible justification (the justified rules have an 'info' type value)
  • line is the line of the current file where the rule was triggered
  • column is the column of the current file where the rule was triggered
  • text is the rule description. It is related to the rule text in configuration file
  • justification is the justification text for the rule. This field is optional, and is present only if the rule is justified
    Example:
    {
    "rule": "M21.6.1", 
    "group": "21- Standard libraries", 
    "kind": "info", 
    "line": 21, 
    "column": 10, 
    "text": "The input/output library <stdio.h> shall not be used in production code.", 
    "justification": "This rule does not apply to the following line"
    }

Each deactivated element represents a group of rules that is deactivated for a specific reason. It contains the following information at the top level:

  • desactivated_rules_by_user is used for all the rules that are deactivated when it is used in the configuration file with the error set to level 0. This field is optional, it can be empty, or you can enter an array of disactivated rule element
    Example:
    {
    "desactivated_rules_by_user": [
    ]
    }
  • desactivated_rules_by_test_option is used for all the rules that are deactivated by using the “-test” option. This field is optional, it can be empty, or you can enter an array of disactivated rule element
    Example:
    {
    "desactivated_rules_test_option": [
    ]
    }

Each disactivated rule element represents a deactivated rule for any reason. It contains the following information at the top level:

  • rule is the name of the rule, it corresponds to the rule label that is defined in the configuration file
  • text is the rule description, it corresponds to the rule text in configuration file
    Example:
    {
    "rule": "E15.3", 
    "text": "The return keyword should not be used in a conditional block."
    }

Each rule statistics element represents global statistics for the rule raised during test. It contains the following information at the top level:

  • ruleStatistics is the array of the statistic rule element
    Example:
    {
    "rulesStatistics": [
    ]
    }

Each statistic rule element contains a rule that was raised one or several times. It contains the following information at the top level:

  • rule is the name of the rule. It corresponds to the rule label that is defined in the configuration file
  • kind is the severity of the rule. The possible values are 'error' or 'warning' that correspond to the error level in the configuration file
  • occurences is the number of times that the rule was raised
    Example:
    {
    "rule": "M17.7", 
    "kind": "error", 
    "text": "When a function returns a value, this value should be used.", 
    "occurences": 4
    }

Javascript functions

You can find in the misrareport.template template a set of JavaScript functions.

Some of the helper functions simplify access to “raw data”:

  • isFct(element) checks whether an element is a function or not
  • isFile(element) checks whether an element is a file or not
  • isFileInError(element) checks whether an element is a file that contains an error or a warning
  • isFctPassed(element) checks whether an element is a passed function or not
  • isFctFailed(element) checks whether an element is a failed function or not
  • isRuleError(element) checks whether a rule level is error or not
  • isRuleWarning(element) checks whether a rule level is warning or not
  • isRuleInfo(element) checks whether a rule level is an information or not
  • isRuleJustified(element) checks whether a rule is justified or not

Other functions are used to display each section of the report:

  • emptyLine() displays an empty line (helper function)
  • startFile(element) is called at start of a file element.
  • endFile() is called at end of a file element.
  • startFileRules() is called at the beginning of a group of rules that is relative to a file. Used to display array headers
  • endFileRules() is called at end of a group of rules relative to a file.
  • startFileFunctions() is called at the beginning of a function
  • rule(element) is called to display details of a raised rule.

The last section is a set of functions that is used to display summaries:

  • displayDesactivatedbytest(elem) displays all deactivated rules by using the '-test' option
  • displayDesactivatedbyuser(elem) displays all deactivated rules that are used in the configuration file
  • displayrulesstatistics(elem) displays statistics for all rules that are raised during the test

The main algorithm dispatches the function calls by parsing the raw data.