Registry / testing / cpplint

cpplint

JSON →
library2.0.2pypypiunverified

Cpplint is an actively maintained, open-source command-line tool for static analysis of C/C++ source files, primarily used to enforce adherence to Google's C++ style guide. Version 2.0.2 is the latest stable release, with frequent updates incorporating modern C++ standards and Python environment compatibility.

pip install cpplint
INSTALL
IMPORT
SIG · CPPLINT
C
cpplint
testingpythonv2.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

The primary way to use cpplint is as a command-line tool. This example creates a C++ file, runs `cpplint` on it with a common filter to ignore line length, and prints the output. Note that `cpplint` writes its findings to stderr. Configuration can also be managed via a `CPPLINT.cfg` file in the project directory.

# Create a dummy C++ file for linting with open("main.cpp", "w") as f: f.write("""#include <iostream>\n\nint main() {\n std::cout << "Hello, World!" << std::endl; // Missing space before '!'\n return 0;\n}\n""") # Run cpplint on the file # This is primarily a command-line tool, so we use subprocess import subprocess import os try: # cpplint usually exits with non-zero on errors, so capture output # Using --filter to ignore common line_length warnings for this example result = subprocess.run( ["cpplint", "--filter=-whitespace/line_length", "main.cpp"], capture_output=True, text=True, check=False # Don't raise CalledProcessError for non-zero exit codes ) print("cpplint output (stdout):") print(result.stdout) print("\ncpplint output (stderr):") print(result.stderr) if result.returncode != 0: print("\nLinting found issues. Return code:", result.returncode) else: print("\nNo linting issues found (or filtered out).") except FileNotFoundError: print("Error: cpplint command not found. Ensure it's installed and in your PATH.") finally: # Clean up the dummy file if os.path.exists("main.cpp"): os.remove("main.cpp")
cpplint --version
Debug
Known issues
breakingPython 2 and Python 3.7 are no longer supported. Users must upgrade to Python 3.8 or newer.
fix
Upgrade your Python environment to 3.8 or later. The current minimum requirement is Python 3.9.
affects: >=2.0.0
breakingThe `setup.py lint` subcommand was removed. Direct invocation of `cpplint` commands is now required.
fix
Remove any reliance on `python setup.py lint`. Instead, run `cpplint` directly from the command line with appropriate arguments.
affects: >=2.0.0
gotchaAs of version 2.0.2, non-const references are no longer erred on by default. This changes previous behavior where they might have been flagged as style violations.
fix
If your project requires strict checking for non-const references, you may need to explicitly enable a corresponding filter if one becomes available, or consider this change in your style enforcement.
affects: >=2.0.2
gotchacpplint strictly enforces Google's C++ Style Guide, which may not align with all project or team-specific style preferences.
fix
Customize linting rules using the `--filter` command-line option (e.g., `cpplint --filter=-whitespace/line_length`) or by creating a `CPPLINT.cfg` file in your project directory.
affects: all
gotchacpplint is rules-based and uses heuristics, which can lead to occasional false positives or negatives. It is not a substitute for a comprehensive code review.
fix
Use `// NOLINT(category)` comments on specific lines to suppress known false positives for particular categories. For blocks of code, use `// NOLINTBEGIN(category)` and `// NOLINTEND`.
affects: all
Errors
Common errors & fixes
cpplint: command not found
The `cpplint` executable is not in your system's PATH, often because it was installed with `pip install --user cpplint`, which places it in a user-specific binary directory (e.g., `~/.local/bin/` on Linux) that might not be automatically included in the PATH.
fix
Add the directory where `cpplint` is installed to your system's PATH environment variable. For example, on Linux, add `export PATH=$PATH:~/.local/bin/` to your `~/.bashrc` or `~/.zshrc` file and then `source` it.
Skipping input '*.cpp': Can't open for reading
On Windows Command Prompt (cmd.exe), the wildcard `*` is not expanded by the shell into a list of files before being passed to `cpplint`. Instead, `cpplint` receives the literal string `*.cpp` and tries to open a file with that exact name.
fix
Use a shell that performs wildcard expansion (like Git Bash or PowerShell) or explicitly list the files, or use a `for` loop in `cmd.exe`. For example, in PowerShell: `Get-ChildItem -Path . -Filter '*.cpp' -Recurse | ForEach-Object { cpplint $_.FullName }` or in `cmd.exe`: `for %f in (*.cpp) do cpplint %f`.
Found C system header after other header. Should be: ..., c system, c++ system, other. [build/include_order]
This error indicates that your header includes do not follow Google's C++ style guide, which specifies a particular order for different types of includes (e.g., project-specific headers, C system headers, C++ system headers, other library headers).
fix
Reorder your `#include` directives to match the specified order. If this specific check is problematic for your project's structure, you can disable it using the `--filter` option: `cpplint --filter=-build/include_order your_file.cpp`.
Cpplint could not find executable
This typically occurs when using `cpplint` through an IDE extension (e.g., in VS Code) where the IDE cannot locate the `cpplint` executable. This is similar to 'command not found' but specific to the IDE's environment.
fix
Configure the full path to the `cpplint` executable in your IDE's settings for the `cpplint` extension. For example, in VS Code, set `"cpplint.cpplintPath": "/home/your_username/.local/bin/cpplint"`.
ModuleNotFoundError: No module named 'cpplint'
The 'cpplint' Python package has not been installed in the active Python environment.
fix
Run `pip install cpplint` in your terminal to install the package.
Upgrade
Version history
2.0.2latest on PyPI · released Apr 8, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources
cpplint — pip install cpplint · libregistry