mirror of
https://github.com/open-goal/jak-project
synced 2026-06-12 13:35:39 -04:00
scripts: new linter script to detect goal_src files with trailing whitespace (#3387)
Removes trailing whitespace from goal_src files, eventually the formatter will do this as well but it's not ready yet so this is a decent interim solution. A competent text editor will also do this / flag it for you.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import glob
|
||||
import re
|
||||
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--fix", action="store_true")
|
||||
parser.set_defaults(fix=False)
|
||||
args = parser.parse_args()
|
||||
|
||||
folders_to_check = ["goal_src"]
|
||||
|
||||
flagged_instances = []
|
||||
|
||||
for folder in folders_to_check:
|
||||
files_to_check = glob.glob("./{}/**/*.gc".format(folder), recursive=True)
|
||||
files_to_check += glob.glob("./{}/**/*.gs".format(folder), recursive=True)
|
||||
files_to_check += glob.glob("./{}/**/*.gd".format(folder), recursive=True)
|
||||
for filename in files_to_check:
|
||||
# Get the file contents
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
lines = f.readlines()
|
||||
lines_with_trailing_whitespace = [line.rstrip('\n').endswith(' ') for line in lines]
|
||||
if any(lines_with_trailing_whitespace):
|
||||
flagged_instances.append(filename)
|
||||
if args.fix:
|
||||
cleaned_lines = [line.rstrip() + '\n' if line.rstrip() != line else line for line in lines]
|
||||
with open(filename, 'w') as file:
|
||||
file.writelines(cleaned_lines)
|
||||
|
||||
if len(flagged_instances) == 0:
|
||||
exit(0)
|
||||
|
||||
if args.fix:
|
||||
print("Fixed whitespace in {} files:".format(len(flagged_instances)))
|
||||
else:
|
||||
print("Found empty whitespace in the following files, please trim them:")
|
||||
for file in flagged_instances:
|
||||
print(file)
|
||||
exit(1)
|
||||
Reference in New Issue
Block a user