3.6 Reports
There are a number of standard reports that can be run by Code Checker for MATLAB. These are explained in the following sections. When selecting the option
Include reports in the GUI, the full results of all standard reports are shown. If this option is not selected, only the violations and errors encountered by the standard reports are reported. For every standard report, an exemption tag is given. For more information about this, see Section
3.9↓.
3.6.1 Meta data and summary
Under meta data, the following things are listed:
-
The time the check has finished.
-
The user that initiated the Code Checker.
-
A user comment that the user added to the report’s content (if any), for example the pull request URL related to the run.
-
The selected job type/settings.
-
Environment information such as the Code Checker for MATLAB version, MATLAB release, and platform.
-
The root folder of the selection. This can take on one of three shapes:
-
The full path of a file when a single file was selected.
-
The present working directory.
-
A selected folder.
-
The file(s) checked. If only one file was selected, this displays the name of the file. If more files were selected, this will show the number of checked files.
-
The number of files that could not be checked due to an error in the file (if any).
-
The number of failing checks (if any), sorted by priority.
-
The configuration file that was used to obtain the settings for each check. It includes a link to open the file.
-
The number of enabled checks and reports after applying priority filtering.
-
The number of disabled checks and reports and a link to an overview of the disabled checks/reports. This is not shown if there are no disabled checks.
-
Number of configuration problems:
-
Checks that have not been configured.
-
Check parameters that have not been configured.
-
Check parameters that have been configured more than once.
-
The reports folder in which Code Checker for MATLAB reports and the installed toolbox information are stored.
The
summary shows which checks have failed for at least one of the checked files. In case the
Include passed checks option, see Section
3.3.3↑, is enabled the summary contains information on
all checks ran, which might include passed checks as well. The summary provides the following things:
-
Name of the report or check that failed.
-
Link to the results of that report/check. Click the name of the report/check to follow the link.
-
Status of the report/check per checked file. Since multiple files can be checked for the same rules, there can be more than one status per report/check.
-
Relative path to the checked file(s) that failed the check. Again, multiple paths per report/check can be reported.
If a file contains a parse error or invalid characters, Code Checker for MATLAB cannot check it. The summary will include a list of all the checked files that contain a parse error or invalid character. The files can be clicked which will open the file in the MATLAB editor so that you can easily target the errors. These errors will also be reported by checkCodeInterpretable, see Section
3.7.11↓.
3.6.2 Configuring reports folder
By default, any reports are stored as .html files in the default folder that contains the reports. For Windows this is:
%APPDATA%\Roaming\cc4m\cc4m_reports
For Mac this is:
~/Library/Application Support/cc4m/cc4m_reports
For Linux this is:
~/.matlab/cc4m/cc4m_reports
From the command line, the folder in which reports are stored can be requested and changed. See
7↓for an overview of the options.
3.6.3 reportFunctions
reportFunctions gives a list of all functions defined in the file, including nested functions and sub functions. For every function, the following data is given:
-
The name of the function and a link to its definition
-
The type of function (constructor, method, function, sub-function, nested function)
-
The number of inputs and outputs of the function
-
Whether or not the function ends with end
Note: this does not report declarations of methods whose function is defined in a separate file. For example, the following method definition will be reported:
methods (Static)
function nrOut = powerSix(nrIn)
nrOut = nrIn^6;
end
end
but the next method declaration (with powerSix in a separate function file) will not:
methods (Static)
nrOut = powerSix(nrIn)
end
Exemption tag: %@ok<RFUNC>
3.6.4 reportVariables
reportVariables provides a list of all variables defined in the file that is checked. For every variable, the following data is given:
-
The name of the variable and a link to the line on which the variable is initiated.
-
The scope of the variable. The scope indicates the function that has knowledge of the variable. In case of shared variables in nested functions, only the function scopes where variables are assigned or updated are mentioned in the report.
-
The type of the variable. This can be: Input, Output, Input & Output, Shared (nested), Global or Persistent. In case of an empty Type, the variable is a local variable.
-
The data type of the variable. In case the data type is detected, it will be reported.
-
The use of the variable - if it is a constant, a computed index (For example: a = find([0 0 1]);) or the index of a FOR-loop.
Exemption tag: %@ok<RVARI>
3.6.5 reportDependencies
The file may use functions not defined in the file itself. These dependencies and additional information, are listed under reportDependencies.
For every valid dependency, the following is given:
-
The name of the dependency
-
The call itself and a link to the line on which the function is called
-
The type of function if known (Local, nested etc.)
-
The file on which the current file depends
-
The function that uses the dependency (Caller)
An example of two dependencies as reported by Code Checker for MATLAB is given in Figure
3.12↓.
Unknown dependencies can be recognized by the Function source column. A dependency is considered unknown if:
-
The function does not exist.
-
The function is not on the path during the Code Checker for MATLAB run. As described in Section 3.3.1↑, the code selected for checking is temporarily added to the path.
-
It is a function handle, or created/used in an eval-like construction.
Limitations
-
Accessing undeclared variables or variables loaded with the load function without outputs could lead to unknown dependencies being reported.
-
If a dependency is used as a variable within the same scope, the dependency is not reported. This also holds when the dependency is used as a function before the variable is declared.
Configurable parameters
-
DoReportBuiltinDependency (boolean): If set to true, MATLAB-installed functions must be shown in the dependency report. The default value for this parameter is true.
-
DependenciesUniqueGlobal (boolean): If set to true, uniqueness of dependencies is global shown over all checked file, only relevant if multiptle files checked. If set to false, uniqueness of dependencies is per file. The default value for this parameter is true.
-
DependenciesUniquePerFunction (boolean): If set to true, uniqueness of dependencies is shown per function, only relevant if single file checked. If set to false, uniqueness of dependencies is shown per file. The default value for this parameter is true.
Exemption tag: %@ok<RDEPE>
3.6.6 reportComplexity
In this report, you can find the cyclomatic complexities of all checked scripts and functions. The cyclomatic complexity is a measure of the number of linearly independent paths through a script or function. Higher cyclomatic complexity generally means more complex code.
Configurable parameters
-
MaxComplexityMainFunc (double): The maximum complexity for the main function. The default value for this parameter is 15 and it can be changed to anywhere between 3 and 50.
-
MaxComplexityScript (double): The maximum complexity for a script. The default value for this parameter is 20 and it can be changed to anywhere between 3 and 50.
-
MaxComplexityConstr (double): The maximum complexity for a constructor. The default value for this parameter is 20 and it can be changed to anywhere between 50 and 250.
-
MaxComplexityMehod (double): The maximum complexity for a method in a classdef file, methods in a separate file are treated as main function. The default value for this parameter is 15 and it can be changed to anywhere between 3 and 50.
-
MaxComplexitySubFunc (double): The maximum complexity for a sub-function. The default value for this parameter is 10 and it can be changed to anywhere between 3 and 50.
-
MaxComplexityNestFunc (double): The maximum complexity for a nested function. The default value for this parameter is 3 and it can be changed to anywhere between 1 and 10.
Exemption tag: %@ok<RCOMP>
3.6.7 reportBinaryExpressions
This report is especially relevant for m-code that will be used for code generation. It reports all binary expressions for which the order of evaluation might matter. For this report, an expression is a binary expression if it uses a binary operator. These operators are: :, ^, ==, <=, >=, ~=, >, <, &, &&, |, ||, +, -, *, .* and /. An expression will be reported by reportBinaryExpressions if any of these are met:
-
A user-defined function is called on both sides of the operator.
-
A user-defined function is called on one side of the operator and a relevant variable is accessed on the other side of the operator. Relevant variables are:
-
Handle objects.
-
Persistent variables
-
Global variables
If a variable is accessed for which the datatype could not be reliably obtained, it is also considered a relevant variable when the fourth preference described in Section
3.3.4↑ is set to
false. The datatype of variables used in the code are unknown for example for the inputs of the checked main function, or outputs of user-defined function calls. Disabling the preference may lead to fewer (incorrect) results being reported.
Exemption tag: %@ok<BINEX>
3.6.8 reportCellArrays
reportCellArrays reports all expressions that assign or create cell arrays that are not arrays of character arrays or arrays of heterogeneous objects. Cell array assignments where the cells are of unknown type are reported based on a parameter value. Using cell arrays for for example numbers or logicals is often discouraged because it is unnecessary, more difficult to read, or because it leads to poorer performance. By using the fourth preference described in Section
3.3.4↑, you can choose whether or not to ignore cells of unknown datatype for this report. Code Checker for MATLAB cannot reliably determine the datatype of the cell assigned in every case. For the unknown cases, you can choose whether to report them or not. If this is set to
false, all results that are reported are violations for which it is certain the assigned cell is not an object nor a character array.
Exemption tag: %@ok<CELAR>
3.6.9 reportComparisons
In this report, all comparisons made with == or ~= are reported if any of its operands may be a non-integer number. Comparing two doubles using == or ~= that are not guaranteed to be whole numbers is not recommended because it can lead to unexpected results. This report lets you inspect the relevant comparisons yourself to make sure the comparisons work as intended. If necessary, you can adjust certain comparisons by adding a tolerance. The code analysis of Code Checker for MATLAB attempts to determine what data types the operands of the comparison have. This can have three different results:
-
When any of the operands is known to be a single or double that is not always a whole number, the comparison is reported as a violation and you will see the result in red text.
-
When both operands are known to be whole numbers or non-numeric, the comparison is not reported.
-
In other cases, the comparison is reported and manual inspection is required to determine whether the comparison is acceptable, or whether a tolerance must be added. These cases will only be reported if the Report violations when not entirely sure preference is switched on. See Section 3.3.4↑ for a description of this preference.
The following example shows what will be reported and what should be used instead:
% Will be reported as a violation:
out = myFcn(in) == sqrt(3);
% Instead use:
out = abs(myFcn(in) - sqrt(3)) < 1e-12;
Exemption tag: %@ok<COMPA>
3.6.10 reportMexFiles
This reports the mex-files the checked code depends on, and also reports whether or not the mex-files for the specified platforms are found. This information provides insight into what mex-files are used, and it can also be used to determine whether the code has a chance to work on different platforms.
-
RequiredExtensions (list): Mex-files with these extensions must be checked by this report. Allowed values are: mexa64, mexmaci64, mexw32, and mexw64.
Exemption tag: %@ok<RMEXF>