codeIssues - Identify code issues in files - MATLAB (original) (raw)
Identify code issues in files
Since R2022b. Recommended over checkcode.
Description
The codeIssues
object stores issues found by the MATLAB® Code Analyzer. The issues found in one or more specified files or folders can be sorted and filtered, either programmatically on the command line or interactively in the Code Analyzer app.
Creation
Syntax
Description
`issues` = codeIssues
identifies code issues for the current folder and returns a codeIssues
object.
`issues` = codeIssues([names](#mw%5Fe4e4f9de-d139-4ff6-8dbb-8bf79ec1b9b2))
analyzes the files or folders specified by names
. The files to analyze must be valid MATLAB code or app files (*.m, *.mlx, or *.mlapp).
`issues` = codeIssues([names](#mw%5Fe4e4f9de-d139-4ff6-8dbb-8bf79ec1b9b2),[Name=Value](#namevaluepairarguments))
changes the files used in analysis based on one or more name-value arguments. For example,issues = codeIssues(names,IncludeSubfolders=false)
excludes subfolders of names
from analysis.
Input Arguments
File or folder names, specified as a string scalar or character vector containing an absolute or relative MATLAB path.
Example: "myFile.m"
Name-Value Arguments
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
, where Name
is the argument name and Value
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Example: issues = codeIssues("myFile.m",CodeAnalyzerConfiguration="factory")
Configuration file, specified as "active"
,"factory"
, or a filename.
"active"
— Use the current active configuration settings."factory"
— Use the default configuration settings.- filename — Use the settings in the specified custom configuration file. For more information on custom Code Analyzer configuration files, see Configure Code Analyzer.
This argument sets the CodeAnalyzerConfiguration
property
Whether to include subfolders in analysis, specified as a numeric or logical1
(true
) or 0
(false
).
Properties
This property is read-only.
Date of the analysis, returned as a datetime
object.
This property is read-only.
MATLAB version used for analysis, returned as a string scalar.
This property is read-only.
List of analyzed files, returned as a string array where each element corresponds to a file that was analyzed.
Configuration file, specified as "active"
,"factory"
, or a filename.
"active"
— Use the current active configuration settings."factory"
— Use the default configuration settings."filename"
— Use the settings in the specified custom configuration file.
This property is set by the CodeAnalyzerConfiguration
name-value argument.
Table of the code issues found, specified as a n-by-9 table where each row corresponds to an instance of a found code issue. Issues
contains these columns:
Column Name | Column Purpose |
---|---|
Location | Name of analyzed file, which also functions as a hyperlink to the location of the issue within the file |
Severity | Severity of issue, returned as info,warning, or error |
Fixability | Whether the issue can be fixed automatically or must be fixed manually, returned as auto or manual. |
Description | MATLAB Code Analyzer message for the issue |
CheckID | Check identifier used to find this code issue |
LineStart | Line in the code where issue begins |
LineEnd | Line in the code where issue ends |
ColumnStart | Column in the code where issue begins |
ColumnEnd | Column in the code where issue ends |
FullFilename | Full path to file |
Table of the suppressed code issues found, specified as a n-by-10 table where each row corresponds to an instance of a found code issue. Suppressed issues are issues that have been found but the associated code analyzer message has been manually suppressed. For more information about suppressed code issues, see Adjust Code Analyzer Message Indicators and Messages.
Issues contains these columns:
Column Name | Column Purpose |
---|---|
Location | Name of analyzed file |
Severity | Severity of issue, returned as info,warning, or error |
Fixability | Whether the issue can be fixed automatically or must be fixed manually, returned as auto or manual. |
Description | The MATLAB Code Analyzer message for the issue |
Suppression | How this issue is being suppressed |
CheckID | Check identifier used to find this code issue |
LineStart | Line in the code where issue begins |
LineEnd | Line in the code where issue ends |
ColumnStart | Column in the code where issue begins |
ColumnEnd | Column in the code where issue ends |
FullFilename | Full path to file |
Object Functions
fix | Fix code issues |
---|---|
export | Write code issues to file |
Examples
Identify code issues within the file test.m
by using codeIssues
.
issues = codeIssues("test.m")
issues =
codeIssues with properties:
Date: 18-Oct-2022 14🔞54
Release: "R2023a"
Files: "C:\MyCode\test.m"
CodeAnalyzerConfiguration: "active"
Issues: [3×10 table]
SuppressedIssues: [0×11 table]
Issues table preview
Location Severity Fixability Description CheckID LineStart LineEnd ColumnStart ColumnEnd FullFilename
________ ________ __________ ____________________________________________________________________________________________ _______ _________ _______ ___________ _________ __________________
"test.m" info manual "Variable appears to change size on every loop iteration. Consider preallocating for speed." AGROW 3 3 1 3 "C:\MyCode\test.m"
"test.m" info auto "Add a semicolon after the statement to hide the output (in a script)." NOPTS 6 6 3 3 "C:\MyCode\test.m"
"test.m" info auto "string('...') is not recommended. Use "..." instead." STRQUOT 8 8 1 13 "C:\MyCode\test.m"
Tips
- Use jsonencode to generate a JSON format string of the
codeIssues
object.
Version History
Introduced in R2022b