2019-10-05 20:53:16 +00:00
|
|
|
#!/usr/bin/env python3
|
2017-05-14 19:48:05 +00:00
|
|
|
|
|
|
|
# Requires: https://github.com/LordGolias/sqf
|
|
|
|
|
|
|
|
import fnmatch
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
from sqf.parser import parse
|
|
|
|
import sqf.analyzer
|
|
|
|
from sqf.exceptions import SQFParserError
|
|
|
|
|
|
|
|
|
|
|
|
def analyze(filename, writer=sys.stdout):
|
|
|
|
warnings = 0
|
|
|
|
errors = 0
|
|
|
|
with open(filename, 'r') as file:
|
|
|
|
code = file.read()
|
|
|
|
try:
|
|
|
|
result = parse(code)
|
|
|
|
except SQFParserError as e:
|
|
|
|
print("{}:".format(filename))
|
|
|
|
writer.write(' [%d,%d]:%s\n' % (e.position[0], e.position[1] - 1, e.message))
|
|
|
|
return 0, 1
|
|
|
|
|
|
|
|
exceptions = sqf.analyzer.analyze(result).exceptions
|
2019-10-05 20:53:16 +00:00
|
|
|
if (exceptions):
|
2017-05-14 19:48:05 +00:00
|
|
|
print("{}:".format(filename))
|
|
|
|
for e in exceptions:
|
|
|
|
if (e.message.startswith("error")):
|
|
|
|
errors += 1
|
|
|
|
else:
|
|
|
|
warnings += 1
|
|
|
|
writer.write(' [%d,%d]:%s\n' % (e.position[0], e.position[1] - 1, e.message))
|
2019-10-05 20:53:16 +00:00
|
|
|
|
2017-05-14 19:48:05 +00:00
|
|
|
return warnings, errors
|
2019-10-05 20:53:16 +00:00
|
|
|
|
2017-05-14 19:48:05 +00:00
|
|
|
def main():
|
|
|
|
print("#########################")
|
|
|
|
print("# Lint Check #")
|
|
|
|
print("#########################")
|
|
|
|
|
|
|
|
sqf_list = []
|
|
|
|
all_warnings = 0
|
|
|
|
all_errors = 0
|
2019-10-05 20:53:16 +00:00
|
|
|
|
2017-05-14 19:48:05 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('-m','--module', help='only search specified module addon folder', required=False, default=".")
|
|
|
|
args = parser.parse_args()
|
2019-10-05 20:53:16 +00:00
|
|
|
|
2017-05-14 19:48:05 +00:00
|
|
|
for root, dirnames, filenames in os.walk('../addons' + '/' + args.module):
|
|
|
|
for filename in fnmatch.filter(filenames, '*.sqf'):
|
|
|
|
sqf_list.append(os.path.join(root, filename))
|
2019-10-05 20:53:16 +00:00
|
|
|
|
2017-05-14 19:48:05 +00:00
|
|
|
for filename in sqf_list:
|
|
|
|
warnings, errors = analyze(filename)
|
|
|
|
all_warnings += warnings
|
|
|
|
all_errors += errors
|
2019-10-05 20:53:16 +00:00
|
|
|
|
2017-05-14 19:48:05 +00:00
|
|
|
print ("Parse Errors {0} - Warnings {1}".format(all_errors,all_warnings))
|
|
|
|
|
|
|
|
# return (all_errors + all_warnings)
|
|
|
|
return all_errors
|
2019-10-05 20:53:16 +00:00
|
|
|
|
2017-05-14 19:48:05 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|