Main Content

codeIssues

Identify code issues in files

    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

    Description

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

    example

    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).

    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.

    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"
    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"
    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

    Examples

    collapse all

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

    issues = codeIssues("test.m")
    issues = 
      codeIssues with properties:
    
                    Date: 20-Apr-2022 14:32:32
                 Release: "R2022b"
                   Files: "C:\myCode\test.m"
           Configuration: "active"
                  Issues: [3×9 table]
        SuppressedIssues: [0×10 table]
    
    
        Issues table preview
    
        Location    Severity                                                             Description                                                              CheckID    LineStart    LineEnd    ColumnStart    ColumnEnd        FullFilename                                       
        ________    ________    ______________________________________________________________________________________________________________________________    _______    _________    _______    ___________    _________    ___________________
    
        "test.m"      info      "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      "Variable appears to change size on every loop iteration. Consider preallocating for speed."                                       AGROW         5           5            1             3        "C:\myCode\test.m"
        "test.m"      info      "Using 'evalc' with two arguments is not recommended. Use try/catch statements instead to make code more clear and efficient."     EVLC          8           8            1             5        "C:\myCode\test.m"
    
    
    
    

    Version History

    Introduced in R2022b