fix: Add pragma once checker (#3111)

This commit is contained in:
Ayaz Salikhov
2026-06-19 17:23:03 +01:00
committed by GitHub
parent a7502033f5
commit 373a883840
8 changed files with 48 additions and 0 deletions

View File

@@ -93,6 +93,12 @@ repos:
types: [c++]
language: script
- id: fix-pragma-once
name: fix missing '#pragma once' declarations in header files
language: python
entry: ./pre-commit-hooks/fix_pragma_once.py
files: \.(h|hpp)$
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: dd18dad857d6133e90bbe478f4f2f22ec0030269 # frozen: v22.1.5
hooks:

View File

@@ -0,0 +1,34 @@
#!/usr/bin/env python3
"""
Adds "#pragma once" to the top of header files that don't already have it.
Usage: ./bin/pre-commit/fix_pragma_once.py <file1> <file2> ...
"""
import sys
from pathlib import Path
PRAGMA_ONCE = "#pragma once\n\n"
def fix_pragma_once(path: Path) -> bool:
original = path.read_text(encoding="utf-8")
if PRAGMA_ONCE not in original:
path.write_text(PRAGMA_ONCE + original, encoding="utf-8")
return False
return True
def main() -> int:
files = [Path(f) for f in sys.argv[1:]]
success = True
for path in files:
success &= fix_pragma_once(path)
return 0 if success else 1
if __name__ == "__main__":
sys.exit(main())

View File

@@ -1,4 +1,5 @@
#pragma once
#include "data/BackendInterface.hpp"
#include "rpc/JS.hpp"
#include "rpc/common/Specs.hpp"

View File

@@ -1,3 +1,5 @@
#pragma once
#include "data/cassandra/Error.hpp"
#include "data/cassandra/impl/AsyncExecutor.hpp"

View File

@@ -1,3 +1,5 @@
#pragma once
#include "util/MockMigrationBackend.hpp"
#include "util/config/ObjectView.hpp"

View File

@@ -1,4 +1,5 @@
#pragma once
#include "util/StringBuffer.hpp"
#include <ostream>

View File

@@ -1,4 +1,5 @@
#pragma once
#include "rpc/common/Types.hpp"
#include "util/Spawn.hpp"
#include "web/Context.hpp"

View File

@@ -1,4 +1,5 @@
#pragma once
#include "util/Random.hpp"
#include <gtest/gtest.h>