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
Export Code Issues to JSON File
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 } } } ] } ] } ] }
Export Code Issues to Specified File
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
issues
— Code issues
codeIssues
object
Code issues, specified as a codeIssues
object.
filename
— Name of output file
string scalar | character vector
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")
FileFormat
— Format of output file
string scalar | character vector
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"
SourceRoot
— Source folder for analysis
string scalar | character vector
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.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)