<commit_before>.. _tool-cppcheck:

========
Cppcheck
========

Cppcheck_ is a tool that does static analysis on C and C++ code.

.. _CPPCheck: http://cppcheck.sourceforge.net/


Installation
============

The :command:`cppcheck` tool is available in most system package managers. For
example, on Ubuntu::

    $ sudo apt-get install cppcheck
<commit_msg>Update the documentation for Cppcheck.<commit_after>.. _tool-cppcheck:

========
Cppcheck
========

Cppcheck_ is a tool that does static analysis on C and C++ code.


.. _CPPCheck: http://cppcheck.sourceforge.net/


Supported File Types
====================

The following are supported by this tool:

* C/C++: :file:`*.c`, :file:`*.cc`, :file:`*.cpp`, :file:`*.cxx`,
  :file:`*.c++`, :file:`*.h`, :file:`*.hh`, :file:`*.hpp`, :file:`*.hxx`,
  :file:`*.h++`, :file:`*.tpp`, :file:`*.txx`


Installation
============

The :command:`cppcheck` tool is available in most system package managers.

On Ubuntu/Debian::

    $ sudo apt-get install cppcheck

On RHEL/CentOS/Fedora::

    $ sudo yum install cppcheck

On macOS using Homebrew_::

    $ brew install cppcheck

See the `Cppcheck downloads page`_ for other options.


.. _Cppcheck downloads page: http://cppcheck.sourceforge.net/#download
.. _Homebrew: https://brew.sh/


Configuration
=============

Cppcheck Location
-----------------

If the :command:`cppcheck` command is in a non-standard location, and can't
be found in Review Bot's :envvar:`PATH` environment variable, then you'll
need to :ref:`specify the path <worker-configuration-exe-paths>` in the
:ref:`Review Bot worker config file <worker-configuration>`:

.. code-block:: python

    exe_paths = {
        'cppcheck': '/path/to/cppcheck',
    }

You will need to restart the Review Bot worker after making this change.


Enabling Cppcheck in Review Board
---------------------------------

First, you'll need to add a Review Bot configuration in Review Board (see
:ref:`extension-configuration-tools`).

The following configuration options are available:

:guilabel:`Enable standard style checks`:
    Enable this checkbox if you want to check for style-related issues, which
    will include code style, warning, and performance checks.

    This is equivalent to :command:`cppcheck --enable=style`.

:guilabel:`Enable all error checks`:
    Enable this checkbox if you want to include all possible checks.

    Note that this may include false positives.

    This is equivalent to :command:`cppcheck --enable=all`.

:guilabel:`Force cppcheck to use a specific language` (optional):
    Force Cppcheck into a mode where it assumes all code is either C or
    C++. By default, the language is auto-detected.

    This is equivalent to :command:`cppcheck --language=c` or
    :command:`cppcheck --language=c++`.

{'fraction_non_alphanumeric': 0.15942549371633752, 'fraction_numerical': 0.0, 'mean_word_length': 3.738095238095238, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3725215', 'n_tokens_mistral': 835, 'n_tokens_neox': 793, 'n_words': 303}