mirror of
https://github.com/isledecomp/isle-portable.git
synced 2024-11-26 17:36:12 -05:00
ccb6223d70
* mxdirectdraw: no need to explicitly add a terminating '\0' in C * mxstopwatch must include LIMITS.H for ULONG_MAX * Add Config app * 88.78% * style fixes * Test more CONFIG things * Add a few assertions on MFC classes * reformat * actionSSSSSSSSSSSSSSS * actions again * decomplint needed a shebang * Fix annotations of Message Map entries * ci: We're building CONFIG.EXE, not CONFIG.DLL * remove ninja.exe * Fix CAboutDialog::GetMessageMap annotation * format reloaded * Fix global CConfigApp object annotation * trigger worflows * ci: request at least python 3 * oops :) * curl CONFIGPROGRESS-OLD.TXT will fail * Forget about actions/setup-python (for now) * Annotation fixes * Config tweaks and MxDirect3d annotations * It's important to compare against the correct file * Introduce common CDialog parent for CAboutDialog and CMainDialog * format * Remove CSerializer --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com>
102 lines
2.6 KiB
Python
Executable file
102 lines
2.6 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import sys
|
|
import argparse
|
|
import colorama
|
|
from isledecomp.dir import walk_source_dir, is_file_cpp
|
|
from isledecomp.parser import DecompLinter
|
|
|
|
colorama.init()
|
|
|
|
|
|
def display_errors(alerts, filename):
|
|
sorted_alerts = sorted(alerts, key=lambda a: a.line_number)
|
|
|
|
for alert in sorted_alerts:
|
|
error_type = (
|
|
f"{colorama.Fore.RED}error: "
|
|
if alert.is_error()
|
|
else f"{colorama.Fore.YELLOW}warning: "
|
|
)
|
|
components = [
|
|
colorama.Fore.LIGHTWHITE_EX,
|
|
filename,
|
|
":",
|
|
str(alert.line_number),
|
|
" : ",
|
|
error_type,
|
|
colorama.Fore.LIGHTWHITE_EX,
|
|
alert.code.name.lower(),
|
|
]
|
|
print("".join(components))
|
|
|
|
if alert.line is not None:
|
|
print(f"{colorama.Fore.WHITE} {alert.line}")
|
|
|
|
|
|
def parse_args() -> argparse.Namespace:
|
|
p = argparse.ArgumentParser(
|
|
description="Syntax checking and linting for decomp annotation markers."
|
|
)
|
|
p.add_argument("target", help="The file or directory to check.")
|
|
p.add_argument(
|
|
"--module",
|
|
required=False,
|
|
type=str,
|
|
help="If present, run targeted checks for markers from the given module.",
|
|
)
|
|
p.add_argument(
|
|
"--warnfail",
|
|
action=argparse.BooleanOptionalAction,
|
|
default=False,
|
|
help="Fail if syntax warnings are found.",
|
|
)
|
|
|
|
(args, _) = p.parse_known_args()
|
|
return args
|
|
|
|
|
|
def process_files(files, module=None):
|
|
warning_count = 0
|
|
error_count = 0
|
|
|
|
linter = DecompLinter()
|
|
for filename in files:
|
|
success = linter.check_file(filename, module)
|
|
|
|
warnings = [a for a in linter.alerts if a.is_warning()]
|
|
errors = [a for a in linter.alerts if a.is_error()]
|
|
|
|
error_count += len(errors)
|
|
warning_count += len(warnings)
|
|
|
|
if not success:
|
|
display_errors(linter.alerts, filename)
|
|
print()
|
|
|
|
return (warning_count, error_count)
|
|
|
|
|
|
def main():
|
|
args = parse_args()
|
|
|
|
if os.path.isdir(args.target):
|
|
files_to_check = list(walk_source_dir(args.target))
|
|
elif os.path.isfile(args.target) and is_file_cpp(args.target):
|
|
files_to_check = [args.target]
|
|
else:
|
|
sys.exit("Invalid target")
|
|
|
|
(warning_count, error_count) = process_files(files_to_check, module=args.module)
|
|
|
|
print(colorama.Style.RESET_ALL, end="")
|
|
|
|
would_fail = error_count > 0 or (warning_count > 0 and args.warnfail)
|
|
if would_fail:
|
|
return 1
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|