Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codacy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude_paths:
- addons/test/**
- addons/y2038/test/*.c
- htmlreport/example.cc
- reports/htmlreport/example.cc
- samples/**/bad.c
- samples/**/bad.cpp
- test/cfg/*.c
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jobs:
# TODO: include in installer?
- name: Compile cppcheck-htmlreport executable
run: |
cd htmlreport || exit /b !errorlevel!
cd reports\htmlreport || exit /b !errorlevel!
pyinstaller cppcheck-htmlreport || exit /b !errorlevel!
del *.spec || exit /b !errorlevel!

Expand All @@ -153,7 +153,7 @@ jobs:
del win_installer\files\platforms\*.rng || exit /b !errorlevel!
del win_installer\files\translations\*.qm || exit /b !errorlevel!
move build\gui\*.qm win_installer\files\translations || exit /b !errorlevel!
copy htmlreport\dist\cppcheck-htmlreport\*.* win_installer\files || exit /b !errorlevel!
copy reports\htmlreport\dist\cppcheck-htmlreport\*.* win_installer\files || exit /b !errorlevel!
:: copy libcrypto-3-x64.dll and libssl-3-x64.dll
copy %RUNNER_WORKSPACE%\Qt\Tools\OpenSSLv3\Win_x64\bin\lib*.dll win_installer\files || exit /b !errorlevel!

Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/scriptcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
if: matrix.python-latest
run: |
shopt -s globstar
pylint --jobs $(nproc) --py-version 3.7 addons/**/*.py htmlreport/cppcheck-htmlreport htmlreport/**/*.py test/**/*.py tools/**/*.py
pylint --jobs $(nproc) --py-version 3.7 addons/**/*.py reports/htmlreport/cppcheck-htmlreport reports/htmlreport/**/*.py test/**/*.py tools/**/*.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

The pylint and py_compile steps (lines 112 and 128–129) cover only reports/htmlreport/**, so the new reports/explorer/report.py is never linted or compiled with --py-version 3.7. Using reports/**/*.py instead would cover both.


- name: check .json files
if: matrix.python-latest
Expand All @@ -125,8 +125,8 @@ jobs:
run: |
shopt -s globstar
python -m py_compile addons/**/*.py
python -m py_compile htmlreport/cppcheck-htmlreport
python -m py_compile htmlreport/**/*.py
python -m py_compile reports/htmlreport/cppcheck-htmlreport
python -m py_compile reports/htmlreport/**/*.py
python -m py_compile test/**/*.py
python -m py_compile tools/**/*.py

Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
python -m venv venv
source venv/bin/activate
python -m pip install -U pip
pip install ./htmlreport/
pip install ./reports/htmlreport/
which cppcheck-htmlreport
PIP_PACKAGE_TEST=1 test/tools/htmlreport/test_htmlreport.py
# TODO: does not test the pip binary
Expand Down Expand Up @@ -199,6 +199,12 @@ jobs:
env:
PYTHONPATH: ./tools

# uses the node that is installed on the runner
- name: test explorer report javascript
run: |
node --version
python -m pytest -Werror --strict-markers -vv test/tools/explorer/explorer_js_test.py

- name: Show all ignored files
if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched
run: |
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ stage
**/*.egg-info/

# cppcheck-htmlreport auto files
/htmlreport/cppcheck_htmlreport/run.py
/reports/htmlreport/cppcheck_htmlreport/run.py

# GDB configuration
.gdbinit

# pyinstaller output
/addons/dist
/addons/misra.spec
/htmlreport/cppcheck-htmlreport.spec
/htmlreport/dist
/reports/htmlreport/cppcheck-htmlreport.spec
/reports/htmlreport/dist

# ccache folder in CI
/.ccache
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ tags:
install: cppcheck
install -d ${BIN}
install cppcheck ${BIN}
install htmlreport/cppcheck-htmlreport ${BIN}
install reports/htmlreport/cppcheck-htmlreport ${BIN}
ifdef FILESDIR
install -d ${DESTDIR}${FILESDIR}
install -d ${DESTDIR}${FILESDIR}/addons
Expand Down
2 changes: 1 addition & 1 deletion cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if (BUILD_CLI)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT applications)

install(PROGRAMS ${CMAKE_SOURCE_DIR}/htmlreport/cppcheck-htmlreport
install(PROGRAMS ${CMAKE_SOURCE_DIR}/reports/htmlreport/cppcheck-htmlreport
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT applications)

Expand Down
6 changes: 3 additions & 3 deletions man/manual-ja.docbook
Original file line number Diff line number Diff line change
Expand Up @@ -1814,11 +1814,11 @@ for arg in sys.argv[1:]:
<chapter>
<title>HTML 形式での報告</title>

<para>cppcheckのXML出力をHTML形式に変更できます。これを利用するには、Python と pygments module (<ulink url="http://pygments.org/">http://pygments.org/</ulink>) が必要です。Cppcheckのソースツリーに<filename class="directory">htmlreport</filename>というフォルダがあります。このフォルダには、CppcheckのXMLファイルをHTML出力に変換するスクリプトがあります。</para>
<para>cppcheckのXML出力をHTML形式に変更できます。これを利用するには、Python と pygments module (<ulink url="http://pygments.org/">http://pygments.org/</ulink>) が必要です。Cppcheckのソースツリーに<filename class="directory">reports/htmlreport</filename>というフォルダがあります。このフォルダには、CppcheckのXMLファイルをHTML出力に変換するスクリプトがあります。</para>

<para>このコマンドでヘルプ画面を生成するには次のように実行します。</para>

<programlisting>htmlreport/cppcheck-htmlreport -h</programlisting>
<programlisting>reports/htmlreport/cppcheck-htmlreport -h</programlisting>

<para>出力画面には次の内容が表示されます。:</para>

Expand All @@ -1836,7 +1836,7 @@ Options:
<para>使用例:</para>

<programlisting>./cppcheck gui/test.cpp --xml 2&gt; err.xml
htmlreport/cppcheck-htmlreport --file=err.xml --report-dir=test1 --source-dir=.</programlisting>
reports/htmlreport/cppcheck-htmlreport --file=err.xml --report-dir=test1 --source-dir=.</programlisting>
</chapter>

<chapter>
Expand Down
99 changes: 92 additions & 7 deletions man/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -1341,11 +1341,22 @@ The `.cfg` file format is documented in the `Reference: Cppcheck .cfg format` (<

# HTML report

You can convert the XML output from Cppcheck into a HTML report. You'll need Python and the pygments module (<http://pygments.org/>) for this to work. In the Cppcheck source tree there is a folder htmlreport that contains a script that transforms a Cppcheck XML file into HTML output.
## Overview

Using AI, you can easily and quickly create a script that converts the Cppcheck XML output into a nice-looking HTML report with any features you want.

We provide 2 ready made scripts:

* htmlreport: results view
* explorer: dashboard, results view, metrics (if available)

## htmlreport

The script `cppcheck-htmlreport` converts a Cppcheck XML file into a HTML output. You'll need Python and the pygments module (<http://pygments.org/>) for this to work.

This command generates the help screen:

htmlreport/cppcheck-htmlreport -h
reports/htmlreport/cppcheck-htmlreport -h

The output screen says:

Expand Down Expand Up @@ -1374,7 +1385,7 @@ or
cppcheck-htmlreport --file=err.xml --report-dir=test1 \
--source-dir=https://github.com/<username>/<repo>/blob/<branch>/

## Choosing between local annotated HTML and remote repository links
### Choosing between local annotated HTML and remote repository links

`cppcheck-htmlreport` supports two modes for linking to source files:

Expand All @@ -1394,6 +1405,81 @@ handled by the hosting service.
In general, local mode fits air-gapped environments, while remote mode works
best for CI workflows and large or private repositories.

## Explorer report

The script `reports/explorer/report.py` creates a Cppcheck Explorer report. The report has a dashboard with graphs, and a results view where you can filter the warnings and see the related source code. If the XML file contains metrics, these are shown as well. The report is designed to be responsive also when there are thousands of warnings.

You only need Python to run the script, no extra modules are required.

### Generating a report

First analyze the code and save the results in an XML file, then generate the report:

cppcheck --enable=style --xml src 2> results.xml
python3 reports/explorer/report.py results.xml -o cppcheck-report

Open `cppcheck-report/index.html` in a browser. To share the report, copy the whole `cppcheck-report` folder. Note that the report contains the source code.

The source files are searched for in the current folder and in the folder of the XML file. Use `--source-dir` if they are located somewhere else:

python3 reports/explorer/report.py results.xml --source-dir=path/to/project -o cppcheck-report

### New and old warnings

If you provide the XML results from an earlier analysis as a baseline, then the report shows which warnings are new:

# Analyze the code and save the results as a baseline
cppcheck --enable=style --xml src 2> baseline.xml

# Later: analyze the code again and compare with the baseline
cppcheck --enable=style --xml src 2> results.xml
python3 reports/explorer/report.py results.xml --baseline=baseline.xml -o cppcheck-report

### Trend graphs

Save the XML results from each analysis in a folder and use `--history` to get trend graphs. The results are ordered by the date in the filename:

mkdir -p history
cppcheck --enable=style --xml src 2> history/results-2026-05-01.xml

# Later: analyze the code again and show the trend
cppcheck --enable=style --xml src 2> results.xml
python3 reports/explorer/report.py results.xml --history=history -o cppcheck-report

If no `--baseline` is given, then the newest report in the history is used as baseline.

::: {.content-visible when-profile="premium"}

### Metrics

To generate metrics, add option `--premium=metrics`. The metrics are saved in the XML v3 report.
Example:

cppcheck --premium=metrics test.c --xml-version=3 2> res.xml
python3 reports/explorer/report.py res.xml -o cppcheck-report

The dashboard shows a summary of the metrics and the metrics view shows the values for each
function and file. Values that exceed the thresholds are highlighted.

The default thresholds are the HIS limits. You can change them by providing a JSON file. Example `thresholds.json`:

{
"cyclomaticComplexity": {"max": 15},
"HISCOMF": {"min": 10}
}

Use the option `--metrics-thresholds` to load the file:

python3 reports/explorer/report.py res.xml --metrics-thresholds=thresholds.json -o cppcheck-report

:::

### All options

To see all options, run:

python3 reports/explorer/report.py -h

# Check level

## Reduced
Expand Down Expand Up @@ -1550,16 +1636,15 @@ Example:

cppcheck --premium=metrics test.c --xml-version=3 2> res.xml

We provide a small simple python script that creates a metrics report in CSV format:
A report that shows the metrics can be created, for example see the chapter [Explorer report](#explorer-report).

If you want the metrics in CSV format, we provide a small simple python script for that:

python3 HISReport.py -f res.xml -j path/to/cppcheck-id-mapping.json -o test.csv

The `cppcheck-id-mapping.json` is provided in the Cppcheck premium installation folder, i.e.
`/opt/cppcheckpremium` or `C:\Program Files\Cppcheck Premium`.

We do not have a ready-made solution to generate a HTML/pdf report. You can easily tweak our
`HISReport.py` script so that it generates HTML and get the report exactly as you want.

## Licenses

### Commercial terms
Expand Down
127 changes: 127 additions & 0 deletions reports/explorer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@

# Report

## Overview

This folder contains a script report.py that converts a cppcheck xml report into a html report.

Only the python standard libraries are used. No extra dependencies shall be needed.

The html report is interactive, there are toggle buttons and stuff.

## Performance

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.

## Themes

There will be different themes. light/dark/etc

## Dashboard

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.

### Sections

- 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.
- 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.
- If several reports are provided we can show trend graphs.
- Show graphs both for "new" warnings and "all" warnings.
- 5 KPI tiles: Errors, warnings, style+perf+portability, total and affected files, with "+N vs previous".
- 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.
- Warnings by product: Bar chart. Hide this if there is only one product, or if a product is selected.
- Risk domain breakdown: Bar chart of IDs grouped into made-up groups ("Memory & Crash Safety", "Security", "Maintainability"…) by keyword matching or by CWE.
- If there are metrics then show some summary about that.

## Result details

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.

All warnings are shown in a list and if a warning is clicked the related code is shown in a tab.

## Metrics

If there are metrics, a metrics report.

# Baseline : New and old warnings

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.

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.

## Classification/guideline mode (MISRA, CERT, Cppcheck Premium)

When the XML has classification attributes, the report switches to a different mode:

- In the results list the severity is replaced by Classification and Guideline columns. Click on a column header to sort.
- 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.
- The dashboard graphs and KPI tiles use the classification instead of the severity, and there is a graph of the most violated guidelines.
- The severity is still shown in the warning details.


# Usage

cppcheck --xml ... 2> results.xml
python3 report.py results.xml -o cppcheck-report

# mark new/old warnings by comparing with a previous report
python3 report.py results.xml --baseline old-results.xml -o cppcheck-report

# trend graphs: older reports in a directory (results-2026-05-01.xml, ...)
python3 report.py results.xml --history history -o cppcheck-report

# metrics (Cppcheck Premium)
cppcheck --premium=metrics --xml-version=3 ... 2> results.xml
python3 report.py results.xml -o cppcheck-report

Then open `cppcheck-report/index.html` in a browser.

Options:

* `-o DIR`, `--output-dir DIR` directory where the report is written (default: cppcheck-report)
* `--xml FILE` xml report (xml files can also be given as positional arguments)
* `--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.
* `--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.
* `--snapshot FILE` older xml report for the trend graphs (can be given several times, oldest first)
* `--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").
* `--metrics-thresholds FILE` json file with metric thresholds, overrides the defaults: `{"cyclomaticComplexity": {"max": 15}, "HISCOMF": {"min": 10}}`
* `--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.
* `--source-encoding ENCODING` encoding of the source files (default: utf-8)
* `--title TITLE` report title
* `--theme THEME` default theme: light, apple, microsoft, dark, midnight, solarized (the viewer can switch theme in the report)

## Report directory

index.html open this in a browser
report.css
report.js
data/results.js all warnings, trend data
data/metrics.js metrics (if the xml has metrics), loaded when needed
data/src/<n>.js source code, one file per source file, loaded when it is shown

The report works directly from the file system (no web server needed). Copy the whole directory to share it.

## Combining several XML files

Multiple xml files can be provided: `--xml file1.xml --xml file2.xml`. Duplicate warnings (same hash and location) are only shown once.

## Metric thresholds

The default thresholds are the HIS limits (same as Cppcheck Premium `HISReport.py`):

| Metric | Id | Threshold |
|---|---|---|
| Cyclomatic complexity v(G) | cyclomaticComplexity | max 10 |
| Statements STMT | HISStmt | max 50 |
| Execution paths PATH | HISPath | max 80 |
| Nesting depth LEVEL | HISLevel | max 4 |
| Called functions CALLS | HISCall | max 7 |
| Calling functions CALLING | HISCalling | max 5 |
| Parameters PARAM | HISParam | max 5 |
| Return points RETURN | HISReturn | max 1 |
| Goto statements GOTO | HISGoto | max 0 |
| Language scope VOCF | HISVOCF | max 4 (computed from HISVocf_N / HISVocf_D) |
| Comment density COMF % | HISCOMF | min 20 (computed from HISComment / HISStmtFile) |

They can be changed with `--metrics-thresholds`.

Loading
Loading