mirror of
https://github.com/XRPLF/clio.git
synced 2026-08-19 03:30:53 +00:00
fix: Add pragma once checker (#3111)
This commit is contained in:
@@ -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:
|
||||
|
||||
34
pre-commit-hooks/fix_pragma_once.py
Executable file
34
pre-commit-hooks/fix_pragma_once.py
Executable 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())
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "data/BackendInterface.hpp"
|
||||
#include "rpc/JS.hpp"
|
||||
#include "rpc/common/Specs.hpp"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "data/cassandra/Error.hpp"
|
||||
#include "data/cassandra/impl/AsyncExecutor.hpp"
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "util/MockMigrationBackend.hpp"
|
||||
#include "util/config/ObjectView.hpp"
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "util/StringBuffer.hpp"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "rpc/common/Types.hpp"
|
||||
#include "util/Spawn.hpp"
|
||||
#include "web/Context.hpp"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "util/Random.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
Reference in New Issue
Block a user