LinuxCommandLibrary

cppclean

Clean C++ code by removing unused includes

TLDR

Run in a project's directory

$ cppclean [path/to/project]
copy

Run on a project where the headers are in the inc1/ and inc2/ directories
$ cppclean [path/to/project] --include-path [inc1] --include-path [inc2]
copy

Run on a specific file main.cpp
$ cppclean [main.cpp]
copy

Run on the current directory, excluding the "build" directory
$ cppclean [.] --exclude [build]
copy

SYNOPSIS

cppclean [options] [file2] ...

PARAMETERS

--verbose
    Enable verbose output.

--recursive
    Recursively search directories for C++ files.

--exclude=
    Exclude files matching the given pattern.

--include=
    Specify an include path for resolving headers.

--filter=
    Specify the filter file to exclude specific checks (usually .cppclean file).

--safe-headers
    Don't suggest adding header files from the same directory.

--report-progress
    Report progress during execution.

--max-line-length=
    Maximum line length allowed in the code.

--exit-code
    Return a non-zero exit code if there are any issues.

--version
    Show program's version number and exit.

DESCRIPTION

cppclean is a static analysis tool designed to check C++ code for various style issues, potential errors, and adherence to coding standards.

It identifies problems such as unused variables, redundant includes, header guards, and other common mistakes that can lead to code maintainability problems or subtle bugs. cppclean aims to improve code quality and consistency by automating the process of code review and helping developers to identify and fix issues early in the development cycle. It provides detailed output, guiding the user to specific locations in the code that require attention.

While it is not a full-fledged compiler, cppclean parses the code to understand its structure and dependencies, allowing it to effectively detect issues without requiring the code to be compiled and executed.

CAVEATS

cppclean primarily focuses on style and common mistakes rather than deep semantic analysis.
It might not catch all possible errors or enforce every aspect of a coding standard.
The effectiveness of cppclean depends on the specific coding guidelines and the configuration of the tool. The filter file can be complex and require some time to configure.

FILTERS

The most common usage of cppclean is with filter file.
Filters can be set to remove certain warnings.
Example:.cppclean file:
`Remove include: ` `Ignore variable: unusedVariable`

SEE ALSO

cpplint(1), clang-tidy(1)

Copied to clipboard