Clang-tidy plugin

Description

The clang-tidy plugin is used for executing the clang-tidy static code analysis tool.

Mandatory settings

There are no mandatory settings for the clang-tidy plugin.

Optional settings

The configuration of the clang-tidy 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.

sources

A list of sources that must be checked by the clang-tidy plugin. The sources may contain wildcards.

checks

A list of checks that should be enabled or disabled. Enabling or disabling checks is done the same way as they are enabled on the clang-tidy command line. Default: no checks will be enabled or disabled on the command line, meaning the default checks enabled by clang will be checked.

warning-as-errors

Threat warnings as errors. The value associated with this key is either:

  • A list of checks, defining which warnings will be threated as errors. See checks for the format.
  • The single keyword all: means that all enabled checks will be threated as errors.

Note: This options is only supported if the clang-tidy binary supports the -warnings-as-error=<string> option.

Example

Configuration

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

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

example:
    - clang-tidy                # Use the clang-tidy plugin when running the 'example' command

clang-tidy:
    patterns:
        - TARGET
    sources:
        - "src/{TARGET}.cpp"
    checks:
        - "*"
        - "cppcoreguidelines-*"
        - "modernize-*"
        - "performance-*"
        - "readability-*"
        - "-fuchsia-*"
        - "-llvmlibc-*"
    command-line:
        - -fix

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.