.pre-commit-scripts/README.md
check-forbidden-patterns.pyDetects forbidden patterns in C++ source files that should never be committed.
std::getenv() — Not portable (Windows MSVC C4996 warning); use sdk::getEnv() instead.Edit the FORBIDDEN_PATTERNS list in check-forbidden-patterns.py to add new checks:
FORBIDDEN_PATTERNS = [
(
r'\bstd::getenv\s*\(', # regex pattern
"Error message shown to user", # descriptive message
{'.cpp', '.h', '.hpp', '.cxx', '.cc', '.c'}, # file extensions to check
),
# Add new patterns here:
(
r'malloc\s*\(', # example: disallow malloc
"Use std::make_unique or std::make_shared instead of malloc",
{'.cpp', '.h', '.hpp'},
),
]
Test the script manually before running via pre-commit:
# Test on a specific file
.pre-commit-scripts/check-forbidden-patterns.py path/to/file.cpp
# Exit code 0 = no violations, 1 = violations found
# Run only this hook
pre-commit run check-forbidden-patterns --all-files
# Run all hooks on staged files
pre-commit run
re.search()).pre-commit-config.yaml)