目录

Code Scanner

Since version 26.0.0, DevEco Studio has introduced Code Scanner to detect resource leaks in the entire project. Developers can manually fix code defects based on the warning prompts in the scan results to guarantee code quality during development.

Constraints

[h2]Supported Countries/Regions

This feature is available only in the Chinese mainland.

Procedure

  1. On the menu bar, choose Code > Code Scanner > Config and select the required scanning rules. The scanning rules are categorized into ArkTS and CPP.

    Click a scanning rule name to view its rule description and code examples (including positive and negative examples) on the right. You can modify the project code based on the provided recommendations. In the Severity field, you can configure the severity level (error, warn, or fatal) for the rule; the default level is error.

    After completing the selection and configuration, click OK to save the rule configuration, or click Save and Run to save the configuration and start code scanning immediately.
    • For ArkTS projects, select the scanning rules under ARKTS; for C++ projects, select the rules under CPP.

  2. On the menu bar, choose Code > Code Scanner > Scan to start full code scanning.
  3. After the scanning is complete, view the check results in the tool panel at the bottom.

    The Severity section displays the counts of warnings by severity level. You can click All, Fatal, Error, or Warn to view the specific details of the corresponding severity level. Clicking the Filter by scene drop-down list allows you to filter the check results by rule. Click a warning file to view the warning information and its associated rule configuration. Double-clicking a warning result navigates to the corresponding code defect. When a warning result is selected, you can view the warning cause and the possible execution flow from the problem source to the occurrence point in the Execution Trace pane on the right.