Cppcheck plugin

Description

The cppcheck plugin is used for executing the cppcheck static code analysis tool.

Mandatory settings

There are no mandatory settings for the cppcheck plugin.

Optional settings

The configuration of the cppcheck plugin may contain the following settings:

patterns

A list of patterns to apply on the command line. See Patterns (5).

enviroment

A list of environment variables that should be set before the commands are executed. See Environment (5).

command-line

Additional command line parameters to pass as a list of separate arguments. By default no additional arguments are added.

working-dir

The working directory of the command. Can be an absolute path are a relative one w.r.t. the path to the considered configuration file. Commands that should be executed relative to the current working dir can use the {EH_WORKING_DIR} pattern.

enable-checks

A list of checks that should be enabled or disabled. Check the documentation of cppcheck for a list of all the available checks. Default: all.

src-dir

The base directory containing all the files to check. Default: . (the current working directory).

Example

Configuration

commands:                       # Define the commands that can be run
    example: Run the cppcheck example

patterns:                       # Define the patterns that can be used
    TARGET:                     # Define targets to check
        default-values:         # Only define the default value
            - hello
            - world

example:
    - cppcheck                  # Use the cppcheck plugin when running the 'example' command

cppcheck:                       # Cppcheck configuration for the 'example' command
    example:
        patterns:               # Define the patterns to use
            - TARGET
        src-dir:                # Define the source dir to look in
            - src
        target-path:            # The target path to look in
            - "{TARGET}.cpp"
        enable-checks:          # The list of additional checks to enable
            - warning
            - style
            - performance
            - portability
            - information
        command-line:           # Set additional arguments
            - --error-exitcode=255

Additional files

In order for the above example to work, the following files need to be created in the src directory:

hello.cpp:

#include <cstdlib>
#include <iostream>

auto main() -> int {
    std::cout << "Hello" << std::endl;
    return EXIT_SUCCESS;
}

world.cpp:

#include <cstdlib>
#include <iostream>

auto main() -> int {
    std::cout << "World!" << std::endl;
    return EXIT_SUCCESS;
}

Usage

Save the example to an exec-helper configuration file and execute in the same directory:

eh example

See also

See exec-helper (1) for information about the usage of exec-helper.

See Configuration (5) for information about the configuration file format.

See Plugins (5) for information about the configuration file format.