cpplint

2.0.2 · active · verified Tue Apr 14

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.

Warnings

Install

Quickstart

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")

view raw JSON →