36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import os
|
|
|
|
def check_encoding(file_path):
|
|
try:
|
|
with open(file_path, 'rb') as f:
|
|
content = f.read()
|
|
content.decode('utf-8')
|
|
# Also check for commonMojibake patterns or literal strings
|
|
# U+FFFD is b'\xef\xbf\xbd' in UTF-8
|
|
if b'\xef\xbf\xbd' in content:
|
|
return "Contains U+FFFD (Replacement Character)"
|
|
return None
|
|
except UnicodeDecodeError as e:
|
|
return f"Invalid UTF-8 at byte {e.start}"
|
|
except Exception as e:
|
|
return str(e)
|
|
|
|
search_dir = r"d:\Development\SingBox-Gopanel"
|
|
extensions = ('.go', '.js', '.jsx', '.ts', '.tsx', '.html', '.css', '.json', '.sql', '.md')
|
|
exclude_dirs = {'.git', 'node_modules', 'dist'}
|
|
|
|
results = []
|
|
for root, dirs, files in os.walk(search_dir):
|
|
dirs[:] = [d for d in dirs if d not in exclude_dirs]
|
|
for file in files:
|
|
if file.endswith(extensions):
|
|
full_path = os.path.join(root, file)
|
|
issue = check_encoding(full_path)
|
|
if issue:
|
|
results.append(f"{full_path}: {issue}")
|
|
|
|
if results:
|
|
print("\n".join(results))
|
|
else:
|
|
print("No issues found in source files.")
|