export
Description
export( writes the contents of the
specified issues)codeIssues object
to the file codeIssues.json.
export(___, specifies
options using one or more name-value arguments in addition to any of the input argument
combinations in previous syntaxes. For example, you can specify the format of the output
file.Name=Value)
Examples
Create a report containing issues found in code.
First, create a function myfun in a file named
myfun.m.
function x = myfun randomNum = rand for n = 1:10 x(n) = sin(randomNum); end end
Identify code issues in myfun by using codeIssues.
C = codeIssues("myfun.m")C =
codeIssues with properties:
Date: 28-Apr-2023 10:49:26
Release: "R2023b"
Files: "C:\MyCode\myfun.m"
CodeAnalyzerConfiguration: "active"
Issues: [2×10 table]
SuppressedIssues: [0×11 table]
Issues table preview
Location Severity Fixability Description CheckID LineStart LineEnd ColumnStart ColumnEnd FullFilename
_________ ________ __________ ____________________________________________________________________________________________ _______ _________ _______ ___________ _________ ___________________
"myfun.m" info auto "Add a semicolon after the statement to hide the output (in a function)." NOPRT 2 2 11 11 "C:\MyCode\myfun.m"
"myfun.m" info manual "Variable appears to change size on every loop iteration. Consider preallocating for speed." AGROW 4 4 8 8 "C:\MyCode\myfun.m"
Export the issues found in myfun by using
export.
export(C)
Open codeIssues.sarif to see the exported report.
{
"version": "2.1.0",
"properties": {
"Date": "28-Apr-2023 10:49:26",
"Release": "R2023b",
"CodeAnalyzerConfiguration": "active"
},
"runs": [
{
"tool": {
"driver": {
"name": "Code Analyzer"
}
},
"artifacts": {
"location": {
"uri": "file:///C:/MyCode/myfun.m"
}
},
"results": [
{
"ruleId": "NOPRT",
"level": "note",
"message": {
"text": "Add a semicolon after the statement to hide the output (in a function)."
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///C:/MyCode/myfun.m"
},
"region": {
"startLine": 2,
"endLine": 2,
"startColumn": 11,
"endColumn": 12
}
}
}
]
},
{
"ruleId": "AGROW",
"level": "note",
"message": {
"text": "Variable appears to change size on every loop iteration. Consider preallocating for speed."
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///C:/MyCode/myfun.m"
},
"region": {
"startLine": 4,
"endLine": 4,
"startColumn": 8,
"endColumn": 9
}
}
}
]
}
]
}
]
}
Create a report containing issues found in code and export to a specified file.
First, create a function myfun in a file named
myfun.m.
function x = myfun randomNum = rand for n = 1:10 x(n) = sin(randomNum); end end
Identify code issues in myfun by using codeIssues.
C = codeIssues("myfun.m")C =
codeIssues with properties:
Date: 25-Apr-2023 10:29:59
Release: "R2023b"
Files: "C:\MyCode\myfun.m"
CodeAnalyzerConfiguration: "active"
Issues: [2×10 table]
SuppressedIssues: [0×11 table]
Issues table preview
Location Severity Fixability Description CheckID LineStart LineEnd ColumnStart ColumnEnd FullFilename
_________ ________ __________ ____________________________________________________________________________________________ _______ _________ _______ ___________ _________ ___________________
"myfun.m" info auto "Add a semicolon after the statement to hide the output (in a function)." NOPRT 2 2 11 11 "C:\MyCode\myfun.m"
"myfun.m" info manual "Variable appears to change size on every loop iteration. Consider preallocating for speed." AGROW 4 4 8 8 "C:\MyCode\myfun.m"
Export the issues found in myfun using to a file named
myReport.
export(C,"myReport")Open myReport.sarif to see the exported report.
{
"version": "2.1.0",
"properties": {
"Date": "28-Apr-2023 10:49:26",
"Release": "R2023b",
"CodeAnalyzerConfiguration": "active"
},
"runs": [
{
"tool": {
"driver": {
"name": "Code Analyzer"
}
},
"artifacts": {
"location": {
"uri": "file:///C:/MyCode/myfun.m"
}
},
"results": [
{
"ruleId": "NOPRT",
"level": "note",
"message": {
"text": "Add a semicolon after the statement to hide the output (in a function)."
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///C:/MyCode/myfun.m"
},
"region": {
"startLine": 2,
"endLine": 2,
"startColumn": 11,
"endColumn": 12
}
}
}
]
},
{
"ruleId": "AGROW",
"level": "note",
"message": {
"text": "Variable appears to change size on every loop iteration. Consider preallocating for speed."
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///C:/MyCode/myfun.m"
},
"region": {
"startLine": 4,
"endLine": 4,
"startColumn": 8,
"endColumn": 9
}
}
}
]
}
]
}
]
}
Input Arguments
Code issues, specified as a codeIssues
object.
Name of output file, specified as a string scalar or character vector. If filename
does not include a file extension, export uses the SARIF file format. If
filename includes a valid file extension,
export uses that extension to determine the file format. For a
list of valid formats, see FileFormat.
Example: "myFile.sarif"
Example: "myFile.json"
Name-Value Arguments
Specify optional pairs of arguments as
Name1=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: export(issues,"issuesFile.sarif",FileFormat="sarif",SourceRoot="\my\root\folder")
Format of output file, specified as a string scalar or character vector.
FileFormat must be one of these values:
| Value | File Format |
|---|---|
"auto" (default) | Format is determined by the file extension of
filename. If filename does not
include an extension, then .sarif is the default
extension. |
"json" | Exported as JSON file using the format of jsonencode |
"sarif" | Exported as JSON file using the format of SARIF |
"sonarqube" | Exported as JSON file using the format of SonarQube |
Example: FileFormat="sarif"
Source folder for analysis, specified as a string scalar or character vector
containing the full or relative path to the root folder. You can specify
SourceRoot only if the output file format is SARIF.
Example: SourceRoot="\my\root\folder"
Version History
Introduced in R2023b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)