引入 pre-commit 自动化代码审查(格式/静态分析/乱码/commit message)
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""检查 C/C++ 源码中是否含 U+FFFD 替换符(编码损坏标志,不可逆),含则退出码 1。"""
|
||||
import sys
|
||||
|
||||
BAD = b"\xef\xbf\xbd"
|
||||
bad_files = []
|
||||
for path in sys.argv[1:]:
|
||||
with open(path, "rb") as f:
|
||||
if BAD in f.read():
|
||||
bad_files.append(path)
|
||||
if bad_files:
|
||||
print("U+FFFD replacement chars found (encoding corrupted, irreversible!):")
|
||||
for p in bad_files:
|
||||
print(" -", p)
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user