|
| 1 | + |
| 2 | +# Report |
| 3 | + |
| 4 | +## Overview |
| 5 | + |
| 6 | +This folder contains a script report.py that converts a cppcheck xml report into a html report. |
| 7 | + |
| 8 | +Only the python standard libraries are used. No extra dependencies shall be needed. |
| 9 | + |
| 10 | +The html report is interactive, there are toggle buttons and stuff. |
| 11 | + |
| 12 | +## Performance |
| 13 | + |
| 14 | +Very important. The report needs to be responsive for large projects with thousands of warnings. It's preferable that multiple files are created instead of a single HTML that contains everything. |
| 15 | + |
| 16 | +## Themes |
| 17 | + |
| 18 | +There will be different themes. light/dark/etc |
| 19 | + |
| 20 | +## Dashboard |
| 21 | + |
| 22 | +A dashboard shows an overview of warnings. The dashboard is designed for a team-leader that wants to see status. The dashboard should primarily present information in graphs. |
| 23 | + |
| 24 | +### Sections |
| 25 | + |
| 26 | +- Executive summary: A text summary. Green/Red Badge if there are undefined behavior. A Green/red badge if there are security/safety issues (misra/cert). The badge is gray if misra/cert was not checked. |
| 27 | +- Product filter strip: Buttons per "product". Products are guessed from the directory (src/core/ becomes "Core"), or set with --product-map. Clicking one filters the whole dashboard. Hide this if all source files are in the same folder. |
| 28 | +- If several reports are provided we can show trend graphs. |
| 29 | +- Show graphs both for "new" warnings and "all" warnings. |
| 30 | +- 5 KPI tiles: Errors, warnings, style+perf+portability, total and affected files, with "+N vs previous". |
| 31 | +- Quality trend over time: Line chart of total/errors/warnings across snapshots (--history DIR or --snapshot). With "new" warnings selected it shows the new warnings in each report, compared with the report before. Hide this if there is only 1 result file. |
| 32 | +- Warnings by product: Bar chart. Hide this if there is only one product, or if a product is selected. |
| 33 | +- Risk domain breakdown: Bar chart of IDs grouped into made-up groups ("Memory & Crash Safety", "Security", "Maintainability"…) by keyword matching or by CWE. |
| 34 | +- If there are metrics then show some summary about that. |
| 35 | + |
| 36 | +## Result details |
| 37 | + |
| 38 | +There is a result details view. All results are shown here. It's possible to toggle different warnings severities. It's possible to toggle IDs. |
| 39 | + |
| 40 | +All warnings are shown in a list and if a warning is clicked the related code is shown in a tab. |
| 41 | + |
| 42 | +## Metrics |
| 43 | + |
| 44 | +If there are metrics, a metrics report. |
| 45 | + |
| 46 | +# Baseline : New and old warnings |
| 47 | + |
| 48 | +Each warning has a hash in the xml report, if old baseline report(s) are provided then those warnings are "old". A warning in a new report is "new" if its hash does not match any baseline warning. |
| 49 | + |
| 50 | +It should be indicated in the dashboard how many new/old warnings there are. It should be possible to see if warnings are new in the results view and it should be possible to hide old warnings. |
| 51 | + |
| 52 | +## Classification/guideline mode (MISRA, CERT, Cppcheck Premium) |
| 53 | + |
| 54 | +When the XML has classification attributes, the report switches to a different mode: |
| 55 | + |
| 56 | +- In the results list the severity is replaced by Classification and Guideline columns. Click on a column header to sort. |
| 57 | +- A filter bar for Mandatory, Required, Advisory, Document, Disapplied and L1/L2/L3 replaces the severity filter. Classifications that are not used in the report are disabled. |
| 58 | +- The dashboard graphs and KPI tiles use the classification instead of the severity, and there is a graph of the most violated guidelines. |
| 59 | +- The severity is still shown in the warning details. |
| 60 | + |
| 61 | + |
| 62 | +# Usage |
| 63 | + |
| 64 | + cppcheck --xml ... 2> results.xml |
| 65 | + python3 report.py results.xml -o cppcheck-report |
| 66 | + |
| 67 | + # mark new/old warnings by comparing with a previous report |
| 68 | + python3 report.py results.xml --baseline old-results.xml -o cppcheck-report |
| 69 | + |
| 70 | + # trend graphs: older reports in a directory (results-2026-05-01.xml, ...) |
| 71 | + python3 report.py results.xml --history history -o cppcheck-report |
| 72 | + |
| 73 | + # metrics (Cppcheck Premium) |
| 74 | + cppcheck --premium=metrics --xml-version=3 ... 2> results.xml |
| 75 | + python3 report.py results.xml -o cppcheck-report |
| 76 | + |
| 77 | +Then open `cppcheck-report/index.html` in a browser. |
| 78 | + |
| 79 | +Options: |
| 80 | + |
| 81 | + * `-o DIR`, `--output-dir DIR` directory where the report is written (default: cppcheck-report) |
| 82 | + * `--xml FILE` xml report (xml files can also be given as positional arguments) |
| 83 | + * `--baseline FILE` baseline xml report, warnings that are not in the baseline are new (can be given several times). `--old` is an alias. If it is not given, the newest `--history`/`--snapshot` report is used. |
| 84 | + * `--history DIR` directory with older xml reports for the trend graphs. They are ordered by the date in the file name (`results-2026-05-01.xml`), or by file time. |
| 85 | + * `--snapshot FILE` older xml report for the trend graphs (can be given several times, oldest first) |
| 86 | + * `--product-map FILE` json file that maps path prefixes to product names: `{"src/core": "Core", "lib/net": "Network"}`. Without it, products are guessed from the first directory below the common source directory (`src/core/x.cpp` becomes "Core"). |
| 87 | + * `--metrics-thresholds FILE` json file with metric thresholds, overrides the defaults: `{"cyclomaticComplexity": {"max": 15}, "HISCOMF": {"min": 10}}` |
| 88 | + * `--source-dir DIR` where the source files are located (can be given several times). By default the current directory and the directories of the xml files are searched. |
| 89 | + * `--source-encoding ENCODING` encoding of the source files (default: utf-8) |
| 90 | + * `--title TITLE` report title |
| 91 | + * `--theme THEME` default theme: light, apple, microsoft, dark, midnight, solarized (the viewer can switch theme in the report) |
| 92 | + |
| 93 | +## Report directory |
| 94 | + |
| 95 | + index.html open this in a browser |
| 96 | + report.css |
| 97 | + report.js |
| 98 | + data/results.js all warnings, trend data |
| 99 | + data/metrics.js metrics (if the xml has metrics), loaded when needed |
| 100 | + data/src/<n>.js source code, one file per source file, loaded when it is shown |
| 101 | + |
| 102 | +The report works directly from the file system (no web server needed). Copy the whole directory to share it. |
| 103 | + |
| 104 | +## Combining several XML files |
| 105 | + |
| 106 | +Multiple xml files can be provided: `--xml file1.xml --xml file2.xml`. Duplicate warnings (same hash and location) are only shown once. |
| 107 | + |
| 108 | +## Metric thresholds |
| 109 | + |
| 110 | +The default thresholds are the HIS limits (same as Cppcheck Premium `HISReport.py`): |
| 111 | + |
| 112 | +| Metric | Id | Threshold | |
| 113 | +|---|---|---| |
| 114 | +| Cyclomatic complexity v(G) | cyclomaticComplexity | max 10 | |
| 115 | +| Statements STMT | HISStmt | max 50 | |
| 116 | +| Execution paths PATH | HISPath | max 80 | |
| 117 | +| Nesting depth LEVEL | HISLevel | max 4 | |
| 118 | +| Called functions CALLS | HISCall | max 7 | |
| 119 | +| Calling functions CALLING | HISCalling | max 5 | |
| 120 | +| Parameters PARAM | HISParam | max 5 | |
| 121 | +| Return points RETURN | HISReturn | max 1 | |
| 122 | +| Goto statements GOTO | HISGoto | max 0 | |
| 123 | +| Language scope VOCF | HISVOCF | max 4 (computed from HISVocf_N / HISVocf_D) | |
| 124 | +| Comment density COMF % | HISCOMF | min 20 (computed from HISComment / HISStmtFile) | |
| 125 | + |
| 126 | +They can be changed with `--metrics-thresholds`. |
| 127 | + |
0 commit comments