Main Content

codeIssues

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.

    In R2023a: Certain issues can be fixed using the fix function.

    In R2023b: Content of a codeIssues object can be exported using export.

    Creation

    Description

    issues = codeIssues identifies code issues for the current folder and returns a codeIssues object.

    issues = codeIssues(names) analyzes the files or folders specified by names. The files to analyze must be valid MATLAB code or app files (*.m, *.mlx, or *.mlapp).

    example

    issues = codeIssues(names,Name=Value) 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

    expand all

    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 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: 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 logical 1 (true) or 0 (false).

    Properties

    expand all

    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 NameColumn Purpose
    LocationName of analyzed file, which also functions as a hyperlink to the location of the issue within the file
    SeveritySeverity of issue, returned as info, warning, or error
    FixabilityWhether the issue can be fixed automatically or must be fixed manually, returned as auto or manual.
    DescriptionMATLAB Code Analyzer message for the issue
    CheckIDCheck identifier used to find this code issue
    LineStartLine in the code where issue begins
    LineEndLine in the code where issue ends
    ColumnStartColumn in the code where issue begins
    ColumnEndColumn in the code where issue ends
    FullFilenameFull 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. Issues contains these columns:

    Column NameColumn Purpose
    LocationName of analyzed file
    SeveritySeverity of issue, returned as info, warning, or error
    FixabilityWhether the issue can be fixed automatically or must be fixed manually, returned as auto or manual.
    DescriptionThe MATLAB Code Analyzer message for the issue
    SuppressionHow this issue is being suppressed
    CheckIDCheck identifier used to find this code issue
    LineStartLine in the code where issue begins
    LineEndLine in the code where issue ends
    ColumnStartColumn in the code where issue begins
    ColumnEndColumn in the code where issue ends
    FullFilenameFull path to file

    Object Functions

    fixFix code issues
    exportWrite code issues to file

    Examples

    collapse all

    Identify code issues within the file test.m by using codeIssues.

    issues = codeIssues("test.m")
    issues = 
    
      codeIssues with properties:
    
                             Date: 18-Oct-2022 14:18: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

    expand all