Implementation:NVIDIA DALI Cpplint
| Knowledge Sources | |
|---|---|
| Domains | Code_Quality, Linting |
| Last Updated | 2026-02-08 16:00 GMT |
Overview
Customized Google C++ style linter that checks DALI's C++ source files for compliance with coding standards, supporting .cc, .cpp, .cu, .cuh, and .h file extensions.
Description
This file (third_party/cpplint.py) is NVIDIA's customized fork of Google's cpplint tool, originally developed by Google Inc. and extended with NVIDIA-specific modifications (copyright 2017-2022). At 6,244 lines, it is a comprehensive static analysis tool that identifies potential style violations in C++ code based on the Google C++ Style Guide.
The linter organizes its checks into five major categories: build (class definitions, C++11/14 usage, deprecated constructs, header guards, includes), legal (copyright notices), readability (casting style, braces, constructors, function size, namespace formatting, UTF-8 compliance), runtime (array usage, casting, explicit constructors, integer types, memory operations, thread safety), and whitespace (blank lines, braces, commas, comments, indentation, line length, operators, tabs). Each violation is assigned a confidence score from 1 to 5, with 5 indicating certainty.
The tool supports extensive configuration through command-line flags including --filter for enabling/disabling specific check categories, --linelength for maximum line width, --root for header guard derivation, --extensions for linted file types (defaulting to .cc, .cpp, .cu, .cuh, .h), and --headers for header file recognition. Per-directory configuration is supported via CPPLINT.cfg files that can set filters, exclude files by regex, configure line length, and establish root directories. The set noparent directive prevents upward traversal of configuration inheritance.
The main entry point parses arguments via ParseArguments(), processes each file through ProcessFile(), and exits with a non-zero status if any errors are found. NOLINT comments in source code suppress false positives on specific lines.
Usage
This linter is used in DALI's CI pipeline and by developers to enforce consistent C++ coding style across the DALI codebase. It is invoked on individual files or directories as part of pre-commit checks or automated quality gates.
Code Reference
Source Location
- Repository: NVIDIA_DALI
- File: third_party/cpplint.py
- Lines: 1-6244
Signature
# Error categories (partial list)
_ERROR_CATEGORIES = [
'build/class', 'build/c++11', 'build/c++14', 'build/header_guard',
'build/include', 'build/include_order', 'build/namespaces',
'legal/copyright',
'readability/braces', 'readability/casting', 'readability/fn_size',
'runtime/arrays', 'runtime/casting', 'runtime/explicit', 'runtime/int',
'whitespace/blank_line', 'whitespace/braces', 'whitespace/indent',
'whitespace/line_length', 'whitespace/tab',
# ... and many more
]
_DEFAULT_FILTERS = ['-build/include_alpha']
# Key functions
def ProcessFile(filename, vlevel, extra_check_functions=[]): ...
def ProcessFileData(filename, file_extension, lines, error, extra_check_functions=[]): ...
def ParseArguments(args): ...
def main(): ...
Import
# Run as standalone script
python third_party/cpplint.py [--verbose=#] [--filter=...] <file> [file] ...
# Example
python third_party/cpplint.py --linelength=100 dali/pipeline/pipeline.cc
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| file(s) | positional args | Yes | One or more C++ source files to lint |
| --verbose | int (0-5) | No | Restrict errors to certain verbosity levels |
| --filter | str | No | Comma-separated category filters: +enable, -disable |
| --linelength | int | No | Maximum allowed line length (default: 80) |
| --root | str | No | Root directory for deriving header guard CPP variable names |
| --extensions | str | No | Comma-separated list of file extensions to lint (default: cc,cpp,cu,cuh,h) |
| --headers | str | No | Comma-separated header extensions to treat as .h |
| --output | str | No | Output format: emacs (default), vs7, or eclipse |
| --counting | str | No | Error counting style: total, toplevel, or detailed |
| --quiet | flag | No | Suppress output if no errors found |
| CPPLINT.cfg | file | No | Per-directory configuration files with filter, linelength, root, exclude_files settings |
Outputs
| Name | Type | Description |
|---|---|---|
| Lint warnings | stderr | Style violations with file, line number, category, confidence level, and description |
| Error counts | stderr | Summary count of total errors found (by category if --counting specified) |
| Exit code | int | 0 if no errors, 1 if errors found |
Usage Examples
Lint a single file
python third_party/cpplint.py dali/pipeline/pipeline.cc
Lint with custom filters and line length
python third_party/cpplint.py \
--linelength=100 \
--filter=-whitespace/indent,-build/include_order \
--verbose=3 \
dali/kernels/*.cu dali/kernels/*.cuh
Use with CPPLINT.cfg
# CPPLINT.cfg placed in project root
set noparent
filter=-build/include_alpha,+build/include_order
linelength=100
root=dali
exclude_files=.*_test\.cc